I have an Arduino Uni Rev3, an Arduino WiFi Shield (R3) and Arduino TFT LCD Screen. IDE version 1.5.7. Standart libraries for TFT and WIFI are used. The WiFi Shield and the TFT Screen works perfectly with the Arduino, if only one is connected.
When I connect both devices, wifi shield not initialized. Reason - WiFi.status() = WL_NO_SHIELD. But display working properly.
The TFT pins following this configuration:
MISO - 12, SCK - 13, MOSI - 11, LCD CS - 6, SD CS - 5, D/C - 9, RESET - 8, So I don't touch WIFI pins - 10,4,7.
I tried set TFT CS pins to HIGH state, but it did not give the result. Also tested on MEGA 2560 with the same problem.
// include the necessary libraries
#include <SPI.h>
#include <SD.h>
#include <TFT.h> // Arduino LCD library
#include <WiFi.h>
// pin definition for the Uno
#define sd_cs 5
#define lcd_cs 6
#define dc 9
#define rst 8
TFT TFTscreen = TFT(lcd_cs, dc, rst);
// wi-fi def
#define wifi_ss 10
#define wifi_sd_ss 4
char ssid[] = "*****"; // your network SSID (name)
char pass[] = "*******"; // your network password
int status = WL_IDLE_STATUS;
// server def
WiFiServer server(25);
// this variable represents the image to be drawn on screen
PImage logo;
void setup() {
// initialize the GLCD and show a message
// asking the user to open the serial line
TFTscreen.begin();
TFTscreen.background(255, 255, 255);
TFTscreen.stroke(0, 0, 255);
TFTscreen.println();
TFTscreen.println(F("Arduino TFT Bitmap Example"));
TFTscreen.stroke(0, 0, 0);
TFTscreen.println(F("Open serial monitor"));
TFTscreen.println(F("to run the sketch"));
delay (5000);
// initialize the serial port: it will be used to
// print some diagnostic info
Serial.begin(9600);
while (!Serial) {
// wait for serial line to be ready
}
// clear the GLCD screen before starting
TFTscreen.background(255, 255, 255);
// try to access the SD card. If that fails (e.g.
// no card present), the setup process will stop.
Serial.print(F("Initializing SD card..."));
if (!SD.begin(sd_cs)) {
Serial.println(F("failed!"));
return;
}
Serial.println(F("OK!"));
// initialize and clear the GLCD screen
TFTscreen.begin();
TFTscreen.background(255, 255, 255);
// now that the SD card can be access, try to load the
// image file.
logo = TFTscreen.loadImage("arduino.bmp");
if (!logo.isValid()) {
Serial.println(F("error while loading arduino.bmp"));
}
Serial.println("Attempting to connect to WPA network...");
Serial.print("SSID: ");
Serial.println(ssid);
if (WiFi.status() == WL_NO_SHIELD) {
// don't continue:
Serial.println("Couldn't find a wifi-shield");
while(true);
}
// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
status = WiFi.begin(ssid, pass);
// wait 5 seconds for connection:
delay(5000);
}
server.begin();
Serial.print("Connected to wifi. My address:");
IPAddress myAddress = WiFi.localIP();
Serial.println(myAddress);
}
void loop() {
// don't do anything if the image wasn't loaded correctly.
if (logo.isValid() == false) {
return;
}
Serial.println(F("drawing image"));
// get a random location where to draw the image.
// To avoid the image to be draw outside the screen,
// take into account the image size.
int x = random(TFTscreen.width() - logo.width());
int y = random(TFTscreen.height() - logo.height());
// draw the image to the screen
TFTscreen.image(logo, x, y);
// wait a little bit before drawing again
delay(1500);
}
hi guys,
I did some experiments with spi pins (miso/mosi) and found that the problem is not in the program, but in hardware. When I diconnected MISO pin from Arduino TFT LCD Screen Wi-Fi shield normaly started. MISO pin is used only for SD-card on board TFT LCD Screen. What the reason?! Why is this pin crashing system? I viewed schematic of TFT LCD Screen (http://arduino.cc/en/uploads/Main/GLCD_sch.pdf). And I think, that I found fatal error. According to standard SPI when SS(CS) pin in HIGH state the device must set MISO port in inactive state. But in our case TFT LCD Screen don't do it due to error in schematic. It conflicts with another devices when data is transfered from them to Arduino.
Looking on schematic. Developers are using chip 74LVC1G125DCK - single bus buffer gate with 3-state output (IC3 on schematic) for MISO output for compatibility 3,3 v Logic level and 5v Logic level. They connected 1 pin of chip on the ground. According datasheet, it is this pin is responsible for setting the output of buffer gate to inactive state. So MISO port always in active state. Developers had to connect 1 pin of chip to the "SD_CSB" bus.
Summing up the Arduino TFT LCD Screen can be used in two modes:
Just as TFT display without sd card. In this case MISO port should not be connected to Arduino. The other spi devices will work properly in project.
As TFT LCD Screen with SD card. In this case MISO port should be connected to Arduino. But other spi devices will not work in project.