Forums > MaxMSP

Problems with UDP communication (between MAX and Arduino)

September 28, 2012 | 4:57 pm

Hello everybody, I have a problem sending data via MAX/MSP to an Arduino.

This is a prntscreen of the MAX sketch I’ve made
[img]http://i.imgur.com/keCxR.png[/img]
Pretty simple stuff, it collects 3 bytes generated randomly by 3 different "drunk" functions and send them via UDP to the Arduino.

This is the Arduino code

#include
#include
#include

#define localPort 7400

byte mac[] = {0×90, 0xA2, 0xDA, 0x0D, 0xE5};      
IPAddress ip(192, 168, 1, 177);                

EthernetUDP Udp;                                  

int PACKET_SIZE = 0;

void setup()                                      
{
 Serial.begin(9600);
 Ethernet.begin(mac, ip);
 Udp.begin(localPort);
}

void loop()
{
 PACKET_SIZE = Udp.parsePacket();
 byte packetBuffer[PACKET_SIZE];
 
 if (PACKET_SIZE > 0)                            
 {
   Udp.read(packetBuffer, PACKET_SIZE);
   
   for (int i = 0; i    {
     Serial.print(packetBuffer[i]);
     
     if (i < (PACKET_SIZE - 1))
       Serial.print(", ");
     else
       Serial.println(".");
   }
 }
}

Easy, it prints into the serial monitor the data recevied via UDP by MAX/MSP. The problem is here…
[img]http://i.imgur.com/KzKfr.png[/img]

I should receive only 3 bytes, I can’t understand why I get 28! Also – the correct ones – are the 20th, 24th and 28th. Seems like the others are something that comes from MAX/MSP but I don’t know why and I don’t know how to avoid this problem. I’m looking for some help, hope you’ll enlighten me guys!
Thanks for your tips!

PS: I’ve just discovered something cool, the first 4 bytes (108, 105, 115, 116) compose the word "list" according the ASCII table, could this help?


September 28, 2012 | 8:29 pm

Hi Matt,

the reason is that [udpsend] sends data in OSC format, not as a plain binary stream. Therefore, you have two choices:

(1) Change your code in Arduino in a way that would get the floats from the OSC stream.
(2) Use another object in Max to send pure binary data to your Arduino. For the latter, you might be interested in the networking objects contained by my free library (see http://www.sadam.hu/software ). Particularly, [sadam.udpSender] should be your friend.

HTH,
Ádám


September 29, 2012 | 7:34 am

Thanks a lot for your reply, I will check right now!


Viewing 3 posts - 1 through 3 (of 3 total)