These examples use the Google Sheets API from the Pico LTE over the cellular connection: create a spreadsheet, add data and rows, delete data and read it. They need a Google Cloud project with the Sheets API, OAuth credentials, an API key and a refresh token.
Before you begin
Hardware
- Sixfab Pico LTE or Pico LTE 2Registered and active in Sixfab Connect, connected to the computer with the micro USB cable.
Software
- Thonny with MicroPython and the Pico LTE SDKSet up as in the quickstart.
- config.jsonIn the root of the board: Prepare the configuration file.
- Google accountFor the Google Cloud Console and Google Sheets.
Set up Google Sheets API
-
Create project.
-
Enable Google Sheets API.
Select the project, open APIs & Services, click ENABLE APIS AND SERVICES, search for Google Sheets API and enable it.



-
Configure consent screen.
Click Create Credentials, select Google Sheets API and User data, and continue.


Fill in the app information, with your Gmail address in both email fields, and click SAVE AND CONTINUE.

-
Add scopes.
Click ADD OR REMOVE SCOPES, search for
spreadsheets, tick the scope and click UPDATE. Do the same fordrive, then click SAVE AND CONTINUE.




-
Create OAuth client.
Select Web application, name the client and add
http://localhostandhttps://developers.google.com/oauthplaygroundto Authorized redirect URIs, then create it.
Download the client information: the file holds the client ID and the client secret.

-
Publish app.
In Enabled APIs & services, click PUBLISH APP, then CONFIRM.

-
Create API key.
Under Credentials, create an API key and keep it.


Get refresh token
-
Open OAuth 2.0 Playground.
Open developers.google.com/oauthplayground, open the settings and enter your client ID and client secret. The client secret is also in Credentials → OAuth 2.0 Client IDs: click the client name, then see Client secrets under Additional information.

-
Authorize Sheets scope.
Select
https://spreadsheets.google.com/feeds/in the list on the left and click Authorize APIs.
Choose your account, then click Advanced and Go to MyApp (unsafe), then Continue.


-
Exchange code for tokens.
Click Exchange authorization code for tokens: a refresh token appears without it too, but the exchange gives a new one. Keep the refresh token.


Prepare spreadsheet
Every example except Create Sheet works on an existing spreadsheet. Create one in Google Sheets, or with Create Sheet below. The spreadsheet ID is in its URL, https://docs.google.com/spreadsheets/d/[SPREADSHEET_ID]; add or rename a sheet with the buttons at the bottom: the examples name the sheet.


Run examples
The scripts are in the examples/google_sheets folder of the SDK repository. In config.json, set the values you saved:
{
"google_sheets": {
"api_key": "[API_KEY]",
"spreadsheetId": "[SPREADSHEET_ID]",
"client_id": "[CLIENT_ID]",
"client_secret": "[CLIENT_SECRET]",
"refresh_token": "[REFRESH_TOKEN]"
}
}
Open the script in Thonny, set the parameters of its function and click Run.
create_sheet.py creates a spreadsheet; spreadsheetId is not needed in config.json: the function writes the new spreadsheet’s ID there itself.
| Parameter | Type | Use |
|---|---|---|
sheets | list, default None | Names of the sheets of the new spreadsheet; up to 5 are recommended. |

The new spreadsheet is in your Google Sheets, with its sheets.


add_data.py writes values to a range of cells.
| Parameter | Type | Use |
|---|---|---|
sheet | str, default None | Name of the target sheet. |
data | list, default None | Values to write, as a two-dimensional list. |
data_range | str, required | Target cell range, in A1 notation. |


add_row.py appends rows after the last row of the sheet.
| Parameter | Type | Use |
|---|---|---|
sheet | str, default None | Name of the target sheet. |
data | list, default None | Values of the rows, as a two-dimensional list. |


delete_data.py clears a range of cells. Put some data in the sheet first.

| Parameter | Type | Use |
|---|---|---|
sheet | str, default None | Name of the target sheet. |
data_range | str, default None | Cell range to clear, in A1 notation; without it, the whole sheet. |


get_data.py reads a range of cells and prints it in the shell. Put some data in the sheet first.

| Parameter | Type | Use |
|---|---|---|
sheet | str, default None | Name of the target sheet. |
data_range | str, default None | Cell range to read, in A1 notation; without it, the whole sheet. |

If sheet is not given, the functions read it from a sheet key in the google_sheets section of config.json.

