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

Logic Gates Puzzle 101

Logic Gates Puzzle 101

The message you got does not make any sense. Can you decypher it with the following logic puzzle? The circuit was not optimised for functionality but to create a challenging puzzle and gorgeous artwork. If ...
Read More
The Hinges and its Secrets for Perfect PETG Print

The Hinges and its Secrets for Perfect PETG Print

A while ago, I published the models for three different strengths of print-in-place hinges. If these are printed with PETG or ASA, they are incredibly strong and durable. This post explains why these objects print ...
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
New Version 2 of the Pattern Generator

New Version 2 of the Pattern Generator

The latest release of the Pattern Generator software, version 2.0.4, introduces a multitude of exciting improvements and enhancements. From a completely revamped backend to a range of additional features and optimizations, this update aims to ...
Read More
The 3D Printed Modular Lantern

The 3D Printed Modular Lantern

I designed a very modular 19th-century-style lantern. You can print it in its simplest form as a simple candlelight to put on a table or a shelf. By printing additional elements, you create a wonderful ...
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

Leave a ReplyCancel reply

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

Stay Updated / Donate

Join me on Mastodon!

☕️ Support my Work

Top Posts & Pages

  • Build a 3D Printer Enclosure
  • Welcome to My Shop
  • Simple Box with Lid for 3D-Print
  • Bit Manipulation using Templates
  • Accessing the SD Card (2)
  • Storage Boxes System for 3D Print
  • Projects
  • Real Time Counter and Integer Overflow
  • New Additions to the Storage Box System
  • Write Less Code using the "auto" Keyword

Latest Posts

  • New Additions to the Storage Box System2023-10-17
  • New Version 2 of the Pattern Generator2023-07-25
  • 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

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.