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:
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 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.
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.
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.
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.
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.
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!
}