UDPSendReceiveString w/ Processing

Hi all,

Very new to Arduino, trying to set it up for a project I’m working on. I am currently trying to run the UDPSendReceiveString example with Processing running a script on my computer so that I can communicate to my Arduino Uno directly from my laptop. According to the documentation, I should be able to press a letter on the Processing monitor, and I should receive a message from the Arduino. However, this doesn’t seem to be working. My questions are:

  1. Is the Processing monitor that little grey square that pops up when you run the script?
  2. Should I be receiving the text from the Arduino on the Arduino’s serial monitor?
  3. Why am I not receiving anything? How do I test that I’m even sending anything?

Arduino code:

 This sketch receives UDP message strings, prints them to the serial port
 and sends an "acknowledge" string back to the sender

 A Processing sketch is included at the end of file that can be used to send
 and received messages for testing with a computer.

 created 21 Aug 2010
 by Michael Margolis

 This code is in the public domain.

#include <SPI.h>         // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h>         // UDP library from: bjoern@cs.stanford.edu 12/30/2008

// 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, 0xED
IPAddress ip(192, 168, 1, 177);

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 and UDP:
  Ethernet.begin(mac, ip);


void loop() {
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  if (packetSize) {
    Serial.print("Received packet of size ");
    Serial.print("From ");
    IPAddress remote = Udp.remoteIP();
    for (int i = 0; i < 4; i++) {
      Serial.print(remote[i], DEC);
      if (i < 3) {
    Serial.print(", port ");

    // read the packet into packetBufffer
    Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);

    // send a reply to the IP address and port that sent us the packet we received
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());

Processing code:

 import hypermedia.net.*;

 UDP udp;  // define the UDP object

 void setup() {
 udp = new UDP( this, 6000 );  // create a new datagram connection on port 6000
 //udp.log( true );         // <-- printout the connection activity
 udp.listen( true );           // and wait for incoming message

 void draw()

 void keyPressed() {
 String ip       = ""; // the remote IP address
 int port        = 8888;        // the destination port

 udp.send("Hello World", ip, port );   // the message to send


 void receive( byte[] data ) {          // <-- default handler
 //void receive( byte[] data, String ip, int port ) {   // <-- extended handler

 for(int i=0; i < data.length; i++)

What is the IP of the PC? Windows? How are they connected? Direct or router?

I use Ubuntu and RPi to interface with Arduino UDPSendReceiveString without a hitch.

PC is Windows. Connection is from ethernet shield directly to pc ethernet port. IP is

Then you have two choices.

  1. Change the IP of the Arduino to match the PC
    or better
  2. Change the PC IP to 192.168.1.x/24 (not

I changed my IP to on my Processing sketch and Arduino sketch. I still haven't gotten it to work. My interface on the bottom of the Processing IDE is not interactive. Could that be the problem?

When you check the network configuration on your Windows laptop, does it show
Are you running the processing program from a terminal (command prompt)?

Do you mean my IPv4 address? Because it does not…but if I change the IP to the IPv4 address, I don’t get anything useful.

And, I’m running the Processing program from the Processing IDE. I can try running it from the terminal though.

Keeping the IP as (not sure why I’m doing this or what it means), if I comment out the draw() function I receive the following console print:
– UDP session started at Tue Jun 06 16:39:10 PDT 2017 –
– bound socket to host:null, port: 6000 –
[17-06-06 16:39:10.864 -0700] close socket < port:6000, address:null >

Yes, the IPv4 address. Change the IP on the laptop to the same localnet as the Arduino.

Insure the PC doesn’t have another conflicting subnet (like wifi adapter). Insure the wifi adapter (if one installed) doesn’t have a 192.168.1.x IP.

Maybe you need to do a bit of reading about networks, specifically IP addresses, netmasks, and localnets.