Data Parsing from Serial

edited January 2014 in Programming Questions

Hello all.

I'm working with a Processing-Arduino interface, but this is more of a programming question. The Arduino is receiving data via sms, and my goal is to parse and save the data using Processing and make a data visualization real-time, at the same time. Right now i don't have the admin rights to change the program in arduino so that data parsing could be easier.

Things successfully done: 1. Data parsing with a logged data. CoolTerm was used to logged the data, then converted to a .csv file. The original data is Space Delimited. Data parsing done in Processing. Here is my code, based on programs by cool programmers : :)


String addCo2Alas = "F:\\co2_alas.csv";
String addCo2Isle = "F:\\co2_isle.csv";
String[] lines;
String a = "mcAlas";
String m = "mcisle";

void setup() {
  size(600, 600);
  lines = loadStrings("co2.csv");
  for (int i = 0; i < lines.length; i++) {
    float co2Gas, airTemp, lakeTemp7, lakeTemp50;
    float laLevel;
    String date, time, station; 

    if (lines[i] != null) {
      String[] val = splitTokens(lines[i], " ,");
      if (val[6].equals(m)) {
        co2Gas = float(val[0]);
        airTemp = float(val[1]);
        lakeTemp7 = float(val[2]);
        lakeTemp50 = float(val[3]);
        date = val[4];
        time = val[5];
        station = val[6];
        appendData(addCo2Isle, date+" "+time+","+co2Gas+","+airTemp+","+lakeTemp7+","+lakeTemp50);
      }else if(val[6].equals(a)){
        airTemp = float(val[1]);
        lakeTemp7 = float(val[2]);
        lakeTemp50 = float(val[3]);
        date = val[4];
        time = val[5];
        station = val[6];
        appendData(addCo2Alas, date+" "+time+","+laLevel+","+airTemp+","+lakeTemp7+","+lakeTemp50);

void draw() {

void appendData(String filename, String text) {
  File f = new File(dataPath(filename));
  // if(!f.exists()){
  // createFile(f);
  // }
  try {
    PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f, true)));
  catch(IOException e) {
  1. Data visualization based in the example from the book 'Distributed Network Data' (page 121.).

  2. Connected with sms receiver serially. Here is my code(just checked if the data will come in:

    import processing.serial.*;
    Serial port;
    //String addCo2Alas = "F:\\CO2\\co2_alas.csv";
    //String addCo2Isle = "F:\\CO2\\co2_isle.csv";
    //String addCo2Opet = "F:\\CO2\\co2_opet.csv";
    //String discard = "F:\\CO2\\co2_opet.csv";
    //String[] lines;
    //String a = "mcAlas";
    //String m = "mcisle";
    //String o = "mcopet";
    String[] header = {"goodnyt", "CMGF=1", "AT+CNMI=3,0,0,0,0", "OK", "AT+CMGD=1,4", "OK"};
    void setup() {
      size(820, 600);
      Serial port = new Serial(this, "COM6", 9600);
    void draw() {
      background(125, 45, 76);
    void serialEvent(Serial port) {
      String input = port.readString();
      if (input != null) {
       // port.clear();

Foreseen problems: 1. In CoolTerm the data streaming is slightly different compared to what is printed in the Processing console. Is it possible to make it look like the CoolTerm streaming? Please see attached figures.


  1. I would like to start the data logging after the AT commands. What method/function should i use?

  2. Basically, i'm having problems dealing with the live streaming data.



  • Oh btw, i already tried to do data parsing and data visualization using DHT11 sensor in arduino, it turned out smoothly. I did'nt expect that data coming from an sms receiver would be very different.


    Saling :)

Sign In or Register to comment.