read incoming serial data as a string?

edited October 2014 in Arduino

I have an Arduino program that is sending data to Processing via serial. It is meant to send a heads up message based on what kind of data is to follow. For example, when I want the Arduino to pipe some image data via serial, the message begins with ">IMG:". So I'd like to test for that string, then do something with the array of numbers that follow.

  if ( port.available() > 0) {  // If data is available,
    //val =;         // read it and store it in val

    String test[] = {

    for (int i = 0; i < test.length; i++) {
      test[i] = str(char(;
    if(test == "> I M G :") {

I can never figure out how to make Processing play nice with strings. I just want to take in the first 4 chars and see if combined they form ">IMG:"

Also, if the Arduino is sending serial data as HEX, is there anything special I need to do when reading via Processing to make sure it safely converts to a usable int of the same value?


Sign In or Register to comment.