Thank you both for the input, I have managed to get two sketches working. One sends the test msg using UDP and the second receives the msg on the other end.
Write Arduino*
#include <Ethernet.h>
#include <EthernetUdp.h>
// MAC address and IP addresses.
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);
IPAddress remoteIP(192, 168, 1, 200); // Receiver IP address
unsigned int localPort = 8888; // local port to listen on UNUSED
unsigned int remotePort = 8888; // Remote port to transmit on
// buffer for sending data
char SendBuffer[] = "Test Hello"; // a string to send
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;
void setup() {
// start the Ethernet
Ethernet.begin(mac, ip);
// Open serial communications and wait for port to open:
Serial.begin(9600);
// start UDP
Udp.begin(localPort);
}
void loop() {
//Serial.println(remoteIP);
//Serial.println(remotePort);
// send data to the remote IP address and port
Udp.beginPacket(remoteIP, remotePort);
Udp.write(SendBuffer);
Udp.endPacket();
Serial.println(SendBuffer);
delay(1000);
}
Receiver Arduino*
#include <Ethernet.h>
#include <EthernetUdp.h>
// 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, 0xDE
};
IPAddress ip(192, 168, 1, 200);
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
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
}
// start UDP
Udp.begin(localPort);
}
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();
Serial.print(", port ");
Serial.println(Udp.remotePort());
// read the packet into packetBufffer
Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
Serial.print("Contents:");
Serial.println(packetBuffer);
}
delay(10);
}
So the "write" Arduino sends a UDP packet to "Receiver" Arduino which works perfectly.
The new task is to find a data type compatible with the analogreads of the A0-A5 on the "Write" Arduino and fit that into an appropriate format that can be sent via the UDP packet.
I first tried an array, which on the "Write" Arduino is easy:
valx = analogRead(X_pin);
valx = map(valx, 0, 1023, 0, 180);
PWMArray[0]=valx;
valy = analogRead(Y_pin);
valy = map(valy, 0, 1023, 0, 180);
PWMArray[1]=valy;
psw = digitalRead(SW_pin);
PWMArray[2]=psw;
When printed to serial gives the desired values.
How to get this array sent via UDP or am I just not seeing how to do that?