I have been searching the forums for examples on how to print out an ip address on a 20x4 HD44780 display; specifically, I am modifying the DHCP example to print out the DHCP obtained IP address. The code is shown below. After I print out the lcd.print("Network Address: "); line, I get gibberish on the LCD, where i should have an IP address. I have searched and found projects shown on you tube, but no one posts their code. I know I am new to the Arduino and learning, but I don't understand why I can't print out the bytes of the IP address array correctly????
/*
DHCP-based IP printer
This sketch uses the DHCP extensions to the Ethernet library
to get an IP address via DHCP and print the address obtained.
using an Arduino Wiznet Ethernet shield.
Circuit:
- Ethernet shield attached to pins 10, 11, 12, 13
created 12 April 2011
by Tom Igoe
*/
#include <SPI.h>
#include <Ethernet.h>
// include the library code:
#include <LiquidCrystal.h>
//
//define variables
//
int lcdcols = 20;
int lcdrows = 4;
int delaytime = 1000;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xA7, 0x3E }; //ACTUAL MAC ADDR of my Arduino
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
void setup() {
// set up the LCD's number of columns and rows; clear display and set the cursor position.
lcd.begin(lcdcols, lcdrows);
lcd.clear();
lcd.setCursor(0,0);
//initial Project Message prints here.
lcd.print("DHCP IP Grabber.");
delay(delaytime); // delay so we can confirm its working.
lcd.clear(); // clear display
lcd.print("Obtaining IP...");
delay(delaytime);
lcd.clear();
lcd.print("Network Address: "); //
lcd.setCursor(0,1);
// start the serial library:
Serial.begin(9600);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for(;
;
}
// print your local IP address
Serial.println("Network Address: "); // This is sent to serial, and shows correctly
//
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC); //this shows up fine in Arduino IDE window...
lcd.print(Ethernet.localIP()[thisByte], DEC); // I GET GIBBERISH HERE>>
Serial.print(".");
lcd.print("."); //
}
Serial.println();
}
void loop() {
}