Hi guys,
I am trying to use UDPSendReceiveString example with my Mega 2560 and Arduino Ethernet shield 2 and getting this error message: "Ethernet cable is not connected"
include <Ethernet.h>
#include <EthernetUdp.h>
byte mac[] = {
0xA8, 0x61, 0x0A, 0xAE, 0x2A, 0x12
};
IPAddress ip(192, 168, 137, 30);
unsigned int localPort = 8888; // local port to listen on
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() {
// You can use Ethernet.init(pin) to configure the CS pin
Ethernet.init(10); // Most Arduino shields
// start the Ethernet
Ethernet.begin(mac, ip);
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
while (true) {
delay(1); // do nothing, no point running without Ethernet hardware
}
}
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
}
// start UDP
Udp.begin(localPort);
}
The mac address could be found on the back side of the shield and the ip address is the one that I manually typed in the network configuration. Since I am not using any router and directly connected the shield with my laptop, I set turned on the sharing function of my WLAN. But do I need this even I just need to send values from my laptop to Arduino via UDP? Well, nevertheless the linkStatus is off all the time.
I would be thanksful to any suggestion.