# DIY Trinkey No-Soldering USB Air Quality Monitor

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/107/495/medium800/temperature___humidity_banner.jpg?1640206186)

Want to measure various air quality parameters, like humidity, temperature, CO2, etc.? Want to measure these directly into your computer? Want to do all this without soldering? No problem. In this guide we'll show how this can done using the [Adafruit Trinkey QT2040](https://www.adafruit.com/product/5056).

We'll use a [Sensirion SCD40](https://www.adafruit.com/product/5187) for CO2 measurement. For temperature, pressure, and humidity, we'll use a [Bosch BME280](https://www.adafruit.com/product/2652). By connecting everything together using [STEMMA QT cables](https://www.adafruit.com/product/4399) - **no soldering is required**.

## Choose Your Own Adventure

This guide shows several different ways of coding up the Trinkey Enviro Sensor Gadget. Pick which ever adventure seems the most exciting! Or works best for your use case. Or try them all out!

Here is a summary:

- **Arduino** - Read via USB CDC serial. Precompiled UF2's are provided. Code changes require recompiling provided source with Arduino IDE.
- **CircuitPython** - Read via USB CDC serial. Code changes can be done directly to source without recompiling.
- **U2IF** - Read directly into PC using Python with Blinka. Code changes are done on the host PC.

## Parts

Here is a list of the hardware items used in this project:

### Adafruit Trinkey QT2040 - RP2040 USB Key with Stemma QT

[Adafruit Trinkey QT2040 - RP2040 USB Key with Stemma QT](https://www.adafruit.com/product/5056)
It's half USB Key, half Adafruit QT Py, and a lotta&nbsp;RP2040_..._it's&nbsp; **Trinkey QT2040** , the circuit board with an RP2040 heart and Stemma QT legs. Folks are loving the [QT Py 2040](https://www.adafruit.com/product/4900) we made, but maybe you...

In Stock
[Buy Now](https://www.adafruit.com/product/5056)
[Related Guides to the Product](https://learn.adafruit.com/products/5056/guides)
![Video of Trinkey RP2040 plugged into a laptop. An OLED display is connected and shows a graphic keyboard cat animation.](https://cdn-shop.adafruit.com/product-videos/640x480/5056-04.jpg)

### Adafruit SCD-40 - True CO2, Temperature and Humidity Sensor

[Adafruit SCD-40 - True CO2, Temperature and Humidity Sensor](https://www.adafruit.com/product/5187)
Take a deep breath in...now slowly breathe out. Mmm isn't it wonderful? All that air around us, which we bring into our lungs, extracts oxygen from and then breathes out carbon dioxide. CO2 is essential for life on this planet we call Earth - we and plants&nbsp;take turns using and...

In Stock
[Buy Now](https://www.adafruit.com/product/5187)
[Related Guides to the Product](https://learn.adafruit.com/products/5187/guides)
![Angled shot of Adafruit SCD-40 - NDIR CO2 Temperature and Humidity Sensor.](https://cdn-shop.adafruit.com/640x480/5187-08.jpg)

### Adafruit BME280 I2C or SPI Temperature Humidity Pressure Sensor

[Adafruit BME280 I2C or SPI Temperature Humidity Pressure Sensor](https://www.adafruit.com/product/2652)
Bosch has stepped up their game with their new BME280 sensor, an environmental sensor with temperature, barometric pressure&nbsp;and&nbsp;humidity! This sensor is great for all sorts of indoor environmental sensing and can even be used in both I2C and SPI!

This precision sensor from...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2652)
[Related Guides to the Product](https://learn.adafruit.com/products/2652/guides)
![small, rectangle-shaped, BME280 temperature humidity pressure sensor breakout board.](https://cdn-shop.adafruit.com/640x480/2652-04.jpg)

### Stacking M2.5 Hardware Kit for STEMMA QT and RP2040 Trinkey

[Stacking M2.5 Hardware Kit for STEMMA QT and RP2040 Trinkey](https://www.adafruit.com/product/5248)
&nbsp;

Here is the perfect hardware kit to make a [RP2040 QT Trinkey](https://www.adafruit.com/product/5056) into any kind of USB-connected smart sensor with a QT-sensor-sandwich!&nbsp;You can assemble it with just a plain Phillips screwdriver. Takes less than a minute to bolt...

In Stock
[Buy Now](https://www.adafruit.com/product/5248)
[Related Guides to the Product](https://learn.adafruit.com/products/5248/guides)
![Angled shot of a USB key-shaped PCB with a sensor board stacked on top via black nylon screws.](https://cdn-shop.adafruit.com/640x480/5248-00.jpg)

### STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long

[STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long](https://www.adafruit.com/product/4399)
This 4-wire cable is&nbsp;50mm / 1.9" long and fitted with JST SH female 4-pin connectors on both ends. Compared with the chunkier JST PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and remove.

<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/4399)
[Related Guides to the Product](https://learn.adafruit.com/products/4399/guides)
![Angled of of JST SH 4-Pin Cable.](https://cdn-shop.adafruit.com/640x480/4399-00.jpg)

# DIY Trinkey No-Soldering USB Air Quality Monitor

## Assembly

Using [STEMMA QT cables](https://www.adafruit.com/product/4399), plugging everything together is easy. And with the available [bolt kit](https://www.adafruit.com/product/5248), there are various ways in which the boards can be fastened together, or not, depending on how you want to arrange things.

## Basic Wiring

Using [STEMMA QT cables](https://www.adafruit.com/product/4399), the basic wiring is very simple - just plug everything together. There are several different STEMMA QT cable lengths to choose from. Also, the ordering of the sensors should not matter.

![](https://cdn-learn.adafruit.com/assets/assets/000/107/487/medium800/temperature___humidity_Trinkey2040_BME280_SCD40_bb.png?1640114728)

## Using Bolt Kit

If you want to stack things together, the [M2.5 hardware kit](https://www.adafruit.com/product/5248) can be used. In order to stack more than two things together, you'll need more than one bolt kit. The SCD40 should end up on top to give it enough clearance.

Using **two bolt kits** , it's possible to stack all the boards together. However, this may be too chonky. The STEMMA QT cable may also interfere with plugging into USB port as well.

![temperature___humidity_all_stack.jpg](https://cdn-learn.adafruit.com/assets/assets/000/107/488/medium640/temperature___humidity_all_stack.jpg?1640115217)

Using **one bolt kit** , just the BME280 and SCD40 can be stacked together. This allows the sensor package to be tethered separately from the Trinkey QT2040.

![temperature___humidity_two_stack.jpg](https://cdn-learn.adafruit.com/assets/assets/000/107/489/medium640/temperature___humidity_two_stack.jpg?1640115350)

It is also OK to use **no bolt kit** at all and just connect the sensors in a free form chain.

![temperature___humidity_no_stack.jpg](https://cdn-learn.adafruit.com/assets/assets/000/107/490/medium640/temperature___humidity_no_stack.jpg?1640115435)

# DIY Trinkey No-Soldering USB Air Quality Monitor

## Arduino Sender

The idea for the sending code is pretty simple - we just read the values in a loop and send them out over the serial port.

The complete Arduino sketch code is provided later to allow customizing. However, we provide some pre-compiled examples in UF2 format. With these UF2 files, you can just drag-and-drop to the Trinkey QT2040 RPI-RP2 bootloader folder. The Arduino IDE does not even need to be installed.

## Installing UF2 Examples

To install the UF2 files:

1. Put the Trinkey QT2040 in bootloader mode by holding the **BOOT** button while pressing the **RST** (reset) button.
2. A folder named **RPI-RP2** should appear.
3. Drag the **UF2** file to the **RPI-RP2** folder.
4. Once copied, board should reset and code is now running.

## Send CSV Formatted Text

This example provides comma separated (CSV) formatted text. Here's the UF2:

[ENVIRO_CSV.uf2](https://cdn-learn.adafruit.com/assets/assets/000/107/459/original/ENVIRO_CSV.uf2?1640027449)
With that running on the Trinkey QT2040, the serial output will look like this:

![](https://cdn-learn.adafruit.com/assets/assets/000/107/462/medium800/temperature___humidity_Screenshot_from_2021-12-20_11-17-27.png?1640027859)

## Send JSON Formatted Text

This example provides JavaScript Object Notation (JSON) formatted text. Here's the UF2:

[ENVIRO_JSON.uf2](https://cdn-learn.adafruit.com/assets/assets/000/107/460/original/ENVIRO_JSON.uf2?1640027460)
With that running on the Trinkey QT2040, the serial output will look like this:

![](https://cdn-learn.adafruit.com/assets/assets/000/107/461/medium800/temperature___humidity_Screenshot_from_2021-12-20_11-16-24.png?1640027836)

## Customizing

You can customize the Arduino sketch sending behavior by modifying these lines found at the top of the sketch:

```cpp
//--| User Config |-----------------------------------------------
#define DATA_FORMAT   0         // 0=CSV, 1=JSON
#define DATA_RATE     5000      // generate new number ever X ms
#define BEAT_COLOR    0xADAF00  // neopixel heart beat color
#define BEAT_RATE     1000      // neopixel heart beat rate in ms, 0=none
//----------------------------------------------------------------
```

The ready to go UF2 examples provided above are just precompiled sketches with these already set for specific use cases, i.e. CSV and JSON output.

## Sensirion SCD4x Arduino Library

To recompile the Arduino sketch, you'll need the Sensirion Arduino library for the SCD40:

[Sensirion SCD4x Arduino Library](https://github.com/Sensirion/arduino-i2c-scd4x)
It can be installed via the Arduino IDE Library Manager. Just search for "Sensirion I2C SCD4x":

![](https://cdn-learn.adafruit.com/assets/assets/000/107/470/medium800/temperature___humidity_libman.jpg?1640036744)

## Arduino Code

Here is the complete code listing for the Arduino sketch.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Trinkey_QT2040_Enviro_Gadget/arduino/trinkey_qt2040_enviro/trinkey_qt2040_enviro.ino

# DIY Trinkey No-Soldering USB Air Quality Monitor

## CircuitPython Sender

This is basically the same idea as the Arduino sketch - just read the values and send over serial in a loop. There are [CircuitPython libraries](https://circuitpython.org/libraries) for the [SCD40](https://github.com/adafruit/Adafruit_CircuitPython_SCD4X) and [BME280](https://github.com/adafruit/Adafruit_CircuitPython_BME280), which makes this easy to implement.

## Install CircuitPython

This is covered in the Trinkey QT2040 main guide:

[CircuitPython Quickstart](https://learn.adafruit.com/adafruit-trinkey-qt2040/circuitpython)
The required libraries will be included with the project bundle download along with project code below.

## Enable USB CDC Data

We could probably just send the data using the typical serial ouput via the typical `print()` command. However, here we show how to enable and use the secondary USB CDC serial port available in CircuitPython:

[USB Serial: Console (REPL) and Data](https://learn.adafruit.com/customizing-usb-devices-in-circuitpython/circuitpy-midi-serial#usb-serial-console-repl-and-data-3096590-12)
As mentioned in that guide, this requires a special **boot.py** file to be located in the **CIRCUITPY** folder. Well, not too special, it's just a few lines of code:

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Trinkey_QT2040_Enviro_Gadget/circuitpython/boot.py

Copy that code and save it to **CIRCUITPY/boot.py**.

## CircuitPython Code

Here is the project code. To get code and necessary libraries, click on the&nbsp; **Download Project Bundle** &nbsp;link below, and uncompress the .zip file. Once the sensors are connected and the modified boot.py has been put in place, simply save the project code as **CIRCUITPY/code.py** :

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Trinkey_QT2040_Enviro_Gadget/circuitpython/enviromon.py

# DIY Trinkey No-Soldering USB Air Quality Monitor

## Receiving Data

With either the Arduino or the CircuitPython code running on the Trinkey QT2040, the data is being sent out via a USB CDC serial port. This data can be received by anything that can open and talk to the serial port. Here we provide an example using **Python** and **pySerial**.

## Install pySerial

The pySerial module is used to open and read from the serial port in Python. If this module is not already installed on your setup, go here:

[pySerial](https://pypi.org/project/pyserial/)
## Which Serial Port?

The **Arduino** example sends out data using the typical `Serial.print()` command. This serial port should show up in the place you'd look for the Arduino Serial Monitor.

The **CircuitPython** example uses a secondary serial port and data is sent using `usb_cdc.data.write()`. This is different than the serial port where `print()` output shows up. There should be two serial ports that show up when running the CircuitPython example. The data is most likely on the second one.

Info: 

Info: 

## Read CSV String

Here is an example of how to open the serial port and read the incoming CSV data:

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Trinkey_QT2040_Enviro_Gadget/python/read_csv.py

## Read JSON String

Here is an example of how to open the serial port and read the incoming JSON data:

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Trinkey_QT2040_Enviro_Gadget/python/read_json.py

# DIY Trinkey No-Soldering USB Air Quality Monitor

## Direct Reading with U2IF

This approach allows for direct reading of the sensors. Instead of reading and parsing from a serial stream, the sensor libraries are used directly in Python running on the host PC. This is done by having [specialized firmware called U2IF](https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-raspberry-pi-pico) running on the Trinkey QT2040. On the host PC, [Blinka](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux/overview) is installed to provide access to the Trinkey running U2IF and allow use of CircuitPython libraries.

**This approach has a lot of setup**. However, if your goal is to get sensor values into a Python application running on the host PC, this approach offers the most direct route.

## Install U2IF Firmware onto Trinkey

This step is pretty easy. Just download the firmware file and copy to Trinkey. To download a copy of the U2IF firmware for the Trinkey QT2040, go here:

[U2IF Firmware for Trinkey QT2040](https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-raspberry-pi-pico/other-rp2040-boards#trinkey-qt2040-3098088-29)
To install the UF2 file:

1. Put the Trinkey QT2040 in bootloader mode by holding the **BOOT** button while pressing the **RST** (reset) button.
2. A folder named **RPI-RP2** should appear.
3. Drag the **UF2** file to the **RPI-RP2** folder.
4. Once copied, board should reset and code is now running.

## Install Blinka onto PC

This step has more to it. The installation process is different for each operating system. Use this guide to install Blinka and the associated supporting software on to your PC:

[Setup on PC](https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-raspberry-pi-pico/setup)
Make sure the post install checks pass before proceeding. **Skip the check for the Pico** , since were using a different board:

[Post Install Checks](https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-raspberry-pi-pico/post-install-checks)
## Install Libraries onto PC

Now we can install the specific CircuitPython libraries needed for talking to the sensors. For the SCD40, install this library:

[SCD4x Library Install](https://learn.adafruit.com/adafruit-scd-40-and-scd-41/python-circuitpython#python-installation-of-scd4x-library-3101356-10)
For the BME280, install this library:

[BME280 Library Install](https://learn.adafruit.com/adafruit-bme280-humidity-barometric-pressure-temperature-sensor-breakout/python-circuitpython-test#python-installation-of-bme280-library-2995297-10)
## Read Sensors via Python

Once all the setup is done, actually reading the sensors is easy.

Danger: 

Here is a basic "hello world" example of simply reading and printing the sensor values in a loop.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Trinkey_QT2040_Enviro_Gadget/u2if/enviro_u2if.py

Danger: 

Running that code should produce output similar to this:

![](https://cdn-learn.adafruit.com/assets/assets/000/107/463/medium800/temperature___humidity_Screenshot_from_2021-12-20_11-34-36.png?1640028905)


## Featured Products

### Adafruit Trinkey QT2040 - RP2040 USB Key with Stemma QT

[Adafruit Trinkey QT2040 - RP2040 USB Key with Stemma QT](https://www.adafruit.com/product/5056)
It's half USB Key, half Adafruit QT Py, and a lotta&nbsp;RP2040_..._it's&nbsp; **Trinkey QT2040** , the circuit board with an RP2040 heart and Stemma QT legs. Folks are loving the [QT Py 2040](https://www.adafruit.com/product/4900) we made, but maybe you...

In Stock
[Buy Now](https://www.adafruit.com/product/5056)
[Related Guides to the Product](https://learn.adafruit.com/products/5056/guides)
### Adafruit SCD-40 - True CO2, Temperature and Humidity Sensor

[Adafruit SCD-40 - True CO2, Temperature and Humidity Sensor](https://www.adafruit.com/product/5187)
Take a deep breath in...now slowly breathe out. Mmm isn't it wonderful? All that air around us, which we bring into our lungs, extracts oxygen from and then breathes out carbon dioxide. CO2 is essential for life on this planet we call Earth - we and plants&nbsp;take turns using and...

In Stock
[Buy Now](https://www.adafruit.com/product/5187)
[Related Guides to the Product](https://learn.adafruit.com/products/5187/guides)
### Adafruit BME280 I2C or SPI Temperature Humidity Pressure Sensor

[Adafruit BME280 I2C or SPI Temperature Humidity Pressure Sensor](https://www.adafruit.com/product/2652)
Bosch has stepped up their game with their new BME280 sensor, an environmental sensor with temperature, barometric pressure&nbsp;and&nbsp;humidity! This sensor is great for all sorts of indoor environmental sensing and can even be used in both I2C and SPI!

This precision sensor from...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2652)
[Related Guides to the Product](https://learn.adafruit.com/products/2652/guides)
### Stacking M2.5 Hardware Kit for STEMMA QT and RP2040 Trinkey

[Stacking M2.5 Hardware Kit for STEMMA QT and RP2040 Trinkey](https://www.adafruit.com/product/5248)
&nbsp;

Here is the perfect hardware kit to make a [RP2040 QT Trinkey](https://www.adafruit.com/product/5056) into any kind of USB-connected smart sensor with a QT-sensor-sandwich!&nbsp;You can assemble it with just a plain Phillips screwdriver. Takes less than a minute to bolt...

In Stock
[Buy Now](https://www.adafruit.com/product/5248)
[Related Guides to the Product](https://learn.adafruit.com/products/5248/guides)
### STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long

[STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long](https://www.adafruit.com/product/4399)
This 4-wire cable is&nbsp;50mm / 1.9" long and fitted with JST SH female 4-pin connectors on both ends. Compared with the chunkier JST PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and remove.

<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/4399)
[Related Guides to the Product](https://learn.adafruit.com/products/4399/guides)
### STEMMA QT / Qwiic JST SH 4-pin Cable - 100mm Long

[STEMMA QT / Qwiic JST SH 4-pin Cable - 100mm Long](https://www.adafruit.com/product/4210)
This 4-wire cable is a little over 100mm / 4" long and fitted with JST-SH female 4-pin connectors on both ends. Compared with the chunkier JST-PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and remove.

<a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/4210)
[Related Guides to the Product](https://learn.adafruit.com/products/4210/guides)
### STEMMA QT / Qwiic JST SH 4-Pin Cable - 200mm Long

[STEMMA QT / Qwiic JST SH 4-Pin Cable - 200mm Long](https://www.adafruit.com/product/4401)
This 4-wire cable is a little over 200mm / 7.8" long and fitted with JST-SH female 4-pin connectors on both ends. Compared with the chunkier JST-PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and remove.

<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/4401)
[Related Guides to the Product](https://learn.adafruit.com/products/4401/guides)

## Related Guides

- [Adafruit Trinkey QT2040](https://learn.adafruit.com/adafruit-trinkey-qt2040.md)
- [Adafruit SCD-40 and SCD-41](https://learn.adafruit.com/adafruit-scd-40-and-scd-41.md)
- [Feather + Raspberry Pi Weather Monitoring Network with LoRa or LoRaWAN](https://learn.adafruit.com/multi-device-lora-temperature-network.md)
- [PyPortal IoT Weather Station](https://learn.adafruit.com/pyportal-iot-weather-station.md)
- [Working with Multiple Same Address I2C Devices](https://learn.adafruit.com/working-with-multiple-i2c-devices.md)
- [Adafruit BME280 Humidity + Barometric Pressure + Temperature Sensor Breakout](https://learn.adafruit.com/adafruit-bme280-humidity-barometric-pressure-temperature-sensor-breakout.md)
- [CircuitPython Libraries on MicroPython using the Raspberry Pi Pico](https://learn.adafruit.com/circuitpython-libraries-on-micropython-using-the-raspberry-pi-pico.md)
- [Using Piezo Buzzers with WipperSnapper](https://learn.adafruit.com/using-piezo-buzzers-with-wippersnapper.md)
- [Multi-Sensor IoT Environmental Sensor Box With CircuitPython](https://learn.adafruit.com/remote-iot-environmental-sensor.md)
- [CircuitPython Libraries on Linux and the NVIDIA Jetson Nano](https://learn.adafruit.com/circuitpython-libraries-on-linux-and-the-nvidia-jetson-nano.md)
- [No-Code Indoor Grow Monitor with PPFD and VPD Measurements](https://learn.adafruit.com/no-code-indoor-grow-monitor.md)
- [Google Docs Sensor Logging From Your PC](https://learn.adafruit.com/gdocs-sensor-logging-from-your-pc.md)
- [I2C Addresses and Troublesome Chips](https://learn.adafruit.com/i2c-addresses.md)
- [Adding a Single Board Computer to Blinka](https://learn.adafruit.com/adding-a-single-board-computer-to-blinka.md)
- [Reading QR Codes with the Tiny Code Reader](https://learn.adafruit.com/reading-qr-codes-with-the-tiny-code-reader.md)
- [Integrating Home Assistant with Adafruit IO](https://learn.adafruit.com/integrating-adafruit-io-with-home-assistant.md)
