LCD won't display when Ethernet shield is enabled in code.

Hey,

I can’t get my LCD to display when my ethernet shield is enabled in my code. I’m powering the Arduino via USB on my computer but also via a usb power adapter with 5V and 1A. So I was thinking maybe it was a power issue but it can’t be. Maybe it’s a ground issue?

I can get Helloworld and any other LCD program to run fine. And in my program the LCD displays what is programmed in setup() but when it hits the loop then it simply goes blank. I’m trying to program a DHT22 to upload data to xively.com but also display on my LCD.

Here is the code when it won’t work, it still uploads to xively but the display is blank.

#include <SPI.h>
#include <Ethernet.h>
#include <HttpClient.h>
#include <Xively.h>
#include <DHT22.h>
#include <stdio.h>
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// Data wire is plugged into port 7 on the Arduino
// Connect a 4.7K resistor between VCC and the data pin (strong pullup)
#define DHT22_PIN 7

// Setup a DHT22 instance
DHT22 myDHT22(DHT22_PIN);

//MAC address for your Ethernet shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// Your Xively key to let you upload data
char xivelyKey[] = "rYiAXGBdh7gRtsZv48VWFDr1BWzyVfYdf7kBVIWADceoXQj5";

// Define the strings for our datastream IDs
char sensorId[] = "temperature";
char sensorId2[] = "humidity";
XivelyDatastream datastreams[] = {
   XivelyDatastream(sensorId, strlen(sensorId), DATASTREAM_FLOAT),
   XivelyDatastream(sensorId2, strlen(sensorId2), DATASTREAM_FLOAT),
};
// Finally, wrap the datastreams into a feed
XivelyFeed feed(169608375, datastreams, 2 /* number of datastreams */);

//Start the ethernet client
EthernetClient client;
XivelyClient xivelyclient(client);

void setup() {
  Serial.begin(9600);
  Serial.println("Starting datastream upload to Xively...");
  Serial.println();
  
  //Initiate the LCD and set the display
  lcd.begin(16, 2);
  lcd.print("Temp:");
  lcd.setCursor(0,1);
  lcd.print("Humidity:");

  while (Ethernet.begin(mac) != 1)
  {
    Serial.println("Error getting IP address via DHCP, trying again...");
    delay(15000);
  }
}

void loop() {

  DHT22_ERROR_t errorCode;
  // The sensor can only be read from every 1-2s, and requires a minimum
  // 2s warm-up after power-on.
  delay(2000);
  
  Serial.print("Requesting data...");
  errorCode = myDHT22.readData();
  switch(errorCode)
  {
    case DHT_ERROR_NONE:
      
      //Print the sensor values in the serial monitor
      Serial.print("Got Data ");
      Serial.print(myDHT22.getTemperatureC());
      Serial.print("C ");
      Serial.print(myDHT22.getHumidity());
      Serial.println("%");
      
      //Set LCD to display temperature and humidity floats
      lcd.setCursor(6,0);
      lcd.print(myDHT22.getTemperatureC());
      lcd.setCursor(10,1);
      lcd.print(myDHT22.getHumidity());
    
      //Put the floats into the xively feed array
      datastreams[0].setFloat(myDHT22.getTemperatureC());
      datastreams[1].setFloat(myDHT22.getHumidity());
     
      break;
    case DHT_ERROR_CHECKSUM:
      Serial.print("check sum error ");
      Serial.print(myDHT22.getTemperatureC());
      Serial.print("C ");
      Serial.print(myDHT22.getHumidity());
      Serial.println("%");
      break;
    case DHT_BUS_HUNG:
      Serial.println("BUS Hung ");
      break;
    case DHT_ERROR_NOT_PRESENT:
      Serial.println("Not Present ");
      break;
    case DHT_ERROR_ACK_TOO_LONG:
      Serial.println("ACK time out ");
      break;
    case DHT_ERROR_SYNC_TIMEOUT:
      Serial.println("Sync Timeout ");
      break;
    case DHT_ERROR_DATA_TIMEOUT:
      Serial.println("Data Timeout ");
      break;
    case DHT_ERROR_TOOQUICK:
      Serial.println("Polled to quick ");
      break;
  }

  //Upload all of the data to xively
  Serial.println("Uploading it to Xively");
  int ret = xivelyclient.put(feed, xivelyKey);
  Serial.print("xivelyclient.put returned ");
  Serial.println(ret);

  Serial.println();
  delay(15000);
}

Here it is when I comment the ethernet stuff out, see attached.

#include <SPI.h>

