Bit of a weird one, but I've not been able to find an answer. Hopefully someone here can help me.
I'm using an Arduino Uno and a mega compatible ethernet shield. Code is straight out of the examples.
Everything works fine when the Arduino is connected to my PC.
However, on standalone power udp.endPacket() returns 0.
If I press the reset button on the ethernet shield, it works perfectly! Unfortunately for this project I won't have easy access to the shield, so I need to find a solution that gets it working on first boot.
Things I've tried: Moving the UDP.Write section to loop(). Adding long (30 second) delays between each line of code. Slamming my head on the desk.
Abridged code here:
void setup ()
{
initLEDs(); //I have LEDs which allow me to error check without using Serial
Ethernet.begin(mac, ip, dns, sub);
delay(500);
if (udp.begin(PORT) == 0)
{
setLEDs(255, 0, 255); //magenta
while (true) delay(1); //do nothing
}
delay(500);
if (udp.beginPacket(server, PORT) == 0)
{
setLEDs(255, 0, 0); //red
while (true) delay(1); //do nothing
}
udp.write(MSG);
if (udp.endPacket() == 0)
{
setLEDs(255, 128, 0); //orange
while (true) delay(1); //do nothing
}
}
void loop ()
{
//udp.read and a bunch of other stuff
delay(10);
}
As I said above, this code works fine after a reset, so I don't think it's a hardware issue. Feels more like a bug that I can't think how to solve.
All advice welcome