Multiple value serial communication from processing to arduino

Hi there,

I am wanting to send various different numbers from an API in JSON format used in processing, into arduino so that I can use these numbers as values to control stuff.

I have managed to send data from one variable (S02) over serial port that has been recieved and understood by the arduino which is being used to switch an led if val>1

How would I go about sending and recieving the PM2.5 data alongside the S02 data?

Thanks, Mark

Processing code.....

 import processing.serial.*;


JSONObject json;



// The serial port:
Serial myPort;
String dataReading = "";
String [] dataOutput = {};

void setup() {
size(500,500);
printArray(Serial.list());
// Open the port you are using at the rate you want:
myPort = new Serial(this, Serial.list()[5], 9600); 

myPort.bufferUntil('\n');

}

void draw(){
  updateJSON();
  delay(30000);
}

void updateJSON(){
  
  json = loadJSONObject("http://api.erg.kcl.ac.uk/AirQuality/Hourly/MonitoringIndex/SiteCode=LW2/Json");
  println(json);
  JSONObject haqi = json.getJSONObject("HourlyAirQualityIndex");
  JSONObject la = haqi.getJSONObject("LocalAuthority");
  JSONObject site = la.getJSONObject("Site");
  JSONArray species = site.getJSONArray("species");
  //String siteCode = site.getString("@SiteCode");
  //println(siteCode);

JSONObject sulphur = species.getJSONObject(3); 
JSONObject particulate = species.getJSONObject(2); 
  println(sulphur.getString("@SpeciesName")+" "+sulphur.getString("@AirQualityBand"));
  println(particulate.getString("@SpeciesCode")+" "+particulate.getString("@AirQualityBand"));
  String s0quality = sulphur.getString("@AirQualityIndex");
  String pmquality = particulate.getString("@AirQualityIndex");
  
  println("PM2.5 quality:" + pmquality);
  println("S02 quality:" + s0quality);
  myPort.write(s0quality);
  
  delay(10000);
  
  
}

And my arduino code...

 char val; // Data received from the serial port
 int ledPin = 13; // Set the pin to digital I/O 13



 void setup() {
   pinMode(ledPin, OUTPUT); // Set pin as OUTPUT
   Serial.begin(9600); // Start serial communication at 9600 bps
 }


 void loop() {
   if (Serial.available()) 
   { // If data is available to read,
     val = Serial.read(); // read it and store it in val
   }
   if (val >= '1') 
   { // If 1 was received
     digitalWrite(ledPin, HIGH); // turn the LED on
   } else {
     digitalWrite(ledPin, LOW); // otherwise turn it off
   }
   delay(10); // Wait 10 milliseconds for next reading
}

A way I receive servo command values from the serial monitor.

//zoomkat 11-22-12 simple delimited ',' string parse 
//from serial port input (via serial monitor)
//and print result out serial port
//multi servos added 
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h> 
Servo myservoa, myservob, myservoc, myservod;  // create servo object to control a servo 

void setup() {
  Serial.begin(9600);

  //myservoa.writeMicroseconds(1500); //set initial servo position if desired

  myservoa.attach(6);  //the pin for the servoa control
  myservob.attach(7);  //the pin for the servob control
  myservoc.attach(8);  //the pin for the servoc control
  myservod.attach(9);  //the pin for the servod control 
  Serial.println("multi-servo-delimit-test-dual-input-11-22-12"); // so I can keep track of what is loaded
}

void loop() {

  //expect single strings like 700a, or 1500c, or 2000d,
  //or like 30c, or 90a, or 180d,
  //or combined like 30c,180b,70a,120d,

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',') {
      if (readString.length() >1) {
        Serial.println(readString); //prints string to serial port out

        int n = readString.toInt();  //convert readString into a number

        // auto select appropriate value, copied from someone elses code.
        if(n >= 500)
        {
          Serial.print("writing Microseconds: ");
          Serial.println(n);
          if(readString.indexOf('a') >0) myservoa.writeMicroseconds(n);
          if(readString.indexOf('b') >0) myservob.writeMicroseconds(n);
          if(readString.indexOf('c') >0) myservoc.writeMicroseconds(n);
          if(readString.indexOf('d') >0) myservod.writeMicroseconds(n);
        }
        else
        {   
          Serial.print("writing Angle: ");
          Serial.println(n);
          if(readString.indexOf('a') >0) myservoa.write(n);
          if(readString.indexOf('b') >0) myservob.write(n);
          if(readString.indexOf('c') >0) myservoc.write(n);
          if(readString.indexOf('d') >0) myservod.write(n);
        }
         readString=""; //clears variable for new input
      }
    }  
    else {     
      readString += c; //makes the string readString
    }
  }
}

There are some simple reliable ways to reveive data in serial input basics as well as a parse example.

...R