#include <Ethernet.h>
#include <HttpClient.h>
#include <Xively.h>
#include <DHT22.h>
#include <stdio.h>
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

You appear to be using the SPI which uses pins 3, 4, and 5 of PortB.
You are using Arduino pins 11, and 12 for the LCD. These are pins 3 and 4 of Port B.
You can avoid this conflict on Port B by choosing some other available I/O pins on your Arduino for the LCD RS and E lines. Make sure you change the LiquidCrystal lcd(…) parameters to reflect these new pins.

Don

Hey Don,

That was exactly it! I simply changed the pins to 9, 8 instead of 12, 11 on the board and in the LCD begin. Now the code looks like this and it works perfect. Thanks!

#include <SPI.h>
#include <Ethernet.h>
#include <HttpClient.h>
#include <Xively.h>
#include <DHT22.h>
#include <stdio.h>
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(9, 8, 5, 4, 3, 2);

// Data wire is plugged into port 7 on the Arduino
// Connect a 4.7K resistor between VCC and the data pin (strong pullup)
#define DHT22_PIN 7

// Setup a DHT22 instance
DHT22 myDHT22(DHT22_PIN);

//MAC address for your Ethernet shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// Your Xively key to let you upload data
char xivelyKey[] = "rYiAXGBdh7gRtsZv48VWFDr1BWzyVfYdf7kBVIWADceoXQj5";

// Define the strings for our datastream IDs
char sensorId[] = "temperature";
char sensorId2[] = "humidity";
XivelyDatastream datastreams[] = {
   XivelyDatastream(sensorId, strlen(sensorId), DATASTREAM_FLOAT),
   XivelyDatastream(sensorId2, strlen(sensorId2), DATASTREAM_FLOAT),
};
// Finally, wrap the datastreams into a feed
XivelyFeed feed(169608375, datastreams, 2 /* number of datastreams */);

//Start the ethernet client
EthernetClient client;
XivelyClient xivelyclient(client);

void setup() {
  Serial.begin(9600);
  Serial.println("Starting datastream upload to Xively...");
  Serial.println();
  
  //Initiate the LCD and set the display
  lcd.begin(16, 2);
  lcd.print("Temp:");
  lcd.setCursor(0,1);
  lcd.print("Humidity:");

  while (Ethernet.begin(mac) != 1)
  {
    Serial.println("Error getting IP address via DHCP, trying again...");
    delay(15000);
  }
}

void loop() {

  DHT22_ERROR_t errorCode;
  // The sensor can only be read from every 1-2s, and requires a minimum
  // 2s warm-up after power-on.
  delay(2000);
  
  Serial.print("Requesting data...");
  errorCode = myDHT22.readData();
  switch(errorCode)
  {
    case DHT_ERROR_NONE:
      
      //Print the sensor values in the serial monitor
      Serial.print("Got Data ");
      Serial.print(myDHT22.getTemperatureC());
      Serial.print("C ");
      Serial.print(myDHT22.getHumidity());
      Serial.println("%");
      
      //Set LCD to display temperature and humidity floats
      lcd.setCursor(6,0);
      lcd.print(myDHT22.getTemperatureC());
      lcd.setCursor(10,1);
      lcd.print(myDHT22.getHumidity());
    
      //Put the floats into the xively feed array
      datastreams[0].setFloat(myDHT22.getTemperatureC());
      datastreams[1].setFloat(myDHT22.getHumidity());
     
      break;
    case DHT_ERROR_CHECKSUM:
      Serial.print("check sum error ");
      Serial.print(myDHT22.getTemperatureC());
      Serial.print("C ");
      Serial.print(myDHT22.getHumidity());
      Serial.println("%");
      break;
    case DHT_BUS_HUNG:
      Serial.println("BUS Hung ");
      break;
    case DHT_ERROR_NOT_PRESENT:
      Serial.println("Not Present ");
      break;
    case DHT_ERROR_ACK_TOO_LONG:
      Serial.println("ACK time out ");
      break;
    case DHT_ERROR_SYNC_TIMEOUT:
      Serial.println("Sync Timeout ");
      break;
    case DHT_ERROR_DATA_TIMEOUT:
      Serial.println("Data Timeout ");
      break;
    case DHT_ERROR_TOOQUICK:
      Serial.println("Polled to quick ");
      break;
  }

  //Upload all of the data to xively
  Serial.println("Uploading it to Xively");
  int ret = xivelyclient.put(feed, xivelyKey);
  Serial.print("xivelyclient.put returned ");
  Serial.println(ret);

  Serial.println();
  delay(15000);
}