Вы находитесь на странице: 1из 6

https://temboo.

com/arduino/others/update-google-spreadsheet
Save Arduino data to spreadsheets

We'll show you how to make your Arduino add rows of data to a Google
spreadsheet. You can use this to log data from sensors connected to your Arduino,
like temperature readings over time, or other instances where your Arduino is
receiving information you'd like to record.
This sketch uses our Google > Spreadsheets > AppendRow Choreo.
GET SET UP
1Make sure you have a Temboo account. If you don't already have one, you can
register for a free account here.
2Next, make sure that you've got the latest version the Arduino IDE installed.
3Since this sketch uses a Google spreadsheet, you'll also need a Google
account.
4Login to Google's Developer Console, and create a new Project if you haven't
done so already.
5Under APIs & auth > APIs, make sure you've enabled API Access for the
Google Drive API.
6Under APIs & auth > Credentials, create a new Client ID and specify Web
application for the Application Type.
7When configuring the Consent Screen, make sure you fill out the Email
Address and Product Name fields.
8Save the Consent Screen details and specify this callback URL as
the Authorized Redirect URI:
https://ACCOUNT_NAME.temboolive.com/callback/google
COPY
9Run the Google > OAuth > InitializeOAuth Choreo, specifying the Client ID
from the app you registered at Google and the following Scope:
https://spreadsheets.google.com/feeds/

The InitializeOAuth choreo will return an authorization URL and a callback ID


(required for the FinalizeOAuth step).
10Open a new web browser, navigate to the authorization URL returned by the
InitializeOAuth Choreo, and click "Accept" to grant the app access to your Google
account.

11Run the Google > OAuth > FinalizeOAuth Choreo, specifying the callback ID
returned earlier by the InitializeOAuth Choreo. This process will return a Refresh
Token which can be used along with the Client ID and Client Secret to authenticate
with Google.

12Create 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.

A screenshot of a spreadsheet taking data from an Arduino - note the column


names
AUTO-GENERATE THE SKETCH
13Go to the Google > Spreadsheets > AppendRow in our Library.
14Turn on IoT Mode and make sure that you've added details about the shield that
your Arduino board is using to connect to the internet.
15Test out the Choreo from our website and confirm that your Google
Spreadsheet was updated successfully.

Testing the AppendRow Choreo from our website


16When you've confirmed that the Choreo runs successfully, you can copy the
auto-generated Arduino code from theCode section and paste it into your Arduino
IDE.
17The auto-generated sketch references the TembooAccount.h header file, which
contains your Temboo account information and internet shield details. You'll find
the code for this file beneath your generated sketch. Create a new tab in the
Arduino IDE called TembooAccount.h and copy in the header file information.
RUN THE SKETCH

18With both files in place you are ready to upload the sketch and start adding
data to your spreadsheet. Time to get logging!
EXTENDING THE SKETCH
You'll notice that your sketch always sends the same value to your spreadsheet. Of
course, it's far more interesting to send dynamic values i.e., sensor values. Here's
an example of what you need to do to make that happen.
19Add the follow line of code to your setup() method so that you're reading the
value on pin A0:
pinMode(A0, INPUT);
COPY
20Next, replace the line of code that currently adds data to your spreadsheet with
the following two lines so that your sketch reads the value on pin A0 and adds it to
the spreadsheet instead:
String sensorValue = (String)analogRead(A0);
AppendRowChoreo.addInput("RowData", sensorValue);
COPY
21That's it! Now your sketch should be generating dynamic values and adding
them to your Google Spreadsheet.
WHAT'S NEXT?
Now that you've mastered working with Google Spreadsheets, why not check out
the rest of the 2000+ Choreos in ourLibrary and get inspired for your next project.
Once you've got your code up and running, you're ready to move on and do more.
From monitoring your running applications, to moving your generated Temboo code
to your preferred development environment and sharing it with colleagues,
collaborators and friends - we've got you covered.
GET LIVE UPDATES ABOUT YOUR APPLICATION
Integrate Temboo with Slack to get up-to-the-second notifications and
alerts about your deployed Temboo code.
COMMIT CODE TO GITHUB
Commit Temboo-generated code directly to GitHub and share with the world. Learn
more.
NEED HELP?

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


answer your questions.

Вам также может понравиться