Hello i'm new when it comes to programming with Arduino and I have a queston about a script i can't seem to get working.
I am using an Arduino Uno with an Ethernet shield and I am trying to requist an IP using the DHCP server and displaying it on a LCD screen.
I have 2 seperate scripts. The first where I show some random variables on my LCD screen and the second is where I requist an IP.
Both work, I can print the IP the Arduino got assigned and I get a reply when I ping it. But when I try to combine both scripts it just stops at the point where I use Ethernet.localIP(); as far as I can tell.
For the DHPC script I have followed this tutorial:
https://www.inkling.com/read/arduino-cookbook-michael-margolis-2nd/chapter-15/recipe-15-2
And for the LCD screen i'm following chapter 11 of the Arduino projects book and this:
https://www.inkling.com/read/arduino-cookbook-michael-margolis-2nd/chapter-11/recipe-11-1
#include <LiquidCrystal.h>
#include <SPI.h>
#include <Ethernet.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
EthernetClient client;
IPAddress myIPAddress;
void setup()
{
Serial.begin(9600);
lcd.begin(16,2);
lcd.clear();
// start ethernet using mac & DHCP
// if this is not possible
if(!connection)
{
Serial.println("Failed to configure Ethernet using DHCP");
lcd.print("DHCP requist");
lcd.setCursor(0, 1);
lcd.print("Failed");
// no point in carrying on, so stay in endless loop:
while(true);
}
else
{
// show that the IP needs to be requisted from the DHCP server
Serial.println("Requisting IP");
lcd.print("Requisting IP");
lcd.setCursor(0,1);
lcd.print("Waiting for DHCP");
}
// requist IP
ip();
// show the IP
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("The IP is:");
lcd.setCursor(0, 1);
lcd.print(myIPAddress);
Serial.println(myIPAddress);
}
// using ethernet with mac & dhcp
boolean connection()
{
if(Ethernet.begin(mac) == 0)
{
return false;
}
else
{
return true;
}
}
// requisting ip
void ip()
{
delay(1000);
Serial.println("Now requisting IP"); // I receive this print
myIPAddress = Ethernet.localIP();
Serial.println("IP requist succesfull"); // I don't receive this or anyting after this
}
void loop()
{
}