Wednesday, 23 May 2012

Issue with Wifly and LCD Screen

Problem

The issue is with the Sparkfun Wifly (http://www.sparkfun.com/products/9954) and Sparkfun LCD screen (http://www.sparkfun.com/products/9363), I was using the Wifly Library and ColorLCDShield Library.
When you want to connect everything together you will not be able to communicate with the LCD after you initialized the Wifly, that because for some reason the SPI bus still communicate with the Wifi.

Solution

The fix is quiet simple, you need to modify 6 files of the Wifly Library:

_Spi.h
//Add two new methods
void end();
void restore();

_Spi.cpp
//That will disable the SPI
void SpiDevice::end() {
SPCR = 01010000;
}

void SpiDevice::restore() {
_initSpi();
}

SpiUart.h
//Add two new methods
void end();
void restore();

SpiUart.cpp
void SpiUartDevice::end() {
SpiDevice::end();
}

void SpiUartDevice::restore() {
SpiDevice::restore();
}

WiFlyDevice.h
//Add two new methods
void end();
void restore();

WiFlyDevice.cpp
void WiFlyDevice::end() {
uart.end();
}
void WiFlyDevice::restore() {
uart.restore();
}

Example

//Start the connection with the Wifly
WiFly.begin();
  
  if (!WiFly.join(ssid, passphrase)) {
    Serial.println("Association failed.");
    while (1) {
      // Hang on failure.
    }
  }  

//Stop for a moment the connection between the SPI and Wifly
WiFly.end();

//Do something with the LCD
lcd.init(PHILLIPS);    //Initialize the LCD
lcd.contrast(40);   // Sets LCD contrast, adjust this if your contrast is odd looking.
lcd.clear(WHITE);    // Clear LCD to solid white

//Restore the communication with the Wifly
WiFly.restore();

So, every time that you want to communicate with the LCD screen, you need to end the SPI communication and leave that to the LCD screen.

4 comments:

Unknown said...

Ciao, sto avendo alcuni problemi con questa soluzione in quanto la libreria wifly è stata aggiornata. potresti inviarmi una e-mail a bozzettoscuola@gmail.com in modo tale che ti possa spiegare meglio?
Grazie

Panda Pro Pressure Washing said...
This comment has been removed by the author.
Panda Pro Pressure Washing said...

Hi mate, I am trying to get this working for my project.

I am not having any luck though, I keep getting variable not declared SpiDevice

Do you have any suggestions any help would be great, im stumped.

Regards,

James

d9frre09ds0ds said...

I have no idea what are you talking about. SpiDevice? Which library? After my code modification?
Please be more specific!