Go Down

Topic: Problem opening UDP port (Read 294 times) previous topic - next topic


I have a very basic problem with my first attempt to send 'hello' via UDP from a Leonardo ETH
My code appears to fail at Udp.begin(localPort)
I never reach 'debug point 2'
If I check the return value from this call I get 0, meaning it has failed to open the port.
I suspect I have a very basic misunderstanding.
Any help please?
Thank you

Code: [Select]

//Arduino Leonardo ETH
#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

byte mac[] = {0x90, 0xA2, 0xDA, 0x11, 0x2D, 0xC4};  //MAC for Arduino
IPAddress ip(192, 168, 0, 2); //IP address for Arduino
IPAddress ip1(192, 168, 0, 1);  //IP Address of far machine

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

EthernetUDP Udp;

void setup() {
  Serial.begin(9600);   //Serial port for debugging
  while(!Serial);       //wait for serial port to become available
  Ethernet.begin(mac, ip);  // start the Ethernet and UDP:
  Serial.print("Debug point 1");
  Serial.print("Debug point 2");
void loop() {
  Udp.beginPacket(ip1, outPort);


I have solved my own problem.
With Leonardo ETH I need to use header <Ethernet2.h> NOT <Ethernet.h>
do NOT include <EthernetUdp.h>

And it all works!

Go Up