[SOLVED] Wifly & LCD screen conflict

I have the Wifly shield and the Color LCD Shield from Sparkfun and I am trying to connect everything together, I am getting an issue with this two devices that are connected on the SPI BUS.

The LCD is using
Reset (RES) 8
Chip-select 9
Data in/out (DIO) 11
Serial Clock (SCK) 13

and the Wifly:
10-13 (CS, MOSI, MISO, SCLK respectively).

When I am doing the code:

lcd.init(PHILLIPS);  // Initializes lcd, using an EPSON driver
  lcd.contrast(80);  // 40's usually a good contrast value
  lcd.clear(RED);  // oooh, teal!

Before to initialize the Wifly I can get something on the screen but if I put this piece of code after the initialized I don't getting anything.

There is a issue with the SPI BUS? Should I turn on something HIGH or LOW when I want to draw something?

Thanks

*** SOLUTION ***
I figured out that the library Wifly was keeping busy the SPI BUS, I made some changes on the library, everythings is described on my blog:

Someone know something? If its an issue about spi and you maybe know something, please share with me >)

I don't know much about the WiFly unit, but I know a bit about the SPI bus from experience gained from the ethernet shield. You must disable one to access the other. If this is not done in the low level access in the library, you will need to do it before each access.

// in setup()
// set WiFly SS to OUTPUT and HIGH (disabled)
pinMode(10,OUTPUT);
digitalWrite(10,HIGH);

// enable lcd SPI
pinMode(9,OUTPUT);
digitalWrite(9,LOW);
// do the comm
lcd.init(PHILLIPS);  // Initializes lcd, using an EPSON driver
lcd.contrast(80);  // 40's usually a good contrast value
lcd.clear(RED);  // oooh, teal!
// then disable the lcd SPI
digitalWrite(9,HIGH);

I have not checked the WiFly library to see if it handles its SPI SS line in the low level read/write routines. You may or may not need to do that with the WiFly SS also (digital pin 10).

edit: I think both of those were in the setup, so I changed it to that.

Dosen't work :frowning: I tried to put HIGH the wifly and LOW the LCD but I still dont see any change on the screen. If I run the 3 lines on a new project I can see the background.

I think so that there is some conflict between wifly and the lcd screen

If you remove the Wifly unit, does the lcd screen work ok with the same code?

edit: I don't think the IRQ is supposed to be an output. I think that is a read line on the Arduino. I removed this part of my response to prevent a possible conflict on the WiFly shield pins.

My recommendation is get the code working with the lcd display, then install the WiFly shield and go from there. Find what is interfering.

It appears from the schematic that the WiFly is powered from Vin, not +5v. Are you providing power to the Arduino using Vin? That is the power jack, not the usb.

If I put the 3 lines on the setup I can see the blue screen but after I initialized the wifly I can't draw any more.

If I load any example for the lcd is working ( with the wifly attached )

Could be some issue about SPI protocol that all information is sending to the Wifly instead of LCD shield.

After you initialize the WiFly, you may need to patch your code a bit. The WiFly library code may not be willing to share the SPI bus, but you should be able to force it to share.

When you want to draw on the lcd, try this:

// disable the WiFly and enable the lcd
digitalWrite(10,HIGH);
digitalWrite(9,LOW);
// do your lcd draw
// then disable the lcd and enable the WiFly
digitalWrite(9,HIGH);
digitalWrite(10,LOW);

If the WiFly library functions handled the SS pin correctly, you would not need to disable and enable digital pin 10, just digital pin 9.

add: If that doesn't work, then you may need to disable interrupts during the lcd write

// disable interrupts and the WiFly and enable the lcd
noInterrupts();
digitalWrite(10,HIGH);
digitalWrite(9,LOW);
// do your lcd draw
// then disable the lcd and enable the WiFly and interrupts
digitalWrite(9,HIGH);
digitalWrite(10,LOW);
interrupts();

I don't know how stopping interrupts will affect your WiFly comm during the lcd write tho.

I tried the both solutions but doesn't work, I figured out that If I call the init the screen become black.

the library is: https://github.com/jimbloom/ColorLCDShield/tree/

edit: My bad. I had it backwards.

That wifi LCD library handles the SS line ok. It handles the SS manipulation in the low level functions, just prior and after the SPI read/write. You should not need to manipulate digital pin 10 9. It should always be HIGH after returning from any library function.

edit: What WiFly library are you using?

read the last post, I attached the link of the LCD library

