lcd Begin & Ethernet.begin

Hello,

I have a problem in to my code. I am using an Arduino Ethernet and i want to print something in my lcd display.

void setup()
{

  // start serial port
  Serial.begin(9600);
  Serial.println("GRobotronics Serial Monitor - Temperature Sensors Check");
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  Serial.println("Initializing...");
  Serial.println();
  delay(5000);
  // Start up the library
  lcd.begin(16, 2);
  sensors.begin();

This is a part of my void setup, when i have the code like this the lcd doesn't printing. But when i put in comment this part of code //Ethernet.begin(mac, ip, gateway, gateway, subnet); the lcd is printing.

Sorry for my pure english, can anyone help me with this issue?

Thanks in advance

Post your full code.

Also what pins are you using to connect the lcd?

#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <Ethernet.h>
#include <LiquidCrystal.h>

// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 8

LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);
// arrays to hold device addresses
DeviceAddress insideThermometer, outsideThermometer;



byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,249);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress server(46, 46, 46, 46);
EthernetClient client;

float tempC ;
float tempC0 ;
float tempC1 ;
char tempBuffer1[8];
char tempBuffer2[8];
int ledPin = 9; 
float oldTemp0;
float oldTemp1;

void setup()
{

  // start serial port
  Serial.begin(9600);
  Serial.println("GRobotronics Serial Monitor - Temperature Sensors Check");
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  Serial.println("Initializing...");
  Serial.println();
  delay(5000);
  // Start up the library
  lcd.begin(16, 2);
  sensors.begin();
  
  // locate devices on the bus
  Serial.print("Found ");
  Serial.print(sensors.getDeviceCount(), DEC);
  Serial.println(" devices.");

  // search for devices on the bus and assign based on an index.
  if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0"); 
  if (!sensors.getAddress(outsideThermometer, 1)) Serial.println("Unable to find address for Device 1"); 

  // show the addresses we found on the bus
  Serial.print("Device 0 Address: ");
  printAddress(insideThermometer);
  Serial.println();

  Serial.print("Device 0 Alarms: ");
  printAlarms(insideThermometer);
  Serial.println();
  
  Serial.print("Device 1 Address: ");
  printAddress(outsideThermometer);
  Serial.println();

  Serial.print("Device 1 Alarms: ");
  printAlarms(outsideThermometer);
  Serial.println();
  
  Serial.println("Setting alarm temps...");

  // alarm when temp is higher than 30C
  sensors.setHighAlarmTemp(insideThermometer, 25);
  
  // alarm when temp is lower than -10C
  sensors.setLowAlarmTemp(insideThermometer, 18);
  
  // alarm when temp is higher than 31C
  sensors.setHighAlarmTemp(outsideThermometer, 30);
  
  // alarn when temp is lower than 27C
  sensors.setLowAlarmTemp(outsideThermometer, 4);
  
  Serial.print("Set Inside Alarm : ");
  printAlarms(insideThermometer);
  Serial.println();
  
  Serial.print("Set Outside Alarm: ");
  printAlarms(outsideThermometer);
  Serial.println();
  

  
  pinMode(ledPin, OUTPUT);
  
}
char pageAdd[32];

// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
  for (uint8_t i = 0; i < 8; i++)
  {
    if (deviceAddress[i] < 16) Serial.print("0");
    Serial.print(deviceAddress[i], HEX);
  }
}

// function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  float tempC0 = sensors.getTempC(insideThermometer);
  float tempC1 = sensors.getTempC(outsideThermometer);
  dtostrf(tempC0,3,1,tempBuffer1);
  dtostrf(tempC1,3,1,tempBuffer2);
  Serial.print("Temp C: ");
  Serial.println(tempC);
}

void printAlarms(uint8_t deviceAddress[])
{
  char temp;
  temp = sensors.getHighAlarmTemp(deviceAddress);
  Serial.print("High Alarm: ");
  Serial.print(temp, DEC);
  Serial.print("C, ");
  temp = sensors.getLowAlarmTemp(deviceAddress);
  Serial.print("Low Alarm: ");
  Serial.print(temp, DEC);
  Serial.print("C");
}

// main function to print information about a device
void printData(DeviceAddress deviceAddress)
{
  //Serial.print("Device Address: ");
  //printAddress(deviceAddress);
  Serial.print(" ");
  printTemperature(deviceAddress);
}

