Loading...
Logo
Processing Forum

Hey  guys, I am going insane and could really use help!

I’m using a little omnidirectional mic as a “sensor” and am trying to throw these readings into a spreadsheet.

The arduino printouts show “meaningful” values. As in, I get a value that makes sense; if it’s quiet, it’s one number, and if I make noise, the number goes up.

However, when it gets to processing, I get this pattern of numbers that just repeats, regardless of what goes on and numbers that don’t match Arduino. Is this because of the kinds of packets of info I am getting from Arduino? I’m going CRAZY!

 

Please help if yall have any ideas!

============================================

ARDUINO

=============================================

Copy code
  1. int sensorPin = 2;
    float val = 0;
  2. void setup(){
    Serial.begin(9600);
  3. }
  4. void loop(){
    val = analogRead(sensorPin)/4.0;
    Serial.print(val,BYTE);
    delay(100);
  5. }

===============================================

==============================================

 

==============================================

PROCESSING

==============================================

Copy code
  1. import processing.serial.*;
    import com.google.gdata.client.spreadsheet.*;
    import com.google.gdata.data.*;
    import com.google.gdata.data.spreadsheet.*;
    import com.google.gdata.util.*;
  2. // Variables structures for google spreadsheet API
    SpreadsheetService service;  //Holds link to all your spreadsheets
    WorksheetEntry worksheet;  //Holds link to the sensor log spreadsheet
    String uname = “breegeek@gmail.com”;  //Your google account user name
    String pwd = “BBBBBBBBBBBBB”;  //Your google account password
    String spreadsheet_name = “sensor log”;  //Name of the spreadsheet you want to write data to.  Must match exactly, including case.
    int spreadsheet_idx = 0; //Index for the “sensor log spreadsheet
  3. //Variables for writing sensor data
    Serial port;  // Create object from Serial class
    int oldTime;  //timer variable
    int reportingInterval = 2000;  //Number of miliiseconds between when sensor data is recorded
  4. // Sends the data to the spreadsheet
    void transmitData(float val) {
    String date = day() + “/” + month() + “/” + year();  //Build the current date
    String time = hour() + “:” + minute() + “:” + second(); //Build the current time
    try {
    //Create a new row with the name value pairs
    ListEntry newEntry = new ListEntry();
    newEntry.getCustomElements().setValueLocal(“date”, date);
    newEntry.getCustomElements().setValueLocal(“time”, time);
    newEntry.getCustomElements().setValueLocal(“reading”, Float.toString(val));
    //Write it out to the google doc
    URL listFeedUrl = worksheet.getListFeedUrl();
    ListEntry insertedRow = service.insert(listFeedUrl, newEntry);
    } catch (Exception e) {
    println(e.getStackTrace());
    }
    }
  5. float val = 0;
    void setup() {
    size(950,600);
    //Set up the serial port to read data
    //This code comes from example 11-8 of Getting Started with Processing
    String arduinoPort = Serial.list()[0];
    port = new Serial(this, arduinoPort, 9600);
    oldTime = millis();
    //Set up the google spreadsheet
    service = new SpreadsheetService(“test”);
    try {
    service.setUserCredentials(uname,  pwd);
    // Search for the spreadsheet named we’re looking for
    // Note that according to the documentation you should be able to include the key in the URL, but I
    // was unable to get this to work.  It looked like there was a bug report in.
    // As a work around, this code pulls a list of all the Spreadheets in your acocunt and searches for the
    // one with the matching name.  When it finds it, it breaks out of the loop and the index is set
    URL feedURL = new URL(“http://spreadsheets.google.com/feeds/spreadsheets/private/full/”);
    SpreadsheetFeed feed = service.getFeed(feedURL, SpreadsheetFeed.class);
    for (SpreadsheetEntry entry: feed.getEntries()) {
    if (entry.getTitle().getPlainText().equals(spreadsheet_name) ) {
    break;
    }
    spreadsheet_idx += 1;
    }
    //Fetch the correct spreadsheet
    SpreadsheetEntry se = feed.getEntries().get(spreadsheet_idx); //Fetch the spreadsheet we want
    worksheet = se.getWorksheets().get(0);  //Fetch the first worksheet from that spreadsheet
    println(“Found worksheet ” + se.getTitle().getPlainText());
  6. } catch (Exception e) {
    println(e.toString());
    }
    }
  7. //Reads the port everye few seconds and sends the data back to Google
    void draw() {
    delay(100);
    if (port.available() > 0) { // If data is available,
    val = port.read();        // read it and store it in val
    }
    //Determine if we need to report the level
    val = map( val, 0, 255, 0, height);
  8. if ((millis() – oldTime) > reportingInterval) {
    oldTime = millis();
    transmitData(val);
    }
  9. println(val);
    }

Replies(1)

Do you happen to have your serial monitor on in the Arduino IDE? Try turning it off and see off and see if you get the right data into processing.