Working with GitHub and Sensors: dataLogger

6 minute read

Where I demonstrate how to use a GitHub repository to develop a data logger with the Arduino Uno to measure and record analog values. In this example, I will be measuring voltage, however the same approach could be used to measure capacitance, temperature, or light etc.

NOTE: The SparkFun Qwiic Alphanumeric Display uses 3.3V and not the 5V from the UNO! Please use a level-shifter or a Pi Pico (or equivalent) when using this specific display.

SparkFun Qwiic Alphanumeric Display

Introduction

GitHub is a valuable tool in the maker space community as a software distribution method. Most Arduino libraries, Adafruit example libraries and open source software tools are on GitHub for distribution. Experienced software developers use GitHub, GitLab or BitBucket as a method to share and collaborate on software projects. For this discussion, I will focus on GitHub.

I have also found students either aren’t familiar with using GitHub or are intimidated as to how to incorporate it into their projects. In this entry, I’ll demonstrate the elements of a simple repository and how to use the software in the repository.

A GitHub Repository

What is a repository? It is typically a collection of software and text files which comprise a project. The repository may be public, for all to see or it might be private, available only to those who have authenticated access. The goal of creating a repository is to share your project with others, in the hopes, they might help you improve it, the positive feelings which sharing provides or even fame and fortune as the “creator of the great…” tool.

The amount of user instruction on a repository provided by the software developer as to how to use their software varies from comprehensive to none. In this entry, I will demonstrate how one might use a GitHub repository. Once you understand how a repository works, you may find and use other repositories which might be of value as well, even if the instructions are minimal.

My GitHub repository dataLogger was specifically written to support this entry. It is intended to be an educational repository. It contains a simple dataLogger program, as well as short programs as to how to accomplish significant steps in the development of dataLogger. I recommend you work through the steps as well, as it will help in your understanding of how to develop a similar program on your own.

Repository Components

To be of value, the repository will have at a minimum two components:

  • README - the README file on the repository is the default program documentation. It provides instructions as to how to install and use the programs on the site.
  • source - the software itself. It might not always be called src, in the repository for this entry, it is called Arduino, to make it very clear the code is intended for the Arduino platform.

Follow both the README and this entry to gain the best understanding of how to 1) develop a data logger and 2) use a GitHub repository for growing your knowledge of software development.

Step 1: Software Installation

This exercise requires both the Arduino program and the GitHub repository mentioned above. For the former, be sure to use the Arduino Legacy IDE 1.8.x, which is about halfway down the page. Do NOT use the Arduino IDE 2.0 for it is too complicated for these examples.

Once you have the Arduino IDE 1.8 installed, go to this GitHub dataLogger repository and follow the Installation instructions.

Step 2: Test

The first program to use in the repository is called a_test, it is also the same as the blink example in the File -> Examples -> 01. Basic -> blink. This file exists to test your setup. By following the Installation steps, you will know that your PC is properly connected to the Uno, the software is installed and working and you are able to compile and upload a program from your PC to the Uno.

It is also important to follow step 9., as this will ensure you are able to make changes and see the resultant behavior on the Uno.

Step 3: Shortcuts

Review the shortcuts on the README. They will save you time. The most important one, is the last one, Reset. From my work with many students, it is apparent that most students don’t understand that they don’t need to upload every time they want to re-run the program. Just press the Reset button!

Step 4: Sketches

We have already executed the initial sketch, test.

Sketch b: analogRead

The next step is to add a potentiometer to the Uno, so you can observe the changes on the ADC or analog pin. Follow the instructions in the README as to adding the potentiometer. Compile and upload the program and while running the program, rotate the potentiometer to the right and to the left.

  • Do the voltages range from 0 to 5V?
  • If you have a digital multimeter (DMM), compare the DC voltages on the DMM with those displayed by the Uno.

Sketch c: analogSave

With analogSave, we increase the capability of the Uno. It can not only read values, it is able to save them when power has been removed or if you close the serial monitor. This latter example requires the next sketch, eepromRead.

Sketch d: eepromRead

Once the serial monitor shows “Out of memory”, the Uno has stopped. It actually hasn’t stopped, it is in a infinite loop, doing nothing. The only way to stop a microcontroller is to remove power.

For our case, it is sufficient to have it in an infinite loop. This will allow us the opportunity to upload a new sketch, eepromRead. This program will read the EEPROM (non-volatile) memory and display it to the screen. Upload the sketch and compare the results from the analogSave program with the results from eepromRead. They need to be identical.

There is a significant issue with the combination of these two programs, analogSave and eepromRead. The latter is only able to read back the data, IF power has NOT been removed from the Uno. In other words, let’s so you use analogSave to collect some values at a remote spot. You remove power from your Uno and bring it back into your lab. Once you plugin the Uno to power, analogSave will immediately begin to record new values! You won’t have sufficient time to upload the eepromRead program to display the original values.

Sketch e: dataLogger

This sketch not only solves the analogSave issue, it adds all of the components outlined above in Setup, as in Initialize, Read, Convert…etc. I wrote it specifically so that each step is Setup is a specific function. This makes it easier to change each functional step based on what you wish to accomplish.

For example, the Convert step is a simple mathematical calculation converting the analog value 0-1023 to a voltage, 0-5V. You could replace the potentiometer with a thermistor, which is a resistor which responds to temperature. There is a complicated formula to use to convert the analog value to temperature. While it is complicated, the only programmatic change is the Convert function, all other functions would remain the same!

You will notice in the documentation, the dataLogger sketch will wait for 10 seconds prior to logging data. This is sufficient time to upload the eepromRead program and display the current data in the EEPROM memory. Thus solving the analogSave issue.

Sketch f: dataLogger_wANdisplay

This final sketch is the one which allows the user to have field-usable dataLogger. It adds a SparkFun Qwiic Alphanumeric Display. The instructions as to how to use the display are at SparkFun Qwiic Alphanumeric Display Hookup Guide. This means, you could use a USB battery pack plugged into the Uno and record and display the voltages. Once the recordings have been made, you can plug the Uno into your PC, quickly upload eepromRead to display the values on your Serial Monitor. Why on the Serial Monitor? It allows you to capture them and save them to a file!

Next Steps

The goal of this entry was to help you become more comfortable with a GitHub repository and learn how to develop a simple Arduino Uno-based datalogger. I would suggest as next steps:

  1. Improve the datalogger so that it might be of value to you. For example, measure the moisture content of a plant using aAdafruit Soil Sensor or measure the temperature in your room using a thermistor.
  2. Create an user account on GitHub
  3. Explore how to use git and GitHUb by this tutorial Hello World

Comments powered by Talkyard.