void checkAlarm(DeviceAddress deviceAddress)
{
  if (sensors.hasAlarm(deviceAddress))
  {
    Serial.print("ALARM: ");
    printData(deviceAddress);
    digitalWrite(ledPin, HIGH);   // sets the LED on
    delay(1000);                  // waits for a seconds
  }
}
void sendTemp()
{
  float tempC0 = sensors.getTempC(insideThermometer);
  float tempC1 = sensors.getTempC(outsideThermometer);
  
  if (oldTemp0 != tempC0 || oldTemp1 != tempC1) { 
  Serial.println("Start Sending to database...");
  sprintf(pageAdd,"/arduino.php?temp1=%s&temp2=%s",tempBuffer1,tempBuffer2);
  Serial.print("-->Inside Temperature: ");
  Serial.println(tempBuffer1);
  Serial.print("-->Outside Temperature: ");
  Serial.println(tempBuffer2);
  delay(1000);
  if(!getPage(server,pageAdd));
  }
  oldTemp0 = tempC0;
  oldTemp1 = tempC1;
}

void lcdPrint(void)
{
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Temp is: ");
}

/*-----------------------------------------void loop-----------------------------------------------------------------------*/
void loop(void)
{ 
  digitalWrite(ledPin, LOW);   // sets the LED on
  
  // request to all devices on the bus
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures();
  Serial.println("DONE");
  
  // check each address individually for an alarm condition
  checkAlarm(insideThermometer);
  checkAlarm(outsideThermometer);
  
  // print the device information
  printData(insideThermometer);
  printData(outsideThermometer);
  
  delay(1000);
  
  sendTemp();

  lcdPrint();
  


// if(!getPage(server,pageAdd));
  }

/*-----------------------------------------end void loop-----------------------------------------------------------------------*/


  
byte getPage(IPAddress ipBuf,char *page)
{
  int inChar;
  char outBuf[128];


  Serial.print("connecting...");

  if(client.connect(ipBuf,80))
  {
    Serial.println("connected");

    sprintf(outBuf,"GET %s HTTP/1.1\r\nHost: www.grobotronicsprojects.com\r\n\r\n",page);
    client.write(outBuf);
    Serial.println("Temperatures saved succesfull in your database!!!");
    delay(5000);
  } 
  else
  {
    Serial.println("failed");
  }
  
  while(client.connected())
  {
    while(client.available())
    {
      inChar = client.read();
      //Serial.write(inChar);
    }

    delay(10);
 
  }
  
  Serial.println("disconnecting.");

  Serial.println();
  client.stop();
  Serial.println("<------------------------------------------------->");
  Serial.print("Wait 5sec ");
  for(int x=5;x>0;x--){
  delay(1000);

  Serial.print( x);
  
  
  }
  Serial.println();
  Serial.println("<------------------------------------------------->");
  Serial.println();
}

My pins are right because i test the lcd with another program and it works. Also with this code if you put in comments Ethernet.begin(mac, ip, gateway, gateway, subnet); agian lcd works.

LCD PIN 1 --> GROUND
LCD PIN 2 --> +5V
LCD PIN 3 --> POTENTIOMENTER
LCD PIN 4 --> PIN 12
LCD PIN 5 --> PIN 11
LCD PIN 6 --> PIN 10
LCD PIN 7-10 --> NONE
LCD PIN 11 --> PIN 5
LCD PIN 12 --> PIN 4
LCD PIN 13 --> PIN 3
LCD PIN 14 --> PIN 2
LCD PIN 15 --> +3.3V
LCD PIN 16 --> GROUND

ONEWIRE TEMPERATURES --> PIN 8

Ok so then the next question is, what pins does the ethernet shield use? If they use any of the same pins, you will have problems.

My pins are right because i test the lcd with another program and it works.

No, they aren't. The Ethernet shield uses pins 10, 11, 12, and 13.

With the ethernet shield on, your using all but pins 6 and 7.
10-13: Ethernet shield
9: LED
8: temperature sensor
6-7: open
2-5: LCD

You need to move 10-12 (LCD pins) somewhere else, but you only have 2 digital pins left. So either get rid of the LED on pin 9, or get a I2C LCD adapter.

You might be able to use the analog pins as well.

I am not using a shield, I have arduino Ethernet board not Ethernet shield....

Makes...no...difference...The...ethernet...to...Arduio...communication...is...via...SPI...on...pins...10,,,11,,,12,,,and...13.

Does the extra punctuation really help?

Have a look for yourself.

NB: Pins 10, 11, 12 and 13 are reserved for interfacing with the Ethernet module and should not be used otherwise. This reduces the number of available pins to 9, with 4 available as PWM outputs.

So I need to change the pins of the LCD display???
Does anyone know where I can find help to connect the LCD hd44780 using i2c via mcp23017??

thanasisloi7:
So I need to change the pins of the LCD display???
Does anyone know where I can find help to connect the LCD hd44780 using i2c via mcp23017??

http://blog.littlebirdelectronics.com/arduino-i2c-mcp-23017-lcd-interface

Though its probably easier to buy one of these i2c / SPI character LCD backpack - STEMMA QT / Qwiic : ID 292 : $9.95 : Adafruit Industries, Unique & fun DIY electronics and kits