UDPSendReceiveString example disables pin output?

Hi,

Ive sucessfully setup the UDPSendRecieveStringExample , and it outputs the UDP packets fine to the serial monitor. However, if I try and turn an LED on or off, nothing happens. This is the case on the built in pin13 too. Changing the code to the ‘Blink’ example and everything works fine, so it’s not a hardware problem.

From my quick look , it seems to be in the EthernetUDP library, as as soon as you instantiate a new instance of the class, the pins stop working.

#include <SPI.h>         // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h>         // UDP library from: bjoern@cs.stanford.edu 12/30/2008


// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {  
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 177);

unsigned int localPort = 8888;      // local port to listen on

// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
char  ReplyBuffer[] = "acknowledged";       // a string to send back

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

void setup() {
  // start the Ethernet and UDP:
  Ethernet.begin(mac,ip);
  Udp.begin(localPort);

  Serial.begin(9600);
    pinMode(12, OUTPUT);  
}

void loop() {
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  if(packetSize)
  {
    Serial.print("Received packet of size ");
    Serial.println(packetSize);
    Serial.print("From ");
    IPAddress remote = Udp.remoteIP();
    for (int i =0; i < 4; i++)
    {
      Serial.print(remote[i], DEC);
      if (i < 3)
      {
        Serial.print(".");
      }
    }
    Serial.print(", port ");
    Serial.println(Udp.remotePort());

    // read the packet into packetBufffer
    Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
    Serial.println("Contents:");
    Serial.println(packetBuffer);

    // send a reply, to the IP address and port that sent us the packet we received
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write(ReplyBuffer);
    Udp.endPacket();
    
     digitalWrite(12, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  digitalWrite(12, LOW);  
  }
  delay(10);
}

Can anybody help? Even just running my code to see if it works on there board?

Thanks.

This is the case on the built in pin13 too.

If you are using an ethernet shield to send/receive these UDP packets, perhaps you ought to make yourself aware of the pins that the ethernet shield uses. Hint: 10, 11, 12, 13, and 4.

Yes. Thank you! Switching to pin9 solved this. I'd been tearing my hair out and tried pins 11 and 12 before, so assumed that wasn't the issue.

Thanks again