0
votes

One day I was playing around with my Arduino and had a cool idea. Maybe I could do a wireless connection WITHOUT the serial monitor! I could use an LCD display instead! So, I went to work. I replaced all of the serial stuff with LCD stuff.

Finally I had no errors in my code (according to the Arduino client, that is).

Here is my code:

#include <LiquidCrystal.h>
#include <WiFi.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

char ssid[] = "Fake Network";                    // Your network SSID (name)
char key[] = "1";       // your network key
int keyIndex = 0;                                // Your network key Index number
int status = WL_IDLE_STATUS;                     // The Wi-Fi radio's status

void setup() {

    lcd.begin(16, 2);

    // Check for the presence of the shield:
    if (WiFi.status() == WL_NO_SHIELD) {
        lcd.println("WiFi shield not present");
        // Don't continue:
        while(true);
    }

    // Attempt to connect to Wi-Fi network:
    while ( status != WL_CONNECTED) {
        lcd.print("Attempting to connect to WEP network, SSID: ");
        lcd.println(ssid);
        status = WiFi.begin(ssid, keyIndex, key);

        // Wait 10 seconds for connection:
        delay(10000);
    }

    // Once you are connected:
    lcd.print("You're connected to the network");
    printCurrentNet();
    printWifiData();
}

void loop() {
    // Check the network connection once every 10 seconds:
    delay(10000);
    printCurrentNet();
}

void printWifiData() {
  // Print your Wi-Fi shield's IP address:
  IPAddress IPaddr = WiFi.localIP();
  lcd.print("IP Address: ");
  lcd.println(IPaddr);
  lcd.println(IPaddr);

  // Print your MAC address:
  byte MACaddr[6];
  WiFi.macAddress(MACaddr);
  lcd.print("MAC address: ");
  lcd.print(MACaddr[5],HEX);
  lcd.print(":");
  lcd.print(MACaddr[4],HEX);
  lcd.print(":");
  lcd.print(MACaddr[3],HEX);
  lcd.print(":");
  lcd.print(MACaddr[2],HEX);
  lcd.print(":");
  lcd.print(MACaddr[1],HEX);
  lcd.print(":");
  lcd.println(MACaddr[0],HEX);
}

void printCurrentNet() {
    // Print the SSID of the network you're attached to:
    lcd.print("SSID: ");
    lcd.println(WiFi.SSID());

    // Print the MAC address of the router you're attached to:
    byte bssid[6];
    WiFi.BSSID(bssid);
    lcd.print("BSSID: ");
    lcd.print(bssid[5],HEX);
    lcd.print(":");
    lcd.print(bssid[4],HEX);
    lcd.print(":");
    lcd.print(bssid[3],HEX);
    lcd.print(":");
    lcd.print(bssid[2],HEX);
    lcd.print(":");
    lcd.print(bssid[1],HEX);
    lcd.print(":");
    lcd.println(bssid[0],HEX);

    // Print the received signal strength:
    long rssi = WiFi.RSSI();
    lcd.print("signal strength (RSSI):");
    lcd.println(rssi);

    // Print the encryption type:
    byte encryption = WiFi.encryptionType();
    lcd.print("Encryption Type:");
    lcd.println(encryption,HEX);
    lcd.println();
}

And the result was....... Nothing. Nothing displayed.

Then I went and did my version of debugging. Note that I started at the bottom of the code.

lcd.print("bug");

I put this under every line of my code. Finally, I got to the top, under this line:

lcd.begin(16, 2);

AND GUESS WHAT! No display in any of the lines! I looked everywhere and I checked the display pins.

FINALLY, I found the problem!

It's a horrible bug that I can't get rid of! The display won't show with the WiFi.h library! I don't know why, But if I even #include <WiFi.h> into my program (or any program with the LiquidCrystal library... Things go exactly the same way!

What is the reason for this problem and how can I fix it? I haven't got any luck yet.

1
Seems to work okay for this guy: bradsduino.blogspot.com/2012/10/…Pete

1 Answers

2
votes

According to the documentation:

Arduino communicates with both the Wifi shield's processor and SD card using the SPI bus (through the ICSP header). This is on digital pins 11, 12, and 13 on the Uno and pins 50, 51, and 52 on the Mega. On Uno 11 is MOSI, and 12 is MISO.

According to your code

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

you are using pins 11 and 12 for the LCD. Now if the LCD was using SPI, then the LCD could share pins 11 and 12 with the Wi-Fi shield, because the same set of pins used for SS (Slave Select) function would tell the peripherals which one of them should be listening. However, the LiquidCrystal library uses its first two argument pins for RS and Enable respectively, making it incompatible with SPI. The solution: move your LCD onto different pins.