This project aims to build a weather station running on a Pi Pico W. The sensors are all I2C devices from Adafruit. A RESTful API runs in the background to facilitate writing to a database.
- Raspberry Pico Pi W
- I2C SCD-30 (addr:
0x61
) - CO2 - I2C DS3231 (addr:
0x68
) - Real time clock - I2C BME280 (addr:
0x77
) - Temp / Humidity / Pressure - I2C PMSA003I (addr:
0x12
) - PM2.5
This project is split into two areas of focus:
- Scripts for the Pi Pico W
- FastAPI server for connecting to a database (postgres in my case)
The Pi Pico code is designed to collect measurements on 15 minute intervals. Once a measurement is taken, an attempt is made to post the current buffer of measurements to the API. If the attempt fails, the buffer is maintained and appended to with the next measurment for the next attempt.
The API backend is just an endpoint which is set up to allow the Pi Pico to
save its measurements to a database. The API endpoint allows the Pico to
POST
a list of several records rather than only a single record in order to
be more fault tolerant.
- Install the following packages on your Pi Pico W (outlined in hw section)
micropython_bme280
micropython_scd30
urtc
- Copy
config.py.template
and rename the copy toconfig.py
. Fill out the values to match your situationLOCATION
- Your logging location (eg 'Bedroom
','Crawl Space'
, etc)SSID
- Your wifi network nameWIFIP
- Your wifi network's passphraseAPI_BASE_URL
- The base url where you're running the API server (eg'http://192.168.1.100'
)
- Copy the Pico scripts to your Pico
- main.py
- config.py
- Connect an I2C sensor device to the GPIO pins:
- SDA -> GP0
- SLC -> GP1
- GND -> GND
- V -> 3.3v
- Use additional STEMMA QT plugs to daisy-chain the rest of the I2C sensors
- Install the API server requirements with
pip install -r server_requirements.txt
- Run the API server with the command
uvicorn postgres_api:api --host 0.0.0.0
Create the tables and function as described in create.sql.
env_log
- Stores measurement recordsaqi_categories
- Lookup table for descriptions and colors of AQI rangesaqi_breakpoints
- Lookup table for AQI range breakpointscalcualte_aqi
- Function to calcualte AQI from concentration measurement and reference values