I'm trying to stack up Arduino UNO, Ethernet Shield and Waveshare 2.8" TFT Shield. Since I'm new to this I'm mostly doing basic stuff.
I successfully manage to get ethernet shield and TFT shield to work individually. Then since TFT shield will not be able to use the ICSP interface I connected the jumpers as it says on wiki.
Hardware configuration
- When using the Arduino board with ICSP interface, the jumpers SB1, SB2 and SB3 on the LCD module should be kept open.
- When using the Arduino board without ICSP interface, the jumpers SB1, SB2 and SB3 on the module should be connected with a 0R resistor, respectively.
After this I put everything together and try to get them working with the below code but for some reason I don't know, Ethernet shield stopped working. I get the error Ethernet shield was not found. Sorry, can't run without hardware. :(
. Even though the error, my TFT screen lights up and runs demo. Probably I'm missing something simple. I'll appreciate any help or guidance.
#include <stdint.h>
#include <LCD.h>
#include <SPI.h>
#include <Ethernet.h>
IPAddress server(192, 168, 0, 107);
IPAddress ip(192, 168, 0, 177);
IPAddress myDns(192, 168, 0, 1);
IPAddress gateway(192, 168, 0, 1);
EthernetClient client;
byte mac[] = {0x90, 0xA2, 0xDA, 0x00, 0x23, 0x36};
void setup()
{
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
/*--------- TFT Init -------------*/
SPI.setDataMode(SPI_MODE3);
SPI.setBitOrder(MSBFIRST);
SPI.setClockDivider(SPI_CLOCK_DIV4);
SPI.begin();
Tft.lcd_init();
/*--------- TFT Init End -------------*/
/*--------- Ethernet Setup -------------*/
Serial.println("Initialize Ethernet with DHCP:");
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
} else if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
}
// no point in carrying on, so do nothing forevermore:
// while (true) {
// delay(1);
// }
}
// print your local IP address:
Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());
/*--------- Ethernet Setup End -------------*/
/*--------- Ethernet Connection Demo Setup -------------*/
if (client.connect(server, 3000)) {
Serial.print("connected to ");
Serial.println(client.remoteIP());
// Make a HTTP request:
client.println("GET / HTTP/1.1");
client.println("Host: localhost");
client.println("Connection: close");
client.println();
} else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
beginMicros = micros();
/*--------- Ethernet Connection Demo Setup End -------------*/
}
void loop()
{
/*--------- TFT Demo -------------*/
Tft.lcd_clear_screen(WHITE);
for (int x = 1; x <= 240; x++) {
for (int y = 1; y <= 320; y++) {
Tft.lcd_draw_rect(x, y, 1, 1, RED);
delay(1);
}
}
/*--------- TFT Demo End -------------*/
/*--------- Ethernet Check-Up ---------*/
switch (Ethernet.maintain()) {
case 1:
//renewed fail
Serial.println("Error: renewed fail");
break;
case 2:
//renewed success
Serial.println("Renewed success");
//print your local IP address:
Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());
break;
case 3:
//rebind fail
Serial.println("Error: rebind fail");
break;
case 4:
//rebind success
Serial.println("Rebind success");
//print your local IP address:
Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());
break;
default:
//nothing happened
break;
}
/*--------- Ethernet Check-Up End ---------*/
/*--------- Ethernet Demo ---------*/
int len = client.available();
if (len > 0) {
byte buffer[80];
if (len > 80) len = 80;
client.read(buffer, len);
if (printWebData) {
Serial.write(buffer, len); // show in the serial monitor (slows some boards)
}
byteCount = byteCount + len;
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
endMicros = micros();
Serial.println();
Serial.println("disconnecting.");
client.stop();
Serial.print("Received ");
Serial.print(byteCount);
Serial.print(" bytes in ");
float seconds = (float)(endMicros - beginMicros) / 1000000.0;
Serial.print(seconds, 4);
float rate = (float)byteCount / seconds / 1000.0;
Serial.print(", rate = ");
Serial.print(rate);
Serial.print(" kbytes/second");
Serial.println();
// do nothing forevermore:
// while (true) {
// delay(1);
// }
}
/*--------- Ethernet Demo End ---------*/
}