Datalogging of data sent from Arduino to PC using Bluetooth

edited October 2017 in Arduino

Hi,

I have an arduino reading six input values sending them over bluetooth to a PC receiving the data on COM4. The data is coded in the arduino code to have commas seperating the sensor data. I am looking to be able to read the data from the bluetooth and log it in an excel file simultaneously showing the time, date and then the six data values in seperate columns. Can someone help me with this? A code I have started so far is below.

    //import the required libraries
    import processing.serial.*;

    Serial mySerial;
    Table table;
    String filename;

    void setup()
    {
      //set mySerial to listen on COM port 10 at 9600 baud
      mySerial = new Serial(this, "COM4", 9600);

      table = new Table();
      //add a column header "Data" for the collected data
      //add a column header "Time" and "Date" for a timestamp to each data entry
      table.addColumn("Date");
      table.addColumn("Time");
      table.addColumn("Occupancy");
      table.addColumn("Lights");
      table.addColumn("Door");
      table.addColumn("Voltage");
      table.addColumn("WindMPH");
      table.addColumn("Temperature");

    }

    void draw()
    {
      //variables called each time a new data entry is received
      int d = day();
      int m = month();
      int y = year();
      int h = hour();
      int min = minute();
      int s = second();
      float[] data;

      if(mySerial.available() > 0)
      {
        //set the value recieved as a String
        //String value = mySerial.readString();
        String[] value =  loadStrings(mySerial.readString());
        data = float(split(value[0], ','));
        //check to make sure there is a value
        if(value != null)
        {
          //add a new row for each value
          TableRow newRow = table.addRow();
          //place the new row and date under the "Date" column
          newRow.setString("Date", str(d) + "/" + str(m) + "/" + str(y));
          //place the new row and time under the "Time" column
          newRow.setString("Time", str(h) + ":" + str(min) + ":" + str(s));
          //place the new row and value under the "Data" column
          newRow.setString("Occupancy", data[1]);
          newRow.setString("Lights", data[2]);
          newRow.setString("Door", data[3]);
          newRow.setString("Voltage", data[4]);
          newRow.setString("WindMPH", data[5]);
          newRow.setString("TempC", data[6]);



        }
      }
    }

    void keyPressed()
    {
      //variables used for the filename timestamp
      int y = year();
      int d = day();
      int m = month();
      int h = hour();
      int min = minute();
      int s = second();
      //variable as string under the data folder set as (mm-dd--hh-min-s.csv)
      filename = str(m) + "-" + str(d) + "-" + str(y) + "--" + str(h) + "-" + str(min) + "-" + str(s) + ".csv";
      //save as a table in csv format(data/table - data folder name table)
      saveTable(table, filename);
      exit();
    }

Answers

  • Hi Elizabeth, You haven't shown your Arduino code but so I'm guessing you have nothing to indicate the start of data. I think you need a unique text at the beginning e.g. 'Start," or [[ or anything to make sure the Processing stays in sync. The something unique on the end e.g. carriage-return.

    Please see my comment to almost the same problem here.

Sign In or Register to comment.