Reputation: 15
I am trying to implement a webserver using the W1500 shield (I think it's called that) that also links to a 16x2 LCD and some DHT22 sensors. In my setup function, I have Ethernet.begin(mac, ip);
but I can only utitlize the lcd.print()
function before calling Ethernet.begin()
. After calling this, any lcd.print()
does not have any effect (even in the loop, the print function does nothing).
What would cause this and how can I get around this?
Thank you!
(This is my first post, I'm bound to have done something wrong so please let me know!)
#include "DHT.h"
#include <SPI.h>
#include <Ethernet.h>
#include <Vector.h>
#include <LiquidCrystal.h>
#define DHTPIN1 6
#define DHTPIN2 7
#define DHTPIN3 8
#define DHTTYPE DHT22
DHT dht[] = {
{DHTPIN1, DHT22},
{DHTPIN2, DHT22},
{DHTPIN3, DHT22},
};
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
byte ip[] = { 10, 0, 0, 99 };
EthernetServer server(80);
float h[3];
float t[3];
float tf[3];
float avgTempC = 0.00;
float avgTempF = 0.00;
float avgHumid = 0.00;
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup()
{
lcd.begin(16, 2);
// THIS CORRECTLY PRINTS TO LCD
lcd.print("TEMP: HUMID:");
for (auto& sensor : dht) {
sensor.begin();
}
Ethernet.begin(mac, ip);
server.begin( );
// HERE IS WHERE IT DOES NOT WORK
String avgTString = String(avgTempF);
String avgHString = String(avgHumid);
lcd.setCursor(0, 1);
lcd.print(avgTString + "F");
lcd.setCursor(8, 1);
lcd.print(avgHString + "%");
Serial.print("server.begin() called\n");
}
void loop() {...}
Upvotes: 0
Views: 296
Reputation: 36
You did not mention which ethernet board and which microcontroller board you actually use.
Please check which pins are used by your ethernet shield. Please have a look at the technical description of your ethernet shield.
If you have - for example - an Arduino Ethernet Shield V1, you find the details here: https://www.arduino.cc/en/Main/ArduinoEthernetShieldV1
Arduino communicates with both the W5100 and SD card using the SPI bus (through the ICSP header). This is on digital pins 10, 11, 12, and 13 on the Uno and pins 50, 51, and 52 on the Mega. On both boards, pin 10 is used to select the W5100 and pin 4 for the SD card. These pins cannot be used for general I/O. On the Mega, the hardware SS pin, 53, is not used to select either the W5100 or the SD card, but it must be kept as an output or the SPI interface won't work.
You cannot use these pins to communicate with the LCD - at least if the LCD does not also use SPI (e.g. if it is connected via 74HC595 shift registers) and even then, you'd have to deselect the other SPI devices and then select the LCD device. For details, see: https://www.arduino.cc/en/reference/SPI
Upvotes: 1