The preceding pages cover versions of the project for the MAX44009, STCC4+SHT41, and GPS Featherwing. If you have a different light sensor, temperature/humidity sensor, or supported GPS receiver, the code can be easily adapted by changing the driver import and sensor initialization. Since all of the Adafruit libraries for the same type of sensors share common property names for their data readings, they are largely interchangeable in these projects. For different GPS breakouts, be sure to update the pins used for initialization according to the module you have.
For example, the following illustrates changing the lux version of the project to use the VCNL4030.
Existing code:
from adafruit_max44009 import MAX44009 # ... # ============================================================================= # SENSOR SETUP # ============================================================================= i2c = board.I2C() sensor = MAX44009(i2c)
from adafruit_vcnl4030 import VCNL4030 # ... # ============================================================================= # SENSOR SETUP # ============================================================================= i2c = board.I2C() sensor = VCNL4030(i2c)
Different Types of Sensors
If you want to venture outside the realm of GPS, lux, temperature, humidity, and CO2, the code can be adapted for other sensor types, but it requires a little more work.
The following sections illustrate changes needed to use a TMAG5273 magnetic sensor.
Change the import and initialization of the driver to use the one for the new sensor.
import adafruit_tmag5273 # ... sensor = adafruit_tmag5273.TMAG5273(i2c)
Add suitable entries to the READING_TYPES dictionary for the new sensor. The magnetic sensor has the property magnetic that returns x, y, and z values in a tuple. The attribute name entry in this dictionary is changed from string to tuple so that it can hold a name and a sub-index.
If your sensor has a basic property that returns a single value, then just use a string with the property name like the original project code does.
READING_TYPES = {
# type key : attr info , unit string
"magnetic_x": (("magnetic", 0), "uT"),
"magnetic_y": (("magnetic", 1), "uT"),
"magnetic_z": (("magnetic", 2), "uT"),
}
Update the code inside the get_range_string_from_sensor() function to handle the attribute name/sub-indexing scheme.
attr_info, _unit = READING_TYPES[_entry["reading"]] attr_name, subindex = attr_info reading = int(getattr(sensor, attr_name)[subindex])
Use one of the reading type key values magnetic_x, magnetic_y, or magnetic_z as the value for a custom reading type on the encryptor page.
Page last edited May 06, 2026
Text editor powered by tinymce.