Problem Reading/Parsing ASCII characters into arduino over UDP


I have a Leonardo board with an ethernet shield which i am trying to read 76 different ASCII characters (representing 76 different keys on a keyboard) coming into an arduino over UDP. This is then parsed and used to send out Keyboard.write functions over usb. With my current code i can read all alpha numeric keys (A-Z) sent as ASCII (from Max/MSP). Any other characters (space, number keys etc.) aren’t being read, the serial monitor just outputs ‘list’. I can see they are being read into the packet buffer so i think i have a problem with the code i am using for reading the char’s.

Any thoughts are really appreciated.

Here is the code im running.

Leonardo IN - IP Port 8999  Mac - 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEF

#include <SPI.h>         // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h>         // UDP library from: 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, 0xEF };
IPAddress ip(192, 168, 1, 177);

unsigned int localPort = 8999;      // 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:

//  Serial.begin(9600);
//  while (!Serial) {
 //   }


void loop() {
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();

    // read the packet into packetBufffer,UDP_TX_PACKET_MAX_SIZE);

    if (packetBuffer[0] == 'a') {
    //  Serial.println("A was pressed");
    if (packetBuffer[0] == 'b') {
 //     Serial.println("B was pressed");

    if (packetBuffer[0] == 'c') {
  //    Serial.println("C was pressed");

        if (packetBuffer[0] == 'd') {
  //    Serial.println("D was pressed");

        if (packetBuffer[0] == 'e') {
  //    Serial.println("E was pressed");

        if (packetBuffer[0] == 'f') {
 //     Serial.println("F was pressed");

        if (packetBuffer[0] == 'g') {
  //    Serial.println("G was pressed");
    //from here the commands do not execute
        if (packetBuffer == "F11") { //f11
//      Serial.println("F11");
        if (packetBuffer == "F12") { //f12
//      Serial.println("F12");
        if (packetBuffer[0] == '0') { //1
//      Serial.println("RShift was pressed");
        if (packetBuffer[0] == '1') { //1
//      Serial.println("1 was pressed");
        if (packetBuffer[0] == '2') { //1
//      Serial.println("2 was pressed");
        if (packetBuffer == "Spc") { // space bar
//      Serial.println("spacebar was pressed");
        if (packetBuffer == "Win") { // windows key
//      Serial.println("gui key was pressed");


Jamie Hamilton
        if (packetBuffer == "Spc") { // space bar

The address of an array will NEVER equal a string literal.

Using 7 if statements to determine that you need to write the character in position 0 of the array is silly, That could be done with one compound if statement.

the serial monitor just outputs 'list'.

There is nothing in the code that makes this happen. Therefore, it isn't happening.

You might print out the received characters similar to below as hex or decimal representation of the characters so the “non printable” ones can be viewed. Also, the attached ASCII chart might be of use.

    INFO =;
    Serial.println(INFO, DEC);
    //Serial.println(INFO, HEX);