Project tutorial
Post Data to a Google Spreadsheet with Temboo

Post Data to a Google Spreadsheet with Temboo © GPL3+

We'll show you how to make your Arduino Yún add rows of data to a Google spreadsheet. You can use this to log data from sensors connected.

  • 1,215 views
  • 0 comments
  • 7 respects

Components and supplies

Apps and online services

About this project

1. Get Set Up

  • Make sure you have a Temboo account. If you don't already have one, you can register for a free account here.
  • Since this sketch uses a Google spreadsheet, you'll also need a Google account
  • Create a Google Spreadsheet. The columns in your spreadsheet will need to have labels for this example to work. (It doesn't matter what the column labels actually are, but there must be text in the first row of each column.) In this example our spreadsheet has two columns as seen below: time (in milliseconds) and sensor values.
  • Make sure that your Yún is connected to the Internet.

2. Write the Sketch

Copy the sketch code below into a new tab in your Arduino IDE. This code calls the AppendRow Choreo, and you will need to replace the placeholder values in the code with your own Google account details.

/*
 SendDataToGoogleSpreadsheet
 Demonstrates appending a row of data to a Google spreadsheet from the Arduino Yun 
 using the Temboo Arduino Yun SDK.  
 This example code is in the public domain.
*/
#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
// Note that for additional security and reusability, you could
// use #define statements to specify these values in a .h file.
const String GOOGLE_USERNAME = "your-google-username"; // use your full google email address
const String GOOGLE_PASSWORD = "your-google-password";
// the title of the spreadsheet you want to send data to
// (Note that this must actually be the title of a Google spreadsheet
// that exists in your Google Drive/Docs account, and is configured
// as described above.)
const String SPREADSHEET_TITLE = "your-spreadsheet-title";
int numRuns = 1;   // execution count, so this doesn't run forever
int maxRuns = 100;   // the max number of times the Google Spreadsheet Choreo should run
void setup() {
 // for debugging, wait until a serial console is connected
 Serial.begin(9600);
 delay(4000);
 while(!Serial);
 Serial.print("Initializing the bridge... ");
 Bridge.begin();
 Serial.println("Done!\n");
}
void loop()
{
 // while we haven't reached the max number of runs...
 if (numRuns <= maxRuns) {
   Serial.println("Running AppendRow - Run #" + String(numRuns++));
   // get the number of milliseconds this sketch has been running
   unsigned long now = millis();
   Serial.println("Getting sensor value...");
   // get the value we want to append to our spreadsheet
   unsigned long sensorValue = getSensorValue();
   Serial.println("Appending value to spreadsheet...");
   // we need a Process object to send a Choreo request to Temboo
   TembooChoreo AppendRowChoreo;
   // invoke the Temboo client
   // NOTE that the client must be reinvoked and repopulated with
   // appropriate arguments each time its run() method is called.
   AppendRowChoreo.begin();
   // set Temboo account credentials
   AppendRowChoreo.setAccountName(TEMBOO_ACCOUNT);
   AppendRowChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
   AppendRowChoreo.setAppKey(TEMBOO_APP_KEY);
   // identify the Temboo Library choreo to run (Google > Spreadsheets > AppendRow)
   AppendRowChoreo.setChoreo("/Library/Google/Spreadsheets/AppendRow");
   // set the required Choreo inputs
   // see https://www.temboo.com/library/Library/Google/Spreadsheets/AppendRow/ 
   // for complete details about the inputs for this Choreo
   // your Google username (usually your email address)
   AppendRowChoreo.addInput("Username", GOOGLE_USERNAME);
   // your Google account password
   AppendRowChoreo.addInput("Password", GOOGLE_PASSWORD);
   // the title of the spreadsheet you want to append to
   AppendRowChoreo.addInput("SpreadsheetTitle", SPREADSHEET_TITLE);
   // convert the time and sensor values to a comma separated string
   String rowData(now);
   rowData += ",";
   rowData += sensorValue;
   // add the RowData input item
   AppendRowChoreo.addInput("RowData", rowData);
   // run the Choreo and wait for the results
   // The return code (returnCode) will indicate success or failure 
   unsigned int returnCode = AppendRowChoreo.run();
   // return code of zero (0) means success
   if (returnCode == 0) {
     Serial.println("Success! Appended " + rowData);
     Serial.println("");
   } else {
     // return code of anything other than zero means failure  
     // read and display any error messages
     while (AppendRowChoreo.available()) {
       char c = AppendRowChoreo.read();
       Serial.print(c);
     }
   }
   AppendRowChoreo.close();
 }
 Serial.println("Waiting...");
 delay(5000); // wait 5 seconds between AppendRow calls
}
// this function simulates reading the value of a sensor 
unsigned long getSensorValue() {
 return analogRead(A0);
}

3. Create Your Header File

The sketch above references the TembooAccount.h header file, which contains your Temboo account information.

If you are currently logged in, you'll see your Temboo details in the code snippet below (otherwise you'll see placeholder values). Copy this code into a new tab in Arduino and call it TembooAccount.h.

With both files in place you are ready to upload the sketch and start adding data to your spreadsheet. Time to get logging!

Note: The first time you run this sketch, you may receive a warning from Google prompting you to authorize access from a third-party system. Follow their instructions about visiting this page to give your Yún access to your Google account.

#define TEMBOO_ACCOUNT "accountName"  // your Temboo account name 
#define TEMBOO_APP_KEY_NAME "myFirstApp"  // your Temboo app key name
#define TEMBOO_APP_KEY  "abc123xxxxxxxxxxxxxx"  // your Temboo app key

