I'm trying to send and receive information via UDP between Arduino (+Ethernet Shield v3) and VVVV, for the moment I didn't manage to send or receive anything from/in Arduino.
here is my setup :
Arduino (+Ethernet Shield v3) plugged into my internet Box (which is also a router)
computer also plugged into the router
I opened the udp port i need using the router manager (udp 8888)
I'm pretty sure the problem don't come from vvvv as I use it often whereas I just started learning arduino.
I tried the Ethernet/WebServer example and it worked, I got information from my computer in the Serial monitor, and I got analog values from pins in my browser using the correct IP.
So I tried a small example of UDP sender from Arduino and for the moment I didn't get anything coming into vvvv.
here is my code (I removed anything unrelated to the UDP communication here) :
#include <SPI.h>
#include <Ethernet.h>
#include <OSCBundle.h>
#include <EthernetUdp.h>
byte mac[] = {
0x90, 0xA2, 0xDA, 0x0F, 0x3B, 0x9D
};//the one on the back of my shield
IPAddress ip(192, 168, 0, 2); // Ethernet Shield IP
IPAddress ip_PC(192, 168, 0, 1); // computer local IP (seen in IPconfig)
unsigned int localPort = 8888;
EthernetClient client;
EthernetUDP Udp;
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
char ReplyBuffer[] = "bien reçu";
void setup() {
Serial.begin(9600);
Ethernet.begin(mac, ip);
Udp.begin(localPort);
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for (;;)
;
}
// print your local IP address:
printIPAddress();
}
void printIPAddress()
{
Serial.print("<EthernetShieldIP>");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println("<IP>");
}
void loop() {
Udp.beginPacket(ip_PC, localPort);
Udp.write("hello");
Udp.endPacket();
}
And nothing seems to be coming into my computer on UDP port 8888
Does somebody have any idea of what i'm doing wrong here ?
that doesn't work anymore, I got some print function on digital pins (where i put switches) and when I manipulate those switches, nothing is printed anymore in the Serial monitor, but when I quote those 3 problematic lines of code, the rest works again.
Use either a static ip or dhcp. I recommend dhcp to start with.
// comment out these two lines
// Ethernet.begin(mac, ip);
// Udp.begin(localPort);
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for (;;)
;
}
// move Udp.begin to here
Udp.begin(localPort);
SurferTim -> that worked ! after i quoted the Ethernet.begin line + moving the Udp.begin line after the the if(...), vvvv started receiving information from arduino !
great ! thanks a lot !
so the idea here is to use ip OR dhcp, but not both of those parameters ?
PaulS -> I'm sorry i don't understand what it means in this case to ignore the returning value, and what i can do to prevent it, in most examples i've found of UDP sending from Arduino, i didn't found one with a return XXX used, but I'm novice so I must miss what you're meaning.
Use either static or dhcp. If you use static, insure you set all Ethernet.begin() parameters. Your router does not use 192.168.0.1 as a dns server or the network gateway.
If you use dhcp, insure you call Ethernet.maintain() in your loop function. That function does nothing until it is time to renew your ip lease.
so if i'm right, as I know that my router doesn't allow static IP to devices (I'll modify that later) I should for the moment use the dhcp and so the Maintain function.