is it possible to read arduinos erial data with pc and post it to google spreadsheet without using arduino lan module..?
now this code is working fine, it read serial port what arduino sends analogRead(1) and puts it google spreadsheet:)
my question is how to make more analogread cells to spreadsheet
import com.google.gdata.client.spreadsheet.*;
import com.google.gdata.data.*;
import com.google.gdata.data.spreadsheet.*;
import com.google.gdata.util.*;
import java.net.URL;
import processing.serial.*;
String uname = "xxx"; //Your google account user name
String pwd = "xxx"; //Your google account password
String spreadsheet_name = "sensorlog"; //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
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()); } }
void setup() {
//Set up the serial port to read data
//This code comes from example 11-8 of Getting Started with Processing
String arduinoPort = Serial.list()[1];
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() {
float val = port.read();
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
if ((millis() - oldTime) > reportingInterval) {
oldTime = millis();
transmitData(port.read());
}
background(0); // Set background to black
// Draw the letter to the center of the screen
textSize(34);
text(port.read(), 50, 50);
delay(1000);}
how to add arduino example code serialcallresponse to my working code there are arrays..
int firstSensor = 0; // first analog sensor
int secondSensor = 0; // second analog sensor
int thirdSensor = 0; // digital sensor
int inByte = 0; // incoming serial byte
void setup()
{ // start serial port at 9600 bps:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
establishContact(); // send a byte to establish contact until receiver responds
}
void loop()
{ // if we get a valid byte, read analog ins:
inByte = Serial.read();
// read first analog input, divide by 4 to make the range 0-255:
firstSensor = analogRead(0);
// delay 10ms to let the ADC recover:
delay(10);
// read second analog input, divide by 4 to make the range 0-255:
secondSensor = analogRead(1);
// read switch, map it to 0 or 255L
thirdSensor = analogRead(2);
// send sensor values:
Serial.write(firstSensor);
Serial.write(secondSensor);
Serial.write(thirdSensor);
}
void establishContact() {
while (Serial.available() <= 0) {
Serial.print('A'); // send a capital A
delay(300); }}
Hi mortenx ,
stupid question :
the code example above (not the one into the arduino), you make it running in processing ?
where are all the library available ?