Ops, I read now your edit :slight_smile: this is the wify library http://www.max246.ch/WiFlyIDE1.0.zip

That WiFly library also appears to handle its SS pin ok. If you post the code you are trying, maybe that would help.

void setup() {
...
pinMode(CS_WIFI,OUTPUT);
  pinMode(CS_LCD,OUTPUT);
  digitalWrite(CS_LCD,HIGH);
  lcd.init(PHILLIPS);  // Initializes lcd, using an EPSON driver
  lcd.contrast(80);  // 40's usually a good contrast value
  lcd.clear(RED);  // oooh, teal!

  WiFly.begin();
  WiFly.setIdleDisconnect();
  if (!WiFly.join(ssid, passphrase)) {
    Serial.println("Association failed.");
    while (1) {
      // Hang on failure.
    }
  }   
// give the Wifi shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");
 
  // if you get a connection, report back via serial:
  if (client.connect()) {
    Serial.println("connected");
  } 
  else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
  
...
}

void loop() {
    //When I catch the char V from the serial call the function => requestQRCODE
}

void requestQRCODE() {

  noInterrupts();
  digitalWrite(10,HIGH);
digitalWrite(9,LOW);
 lcd.init(PHILLIPS); 
  digitalWrite(10,HIGH);
digitalWrite(9,LOW);
lcd.contrast(10);  // 40's usually a good contrast value
  lcd.clear(RED);
// do your lcd draw
// then disable the lcd and enable the WiFly
digitalWrite(9,HIGH);
digitalWrite(10,LOW);
interrupts();

}

I tried to remove the init into the requestQRCODE but still doesn't work

With the WiFly shield connected, try this. Does the lcd init and draw work ok?

// include files here
#define CS_WIFI 10
#define CS_LCD 9

void setup() {
  Serial.begin(9600);

  // disable wifly
  pinMode(CS_WIFI,OUTPUT);
  digitalWrite(CS_WIFI,HIGH);

  // run lcd init
  lcd.init(PHILLIPS);  // Initializes lcd, using an EPSON driver
  lcd.contrast(80);  // 40's usually a good contrast value
  // do you still get teal?
  lcd.clear(RED);  // oooh, teal!

  // draw something on the lcd here
}

void loop() {

}

How does that do?

add: I prefer you not use the "...". To me, that means "I left out something important".

