This project demonstrates how to use the Omnimo nRF52840 with a SparkFun Qwiic OLED Display (SSD1306) and an AIR QUALITY 4 CLICK sensor to monitor indoor air quality. The system displays real-time eCO2 (equivalent CO2) and TVOC (Total Volatile Organic Compounds) levels on the OLED screen.
The project is designed for CircuitPython 8.1 and above, ensuring compatibility with both older and newer versions of CircuitPython. It's a great starting point for building advanced environmental monitoring systems or IoT projects.
By the end of this project, you will have:
- A working air quality monitoring system that measures eCO2 and TVOC levels.
- Real-time display of data on an SSD1306 OLED screen.
- Omnimo nRF52840
- SparkFun Qwiic OLED Display (0.91 in., 128x32 resolution)
- AIR QUALITY 4 CLICK Sensor (SGP30-based sensor)
- Jumper wires for connecting the components
- USB-C cable for programming the Omnimo nRF52840
- CircuitPython 8.1
Required libraries:
adafruit_sgp30
adafruit_displayio_ssd1306
displayio
(built-in)terminalio
(built-in)- Required libraries:
adafruit_sgp30
(built-in)
adafruit_displayio_ssd1306
displayioterminalio
(built-in)
You can install the required libraries by downloading the latest CircuitPython library bundle from Adafruit's GitHub repository.
Step-by-Step InstructionsStep 1: Set Up Your Development Environment- Install the latest version of CircuitPython on your Omnimo nRF52840.
Download the CircuitPython library bundle and extract the following libraries:
adafruit_sgp30.mpy
adafruit_displayio_ssd1306.mpy
- Download the CircuitPython library bundle and extract the following libraries:
adafruit_sgp30.mpy
adafruit_displayio_ssd1306.mpy - Copy these libraries into the
lib
folder on your Omnimo nRF52840.
Copy the provided code below into a file named code.py
and upload it to the root directory of your Omnimo nRF52840.
import time
import board
import displayio
from i2cdisplaybus import I2CDisplayBus
import busio
import terminalio
from adafruit_display_text import label
import adafruit_sgp30
import adafruit_displayio_ssd1306 as ssd1306
# Release any existing displays
displayio.release_displays()
# Initialize I2C buses
i2c0 = busio.I2C(board.QWIIC_SCL, board.QWIIC_SDA) # For SSD1306 display
i2c1 = board.I2C() # For AIR QUALITY 4 CLICK sensor
# Initialize SGP30 sensor
sgp30 = adafruit_sgp30.Adafruit_SGP30(i2c1)
print("SGP30 serial #", [hex(i) for i in sgp30.serial])
sgp30.set_iaq_baseline(0x8973, 0x8AAE)
sgp30.set_iaq_relative_humidity(celsius=22.1, relative_humidity=44)
# Configure SSD1306 display
ssd_width = 128
ssd_height = 32
ssd_bus = I2CDisplayBus(i2c0, device_address=0x3C)
display = ssd1306.SSD1306(ssd_bus, width=ssd_width, height=ssd_height)
# Define text colors
TEXT_WHITE = 0xFFFFFF
# Create text labels
hello_label = label.Label(terminalio.FONT, color=TEXT_WHITE)
hello_label.anchor_point = (0.0, 0.0)
hello_label.anchored_position = (0, 0)
hello_label.scale = 1
eCO2_label = label.Label(terminalio.FONT, color=TEXT_WHITE)
eCO2_label.anchor_point = (0.0, 0.0)
eCO2_label.anchored_position = (0, 10)
eCO2_label.scale = 2
TVOC_label = label.Label(terminalio.FONT, color=TEXT_WHITE)
TVOC_label.anchor_point = (0.0, 0.0)
TVOC_label.anchored_position = (60, 10)
TVOC_label.scale = 2
# Add labels to the display group
layer1 = displayio.Group()
layer1.append(hello_label)
layer1.append(eCO2_label)
layer1.append(TVOC_label)
display.root_group = layer1
# Main loop
elapsed_sec = 0
while True:
print("eCO2 = %d ppm \t TVOC = %d ppb" % (sgp30.eCO2, sgp30.TVOC))
hello_label.text = "eCO2 TVOC"
eCO2_label.text = f"{sgp30.eCO2:.0f}"
TVOC_label.text = f"{sgp30.TVOC:.0f}"
time.sleep(1)
elapsed_sec += 1
if elapsed_sec > 10:
elapsed_sec = 0
print(
"**** Baseline values: eCO2 = 0x%x, TVOC = 0x%x"
% (sgp30.baseline_eCO2, sgp30.baseline_TVOC)
)
Step 4: Test the System- Power on the Omnimo nRF52840.
- The OLED display will show real-time eCO2 and TVOC readings.
- AIR QUALITY 4 CLICK Sensor: Measures eCO2 and TVOC levels in the environment.
- SSD1306 OLED Display: Displays the measured eCO2 and TVOC values in real time.
- Baseline Calibration: The AIR QUALITY 4 CLICK sensor recalibrates itself every 10 seconds to ensure accurate readings.
This project demonstrates the power of the Omnimo nRF52840 in creating practical and useful IoT applications. By integrating the AIR QUALITY 4 CLICK sensor and SSD1306 OLED display, you can build a compact and efficient air quality monitoring system. Feel free to expand upon this foundation by adding additional sensors or integrating it into larger IoT ecosystems!
eAFAQ

Comments
Please log in or sign up to comment.