Skip to main content
Skip table of contents

Monitor with GoogleDrive (App Note)

If you own a LabJack device, have Python installed, and have a Google account, you may find this App Note to be of interest.  You can create a program that posts collected data to a Google Sheets spreadsheet so you can view your collected data from anywhere, for free!

Google Sheets Logging with Python 3

The program below was contributed by Darby Bates of University of Toronto and is adapted and maintained by LabJack Corporation engineers. 

Follow these steps to log data from a LabJack device to a spreadsheet with the Python 3 Google API: 

  1. Ensure that you have a distribution of Python 3 installed. 

  2. Ensure that you have the LabJack LJM Python package installed.

  3. Ensure that you have the other necessary Python packages installed including gspread and oauth2client.

  4. Download and unzip the example Python logging script. Ensure that you have downloaded the proper Python script (T7Pro_GoogleSheet.py) and not the deprecated Python 2 script from the second section of this App Note. 

  5. Login to the Google devolopers API console with your Google account.

  6. From your Google API dashboard, click CREATE PROJECT.

  7. Name your project (this name cannot be changed later so double check spelling, formatting, etc.). Then click CREATE

  8. For your new project, click +ENABLE APIS AND SERVICES.

  9. In the Search for API's & Services search box, search for "Google Sheets API" and then after selecting the API, click ENABLE

  10. Similarly, in the Search for API's & Services search box, search for and enable the "Google Drive API".

  11. From the same project, from the Navigation menu (the three horizontal lines in the top left of the console) navigate to APIs and Services > Dashboard.

  12. Select the Credentials tab on the left hand side of the console and then click +CREATE CREDENTIALS.

  13. In the credentials creation menu, select Create service account. Then name your service account and click CREATE

  14. In the service account permissions menu under role, select ProjectEditor and click CONTINUE.

  15. Select +CREATE KEY and choose to download the key in JSON format.

  16. Place this downloaded key in the same directory as the example python script and rename it as client_secret.json.

  17. With your Google account create a new Google Sheet, and give it a unique name.

  18. Enter this unique name in line 22 of the python script:
    SPREADSHEETNAME = 'LJ Test Sheet' #Edit spreadsheet name here between the '' characters, replacing LJ Test Sheet with your sheet's unique name. 

  19. From your Google API dashboard for the same project created in step 7, select the Credentials tab on the left and then under service accounts, click on the service account created in step 13. Copy the email address in the email text box. This email can also be found in the downloaded JSON file in the field client email. 

  20. Then, in your Google sheet created in step 17, share the sheet with email address of the service account, and give it edit permissions. 

  21. Now, the Google sheet, the APIs, and the service account should be formatted correctly and the program is ready to run. Navigate to the directory that contains the example python script and the renamed JSON key and run the python script. 

  22. If the script ran correctly, the second row of your Google sheet should now contain a timestamp, and the values read from AIN0, AIN1, and AIN2 from your connected LabJack device.  

  23. Every time that the script is run, the second row of the sheet will be updated and all older data will be pushed down one row.

Google Sheets Logging with Python 2 (Deprecated)

Follow these steps to log data from a LabJack device to a spreadsheet with the Python 2 Google API and a U3

  1. Make sure that LabJackPython is installed.

  2. Download and install Google's Python API.

  3. Try Google's API example located in the root directory and then samples/spreadsheets to make sure you installed it properly
    to run: python spreadsheetExample.py --user [yourUserName] --pw [yourPassword]

  4. The program should display all of the spreadsheet files created in your Google Drive account, and let you open and change values of the file.

  5. Download the example program that opens a U3 device and stores information to a created Google Drive spreadsheet.

  6. Create a spreadsheet and modify the example program's SPREADSHEET_NAME, WORKSHEET_NAME, GOOGLE_USER_NAME, and GOOGLE_PASSWORD string constants.

  7. If needed, change the LabJack device being opened. The program was written for a U3, so change U3s to U6s or UE9s.

  8. Run program!

Two Step Verification

Do you have two step verification enabled on your account? If so you need to generate a new application-specific password and use that as your password for the example program.

Files

T7Pro_GoogleSheet.zip

googleDocsSpreadsheetExample.py_.txt

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.