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 running on the Trinkey QT2040. On the host PC, Blinka 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:
To install the UF2 file:
- Put the Trinkey QT2040 in bootloader mode by holding the BOOT button while pressing the RST (reset) button.
- A folder named RPI-RP2 should appear.
- Drag the UF2 file to the RPI-RP2 folder.
- 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:
Make sure the post install checks pass before proceeding. Skip the check for the Pico, since were using a different board:
Install Libraries onto PC
Now we can install the specific CircuitPython libraries needed for talking to the sensors. For the SCD40, install this library:
For the BME280, install this library:
Here is a basic "hello world" example of simply reading and printing the sensor values in a loop.
# SPDX-FileCopyrightText: 2021 Carter Nelson for Adafruit Industries # # SPDX-License-Identifier: MIT import time import board import adafruit_scd4x from adafruit_bme280 import basic as adafruit_bme280 i2c = board.I2C() # uses board.SCL and board.SDA # i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller scd = adafruit_scd4x.SCD4X(i2c) scd.start_periodic_measurement() bme = adafruit_bme280.Adafruit_BME280_I2C(i2c) while True: time.sleep(5) print("CO2 =", scd.CO2) print("Pressure = {:.1f} hPa".format(bme.pressure)) print("Temperature = {:.1f} degC".format(bme.temperature)) print("Humidity = {:.1f}%".format(bme.humidity))
Running that code should produce output similar to this:
Text editor powered by tinymce.