2.4 KiB
ENSAHT
What?
A firmware for the Raspberry Pi Pico W to grab data from a few environmental sensors and then log them to Adafruit IO (or the MQTT service of your choice).
Why?
I dunno, cause I wanted to play with these sensors and keep track of the air quality in my room. But eCO2 is pretty inaccurate, and I suspect I have a fake ENS sensor because the readings seem almost random.
Instructions
Prep
You need to have the pico-sdk installed. I have it installed in ~/workspace/rp2040/pico-sdk and this is currently hard-coded into CMakeFiles.txt. I'm not sure if exporting an environment variable overrides this by default, but you can always just edit it to point to wherever you have it installed.
You also must create a file in include/ called credentials.h in the following format:
#ifndef CREDENTIALS_H
#define CREDENTIALS_H
// Replace these placeholders with your actual credentials
#define ADAFRUIT_IO_USERNAME "your-username"
#define ADAFRUIT_IO_KEY "your-adafruit-io-key"
#define WIFI_SSID "wifi-ssid"
#define WIFI_PASSWORD "wifi-password"
#endif // CREDENTIALS_H
This keeps your credentials separate from the git history in case you want to make/submit changes. The build will fail if you don't create this file and define those four things.
You'll also need to edit src/main.c and change the MQTT topic names to whatever you are using.
Build
Create a new directory in the project called build. Move into that directory and run:
cmake ..
make
and if you have a picoprobe or RasPi debug probe installed (or other CMSIS-DAP compatible probe) you can then directly write to the Pico with
make flash
or, you can hold down the BOOT button on the Pico W while plugging it in. It will appear as a USB drive. Then copy the ensaht.uf2 file from the build/ directory to that USB drive. It'll take a second, then it'll disappear. You may need to manually reset the Pico (or unplug/replug it). Open a serial terminal (I used to recommend minicom until I found tio, which is much better), probably something like
tio /dev/ttyACM0
and it will print out sensor values. It will also log these to whatever MQTT server you have set up, assuming it was able to connect to Wi-Fi. And that's it!
License
Unlike most software I write, this is released under MIT instead of under MPL. So, follow the MIT license if you wanna reuse it!