“Read SGP30” Command-Line Tool

published: December 19, 2020 — last modified: October 23, 2025

I published another small command-line tool for Raspberry-Pi. This time one to read data from the Sensirion SGP30 sensor.

While you can communicate over I2C with sensors using Python, I found it not as reliable as using compiled C or C++ programs. To combine the two worlds, I started writing really small command-line tools, which do the communication with the sensors.

These tools give you a lot of flexibility. You can call them on the command-line directory, to test if the sensors are working as expected. Or, you call them from your python scripts and parse the returned JSON data.

Usage

If you call the tool with no arguments, it will read the current measurements.

pi:~ $ read_sgp30 
{ "co2_ppm": 861, "tvoc_ppb": 145 }

With the argument -h or --help, you will get a list of possible actions and options.

pi:~ $ read_sgp30 --help
Usage: read_sgp30 [arguments]
 -h --help    Display this help.
 -v --version Display the application version.
 -r           Read the measurements (default).
 -i           Initialize the measurements.
 -t           Perform a measurement test.
 -s           Read serial number.
 -z           Reset the sensor (and other sensors on the same bus!).
 -xs          Store the iAQ baseline.
 -xr          Restore the iAQ baseline.
 -b0 -b1      Select the bus. 1 is the default.
 -d           Show debugging messages.

How to Compile and Install the Tool

In order to compile and install the tool on your Raspberry-Pi, you need to install the compiler, CMake and the I2C-Tools first:

pi:~ $ sudo apt install gcc cmake i2c-tools

Download the files the git repository to a subdirectory in your home. In this example, I downloaded the files to the directory /home/pi/read_sgp30.

Now create a separate build directory. In this example, I create the directory /home/pi/build_read_sgp30.

Next switch to the build directory, execute cmake to create the build script. Build the executable with make and install the executable in your system using sudo make install.

pi:~/ $ cd build_read_sgp30
pi:~/build_read_sgp30/ $ cmake ../read_sgp30
pi:~/build_read_sgp30/ $ make
pi:~/build_read_sgp30/ $ sudo make install

Download

Download or clone the repository from GitHub:

License

The code is licensed under the GPL license version 3.

Available Sensors

The SGP30 sensor is available from various sources as breakout board. Here two examples:

Conclusion

As a software-architect, I always split large software into small and easy to maintain modules. It makes my life, and the life of the support staff easier. Using small tools, which can be combined into a large complex system, is one of the main philosophies of Unix. 😎

I hope, if this tool may not be exactly what you need, it will at least inspire you to write modular software. Have a look at the well documented code, it will provide you a good base to write similar tools.

If you have any questions, missed information, or simply want to provide feedback, feel free to comment below or contact me on Twitter. 😄

More Posts

SMD LEDs Tests

Posted on 2017-02-16— Fun, Projects

I tested 13 SMD LEDs for my plant-watering sensor project, soldering them to a small board and driving them from an Arduino Zero Pro to compare brightness and flash styles. I share photos, part numbers and a short demo video — read on if you’d like the full results and notes.

Read this post

Use Enum with More Class!

Posted on 2019-07-29— C++, Improve your Code, Learn

I explain C++11 enum class: why it prevents name conflicts, how it compares to traditional enums and common workarounds, with practical Arduino-friendly examples. If you want clearer, safer enum usage in your interfaces, read the full post for code samples and simple best-practice guidance.

Read this post

Adafruit PowerBoost 1000C Enclosure (LR2165)

Posted on 2021-08-21— 3D Printing, Projects

I designed a simple three-part 3D printed enclosure for the Adafruit PowerBoost 1000C and up to a 1200mAh LiPo. In this post I share the print files, component list, and step-by-step assembly tips to convert the board into a safe portable power pack — please read on if you'd like to build one.

Read this post

Snowflake Component Side

Posted on 2017-11-14— Projects

I walk through assembling the component side of my snowflake panel, showing stencil-applied solder paste, placement of 105 resistors, capacitors, headers and chips, and sped-up hot-air soldering. I test the LEDs at the end — please read/watch the full post if you'd like the complete build and tips.

Read this post

Building a Magnet Matrix

Posted on 2016-09-08— Projects

I built an 8×8 neodymium magnet matrix to keep steel-ball switches in place under a PCB for my Outmoded Sequencer. I walk through marking and drilling 64 holes, gluing each magnet, and sealing with acrylic paint. If you're curious to try this practical approach, read the full post for step-by-step tips.

Read this post

Snowflake Power Converter

Posted on 2018-01-11— Projects

I built a simple USB-to-3.3V power converter for my snowflake decoration using a Traco TSR2-2433 and a laser-cut acrylic case with glow-in-the-dark engravings. I'll walk through the board, Fusion360/Eagle workflow, laser cutting and painting - read on if you want the files and build notes.

Read this post