Lucky Resistor
Menu
  • Home
  • Learn
    • Learn C++
    • Product Photography for Electronics
      • Required Equipment and Software
    • Soldering for Show
  • Projects
  • Libraries
  • Applications
  • Shop
  • About
    • About Me
    • Contact
    • Stay Informed
  •  
Menu

“Read SGP30” Command-Line Tool

Posted on 2020-12-19 by Lucky Resistor

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:

Read SGP30 on 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:

  • Pimoroni SGP30 Board
  • Adafruit SGP30 Board

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

Better Bridging with Slicer Guides

Better Bridging with Slicer Guides

I got questions about a particular feature you find if some of my 3D models. In this short text, I will explain why I add it and why you should add features like this too ...
Read More
Large Update to the Circle Pattern Generator

Large Update to the Circle Pattern Generator

Today I published a significant update to the circle pattern generator. Version 1.4.1 of the application is available for macOS and Windows for download. This new version adds various shapes, rotations, colours and a generator ...
Read More
Stronger 3D Printed Parts with Vertical Perimeter Linking

Stronger 3D Printed Parts with Vertical Perimeter Linking

One issue with fused filament fabrication is the weakness introduced into the parts at the layer boundaries. I had this simple idea of how especially straight sections of 3D prints could be improved on regular ...
Read More
Candlelight Emulation – Complexity with Layering

Candlelight Emulation – Complexity with Layering

In this blog post I explain the microcontroller firmware that emulates candlelight in more detail. You can apply the explained techniques in similar situations to get organic effects on CPU and RAM-limited platforms. I will ...
Read More
Rail Grid Alternatives and More Interesting Updates

Rail Grid Alternatives and More Interesting Updates

I published another large update to the storage boxes project in the last two weeks. All buyers who subscribed to update emails already got a summary of the changes. If you read the email, you ...
Read More
Extreme Integers – Doom from Below

Extreme Integers – Doom from Below

As a beginner or immediate C++ programmer, you heard never mixing unsigned and signed integer types or avoiding unsigned integers at all. There was also this talk about undefined behaviour. Yet, in embedded software development, ...
Read More

Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Stay Updated

Join me on Mastodon!

Top Posts & Pages

  • How and Why to use Namespaces
  • Storage Boxes System for 3D Print
  • Use Enum with More Class!
  • Circle Pattern Generator
  • Real Time Counter and Integer Overflow
  • Circle Pattern Generator
  • Logic Gates Puzzles
  • C++ Templates for Embedded Code
  • C++ Templates for Embedded Code (Part 2)
  • Logic Gates Puzzle 101

Latest Posts

  • The Importance of Wall Profiles in 3D Printing2023-02-12
  • The Hinges and its Secrets for Perfect PETG Print2023-02-07
  • Better Bridging with Slicer Guides2023-02-04
  • Stronger 3D Printed Parts with Vertical Perimeter Linking2023-02-02
  • Logic Gates Puzzle 1012023-02-02
  • Candlelight Emulation – Complexity with Layering2023-02-01
  • Three Ways to Integrate LED Light Into the Modular Lantern2023-01-29
  • The 3D Printed Modular Lantern2023-01-17

Categories

  • 3D Printing
  • Build
  • Common
  • Fail
  • Fun
  • Learn
  • Projects
  • Puzzle
  • Recommendations
  • Request for Comments
  • Review
  • Software
Copyright (c)2022 by Lucky Resistor. All rights reserved.