void setup() {
...
pinMode(CS_WIFI,OUTPUT);

And if that works, post that code. All of it, including the includes.

The connection is fine :

// Color LCD Shield library
#include <ColorLCDShield.h>

#define SIZE 4

LCDShield lcd;  // Creates an LCDShield, named lcd
char Str4[ ] = "11111110011111001011101111111n10000010100011111110001000001n10111010010110111001101011101n10111010110001100101001011101n10111010000111001111001011101n10000010101001110100101000001n11111110101010101010101111111n00000000000000011001000000000n11111011111101111101010101010n10011100110111001111111010001n00110011110000011000101100000n00111100011000111001111011010n11001111110011110111000101100n11100101111100101111111110001n00011111011010110100100011100n11100100010000011001111010010n00000010000011100101000101100n10011101100101001001111110101n10110010110001111000010010100n10110100010100110011000010010n10110011110111100100111110111n00000000110100101110100011111n11111110101001011011101011100n10000010000110001011100010001n10111010100011000100111110110n10111010111101001011000101101n10111010111001110001011111110n10000010111100111000110111010n11111110101101011101001010100n";
void setup()
{
  lcd.init(PHILLIPS);  // Initializes lcd, using an EPSON driver
  lcd.contrast(40);  // 40's usually a good contrast value
  lcd.clear(WHITE);  // oooh, teal!
  
  int col = 5,row = 5;
  for (int i = 0;i < sizeof(Str4);i++) {
      if (Str4[i] == 'n') {
         col = 5;
         row += SIZE;
      } else {
        if (Str4[i] == '1') { 
         drawBig(SIZE,SIZE,RED,row,col);
        }
        else {
         drawBig(SIZE,SIZE,WHITE,row,col); 
        }
        col += SIZE;
        
      }
  }
}

void drawBig(int w,int h,int color,int row,int col) {
    for (int i = 0;i < w;i++) {
      for (int a = 0;a < h;a++) {
          lcd.setPixel(color,col+i,row+a);
      }
    }
}

void loop()
{
}

The problem is that I can't control the display after I initialized the wifly

Good deal. Then on we go. Now set up the WiFly, and then check the Slave Select pins for both devices.

// include the WiFly include(s)

// Color LCD Shield library
#include <ColorLCDShield.h>

#define SIZE 4

LCDShield lcd;  // Creates an LCDShield, named lcd
char Str4[ ] = "11111110011111001011101111111n10000010100011111110001000001n10111010010110111001101011101n10111010110001100101001011101n10111010000111001111001011101n10000010101001110100101000001n11111110101010101010101111111n00000000000000011001000000000n11111011111101111101010101010n10011100110111001111111010001n00110011110000011000101100000n00111100011000111001111011010n11001111110011110111000101100n11100101111100101111111110001n00011111011010110100100011100n11100100010000011001111010010n00000010000011100101000101100n10011101100101001001111110101n10110010110001111000010010100n10110100010100110011000010010n10110011110111100100111110111n00000000110100101110100011111n11111110101001011011101011100n10000010000110001011100010001n10111010100011000100111110110n10111010111101001011000101101n10111010111001110001011111110n10000010111100111000110111010n11111110101101011101001010100n";
void setup()
{
  // You must do this for debugging
  Serial.begin(9600);

  // you should disable the WiFly SPI before doing the lcd init
  // It will cause you grief someday
  lcd.init(PHILLIPS);  // Initializes lcd, using an EPSON driver
  lcd.contrast(40);  // 40's usually a good contrast value
  lcd.clear(WHITE);  // oooh, teal!
  
  int col = 5,row = 5;
  for (int i = 0;i < sizeof(Str4);i++) {
      if (Str4[i] == 'n') {
         col = 5;
         row += SIZE;
      } else {
        if (Str4[i] == '1') { 
         drawBig(SIZE,SIZE,RED,row,col);
        }
        else {
         drawBig(SIZE,SIZE,WHITE,row,col); 
        }
        col += SIZE;
        
      }
  }

  WiFly.begin();
  WiFly.setIdleDisconnect();
  if (!WiFly.join(ssid, passphrase)) {
    Serial.println("Association failed.");
    while (1) {
      // Hang on failure.
    }
  }   
// give the Wifi shield a second to initialize:
  delay(1000);

  if(digitalRead(9) == LOW) Serial.println("lcd active");
  if(digitalRead(10) == LOW) Serial.println("WiFly active");

  Serial.println("Setup done");
}

void drawBig(int w,int h,int color,int row,int col) {
    for (int i = 0;i < w;i++) {
      for (int a = 0;a < h;a++) {
          lcd.setPixel(color,col+i,row+a);
      }
    }
}

void loop()
{
}

Do you get an "active" message on the serial monitor?
If all goes well, the only serial output should be "Setup done".

edit: Shortened the code. And called Serial.begin(). That is required for debugging.

I should try but I can't do it now, I will write the result on Monday, thanks!

Toilet monitor is starting...
DEBUG: Entered WiFlyDevice::begin()
DEBUG: Entered reboot
DEBUG: Entered findInResponse
DEBUG: Entered requireFlowControl
DEBUG: Entered enterCommandMode
DEBUG: Entered findInResponse
DEBUG: Entered enterCommandMode
DEBUG: Entered findInResponse
connecting...
DEBUG: Entered enterCommandMode
DEBUG: Entered findInResponse
void setup() {
  Serial.begin(9600);
  Serial.println("Toilet monitor is starting...");
//  pinMode(CS_WIFI,OUTPUT);
 // pinMode(CS_LCD,OUTPUT);
 
  lcd.init(PHILLIPS);  // Initializes lcd, using an EPSON driver
  lcd.contrast(80);  // 40's usually a good contrast value
  lcd.clear(RED);  // oooh, teal!

  WiFly.begin();
  WiFly.setIdleDisconnect();
  if (!WiFly.join(ssid, passphrase)) {
    Serial.println("Association failed.");
    while (1) {
      // Hang on failure.
    }
  }   
  // give the Wifi shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");
 
 if(digitalRead(9) == LOW) Serial.println("lcd active");
  if(digitalRead(10) == LOW) Serial.println("WiFly active");
  
  lcd.clear(BLUE);  // oooh, teal!
}

strange :S it's seems that both are HIGH

strange :S it's seems that both are HIGH

No, it isn't. That is the way it is supposed to be. Both should be disabled at that point. You shouldn't get an "active" message.

The library routines, if functioning correctly, should manipulate those SS pins when doing the actual SPI read/write.

What is the solution now? I don't really know what I should to do, Should I change the library ?