UDPSendReceiveString w/ Processing
hi all,
very new arduino, trying set project i'm working on. trying run udpsendreceivestring example processing running script on computer can communicate arduino uno directly laptop. according documentation, should able press letter on processing monitor, , should receive message arduino. however, doesn't seem working. questions are:
1) processing monitor little grey square pops when run script?
2) should receiving text arduino on arduino's serial monitor?
3) why not receiving anything? how test i'm sending anything?
arduino code:
processing code:
very new arduino, trying set project i'm working on. trying run udpsendreceivestring example processing running script on computer can communicate arduino uno directly laptop. according documentation, should able press letter on processing monitor, , should receive message arduino. however, doesn't seem working. questions are:
1) processing monitor little grey square pops when run script?
2) should receiving text arduino on arduino's serial monitor?
3) why not receiving anything? how test i'm sending anything?
arduino code:
code: [select]
/*
udpsendreceivestring:
this sketch receives udp message strings, prints them serial port
and sends "acknowledge" string sender
a processing sketch included @ end of file can used send
and received messages testing computer.
created 21 aug 2010
by michael margolis
this code in public domain.
*/
#include <spi.h> // needed arduino versions later 0018
#include <ethernet.h>
#include <ethernetudp.h> // udp library from: bjoern@cs.stanford.edu 12/30/2008
// enter mac address , ip address controller below.
// ip address dependent on local network:
byte mac[] = {
0xde, 0xad, 0xbe, 0xef, 0xfe, 0xed
};
ipaddress ip(192, 168, 1, 177);
unsigned int localport = 8888; // local port listen on
// buffers receiving , sending data
char packetbuffer[udp_tx_packet_max_size]; //buffer hold incoming packet,
char replybuffer[] = "acknowledged"; // string send back
// ethernetudp instance let send , receive packets on udp
ethernetudp udp;
void setup() {
// start ethernet , udp:
ethernet.begin(mac, ip);
udp.begin(localport);
serial.begin(9600);
}
void loop() {
// if there's data available, read packet
int packetsize = udp.parsepacket();
if (packetsize) {
serial.print("received packet of size ");
serial.println(packetsize);
serial.print("from ");
ipaddress remote = udp.remoteip();
(int = 0; < 4; i++) {
serial.print(remote[i], dec);
if (i < 3) {
serial.print(".");
}
}
serial.print(", port ");
serial.println(udp.remoteport());
// read packet packetbufffer
udp.read(packetbuffer, udp_tx_packet_max_size);
serial.println("contents:");
serial.println(packetbuffer);
// send reply ip address , port sent packet received
udp.beginpacket(udp.remoteip(), udp.remoteport());
udp.write(replybuffer);
udp.endpacket();
}
delay(10);
}
processing code:
code: [select]
import hypermedia.net.*;
udp udp; // define udp object
void setup() {
udp = new udp( this, 6000 ); // create new datagram connection on port 6000
//udp.log( true ); // <-- printout connection activity
udp.listen( true ); // , wait incoming message
}
void draw()
{
}
void keypressed() {
string ip = "192.168.1.177"; // remote ip address
int port = 8888; // destination port
udp.send("hello world", ip, port ); // message send
}
void receive( byte[] data ) { // <-- default handler
//void receive( byte[] data, string ip, int port ) { // <-- extended handler
for(int i=0; < data.length; i++)
print(char(data[i]));
println();
}
what ip of pc? windows? how connected? direct or router?
i use ubuntu , rpi interface arduino udpsendreceivestring without hitch.
i use ubuntu , rpi interface arduino udpsendreceivestring without hitch.
Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > UDPSendReceiveString w/ Processing
arduino
Comments
Post a Comment