4. What's Next?

Now that you've mastered working with Google Spreadsheets, why not check out the rest of the 2000+ Choreos in our Library and get inspired for your next project.

5. Need Help?

We're always happy to help. Just email us at support@temboo.com, and we'll answer your questions.

Code

Code snippet #1Arduino
/*
  SendDataToGoogleSpreadsheet

  Demonstrates appending a row of data to a Google spreadsheet from the Arduino Yun 
  using the Temboo Arduino Yun SDK.  

  This example code is in the public domain.
*/

#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information

/*** SUBSTITUTE YOUR VALUES BELOW: ***/

// Note that for additional security and reusability, you could
// use #define statements to specify these values in a .h file.

const String GOOGLE_USERNAME = "your-google-username"; // use your full google email address
const String GOOGLE_PASSWORD = "your-google-password";

// the title of the spreadsheet you want to send data to
// (Note that this must actually be the title of a Google spreadsheet
// that exists in your Google Drive/Docs account, and is configured
// as described above.)
const String SPREADSHEET_TITLE = "your-spreadsheet-title";

int numRuns = 1;   // execution count, so this doesn't run forever
int maxRuns = 100;   // the max number of times the Google Spreadsheet Choreo should run

void setup() {
  
  // for debugging, wait until a serial console is connected
  Serial.begin(9600);
  delay(4000);
  while(!Serial);

  Serial.print("Initializing the bridge... ");
  Bridge.begin();
  Serial.println("Done!\n");
}

void loop()
{

  // while we haven't reached the max number of runs...
  if (numRuns <= maxRuns) {

    Serial.println("Running AppendRow - Run #" + String(numRuns++));

    // get the number of milliseconds this sketch has been running
    unsigned long now = millis();
    
    Serial.println("Getting sensor value...");

    // get the value we want to append to our spreadsheet
    unsigned long sensorValue = getSensorValue();

    Serial.println("Appending value to spreadsheet...");

    // we need a Process object to send a Choreo request to Temboo
    TembooChoreo AppendRowChoreo;

    // invoke the Temboo client
    // NOTE that the client must be reinvoked and repopulated with
    // appropriate arguments each time its run() method is called.
    AppendRowChoreo.begin();
    
    // set Temboo account credentials
    AppendRowChoreo.setAccountName(TEMBOO_ACCOUNT);
    AppendRowChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
    AppendRowChoreo.setAppKey(TEMBOO_APP_KEY);
    
    // identify the Temboo Library choreo to run (Google > Spreadsheets > AppendRow)
    AppendRowChoreo.setChoreo("/Library/Google/Spreadsheets/AppendRow");
    
    // set the required Choreo inputs
    // see https://www.temboo.com/library/Library/Google/Spreadsheets/AppendRow/ 
    // for complete details about the inputs for this Choreo
    
    // your Google username (usually your email address)
    AppendRowChoreo.addInput("Username", GOOGLE_USERNAME);

    // your Google account password
    AppendRowChoreo.addInput("Password", GOOGLE_PASSWORD);

    // the title of the spreadsheet you want to append to
    AppendRowChoreo.addInput("SpreadsheetTitle", SPREADSHEET_TITLE);

    // convert the time and sensor values to a comma separated string
    String rowData(now);
    rowData += ",";
    rowData += sensorValue;

    // add the RowData input item
    AppendRowChoreo.addInput("RowData", rowData);

    // run the Choreo and wait for the results
    // The return code (returnCode) will indicate success or failure 
    unsigned int returnCode = AppendRowChoreo.run();

    // return code of zero (0) means success
    if (returnCode == 0) {
      Serial.println("Success! Appended " + rowData);
      Serial.println("");
    } else {
      // return code of anything other than zero means failure  
      // read and display any error messages
      while (AppendRowChoreo.available()) {
        char c = AppendRowChoreo.read();
        Serial.print(c);
      }
    }

    AppendRowChoreo.close();
  }

  Serial.println("Waiting...");
  delay(5000); // wait 5 seconds between AppendRow calls
}

// this function simulates reading the value of a sensor 
unsigned long getSensorValue() {
  return analogRead(A0);
}

Comments

Created by

Temboo_OFFICIAL

Are you Temboo_OFFICIAL? Claim this project and add it to your profile.

This is mine

Posted by

Arduino scuola
Arduino_Scuola
  • 32 projects
  • 97 followers

Published on

July 8, 2016

Members who respect this project

Default10354686 10150004552801856 220367501106153455 nAdambenz

and 4 others

See similar projects
you might like

Similar projects you might like

Send MKR1000 Data to Google Sheets

Project tutorial by Stephen Borsay

  • 9,995 views
  • 28 comments
  • 31 respects

Send an SMS using Twilio with Temboo

Project tutorial by Temboo_OFFICIAL

  • 1,481 views
  • 1 comment
  • 1 respect

Send An Email From Your Gmail Account With Temboo

Project tutorial by Temboo_OFFICIAL

  • 1,390 views
  • 0 comments
  • 2 respects

Read And Update Databases With Temboo

Project tutorial by Temboo_OFFICIAL

  • 2,419 views
  • 2 comments
  • 5 respects

Upload a File to your Dropbox Account with Temboo

Project tutorial by Temboo_OFFICIAL

  • 1,192 views
  • 0 comments
  • 1 respect

Control your Yún from your Phone with Temboo

Project tutorial by Temboo_OFFICIAL

  • 921 views
  • 0 comments
  • 1 respect
Add projectSign up / Login