Modzy Edge running on a RaspberryPi
Running AI and ML models on an 'Edge' device like a RaspberryPi is easy with Modzy! This repo contains everything necessary to set up an Air Quality Index sensor to detect current air quality and use that data to generate a next-hour prediction on a RaspberryPi.
See the full documentation here: https://docs.modzy.com/docs/raspberrypi
Hardware BOM
- RaspberryPi 3B+
- Adafruit PMSA003I Air Quality
- Adafruit SCD-40
- 2x Qwiic JST SH 4-pin Header Cable
- warning light
- jumper wires: M-F, M-M
- breadboard
- battery, if desired
Software dependencies
- Set up the Pi by following the RaspberryPi getting started guide.
- Update the Pi:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python3-pip
sudo pip3 install --upgrade setuptools
sudo apt-get install -y i2c-tools libgpiod-dev
- Install libraries:
- Docker, following these simple instructions: https://docs.docker.com/engine/install/debian/ and allow non-sudo users to use docker by running
sudo groupadd docker, sudo usermod -aG docker $USER
- CircuitPy and the libraries to interact with the AQI sensors:
pip3 install --upgrade adafruit-python-shell
wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/raspi-blinka.py
sudo python3 raspi-blinka.py
pip3 install adafruit-circuitpython-scd4x
pip3 install adafruit-circuitpython-pm25
- Finally, install the Python Modzy-SDK:
pip install modzy-sdk
or, if you have an unsupported processorpip install git+https://github.com/modzy/sdk-python.git
- Docker, following these simple instructions: https://docs.docker.com/engine/install/debian/ and allow non-sudo users to use docker by running
Run logger and predictor
- Verify the script from this repo executes successfully:
python logger.py
- Execute this script in the background on startup by creating
/etc/systemd/system/aqi_logger.service
and set it to autorun with these commands:sudo systemctl daemon-reload
sudo systemctl start aqi_logger.service
sudo systemctl enable aqi_logger.service
- Set up your Device and Device Group in Modzy
- Execute
python aq_predictor.py
from this repo. - That's it! You now have a device logging a variety of air quality indicators and running a model to predict what the air quality will be 1 hour in the future!
- Note this model requires at least 1 hour of data before it can begin to make accurate predictions.