Five days later, can’t get data from arduino
Hey guys, I am going insane and could really use help!
I’m using a little omnidirectional mic as my “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
=============================================
int sensorPin = 2;
float val = 0;
void setup(){
Serial.begin(9600);
}
void loop(){
val = analogRead(sensorPin)/4.0;
Serial.print(val,BYTE);
delay(100);
}
===============================================
==============================================
==============================================
PROCESSING
==============================================
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.*;
// 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
//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
// 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());
}
}
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());
} catch (Exception e) {
println(e.toString());
}
}
//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);
if ((millis() – oldTime) > reportingInterval) {
oldTime = millis();
transmitData(val);
}
println(val);
}
hilalkoyuncu 2:18 am on March 20, 2011 Permalink |
Hi Bree,
I am just using the Xbees them selves without Arduinos. I recommend you do the same, it is just easier if you are not trying to create a crazy complicated system.
-Configure your Xbees as its shown in the 5th chapter.(API mode)
-I think you might have to enter ATD03 instead of ATD02 because your sensor will not be a digital input.
-When building the circuit use a piezo instead of a temp sensor cause it has a transducer and it will pick up sound as you are trying to do.
-Use the processing sketch given for reading temperature, tweak it so that it will draw what you want to visualize. You can simply use the “temp” value in the sketch
as the input for your visualizer.
-Enjoy the awesomeness of your project!:)
breegeek 2:17 pm on March 20, 2011 Permalink |
Thanks ill try that!