A Raspberry Pi powered CO2 monitoring station using Python and Flask
If starting with blank micro SD card:
Connect your keyboard and mouse to the OTG port via a OTG (On-The-Go) USB hub with a micro USB plug. Connect the monitor to the mini-HDMI port and boot by plugging the power cable in.
On first start, setup the default user name "pi" and password "RaspberryPi"
Connect to WiFi
Enable Raspberry Pi Connect if you like.
"Skip" OS Update
Restart
If WiFi not yet connected: Connect to the WiFi using the icon at the top right of the screen.
Menu>Preferences>Praspberry Pi Configuration>Interface>SSH
Menu>Preferences>Praspberry Pi Configuration>Interface>I2C
Menu>Preferences>Praspberry Pi Configuration>Interface>VNC
Menu>Preferences>Raspberry Pi Configuration>Localisation>Locale Menu>Preferences>Raspberry Pi Configuration>Localisation>Timezone Menu>Preferences>Raspberry Pi Configuration>Localisation>Keyboard if necessary Menu>Preferences>Raspberry Pi Configuration>Localisation>WiFi Country
You'll need the IP address of your raspberry pi. Get it from
(venv) pi@raspberrypi:~ $ ifconfig | grep 192
inet 192.168.1.61 netmask 255.255.255.0 broadcast 192.168.1.255
And it's the address of the format 192.168, but not ending 255, so in this case its 192.168.1.61
The initial default, virtual memory allocation is very small. You need to expand it to allow many things, such as updating software.
Run swapon command
swapon
> NAME TYPE SIZE USED PRIO
> var/swap file 100M 100M -2
Swap Memory is 100 MB
sudo nano /etc/dphys-swapfile
Change swap size to 1024 MB
CONF_SWAPSIZE=1024
Use Control-s to save the changes and control-x to exit nano. Then reboot Moon Rabbit, to apply the changes.
sudo reboot
Check swapsize again
swapon
> NAME TYPE SIZE USED PRIO
> var/swap file 1024M 377.8M -2
Swap size has changed
Supervisord allows remore control of the software on the Raspberry Pi Zero 2 W from a browser on the same WiFi LAN.
Install Supervisord
# Update and upgrade the system packages
sudo apt-get update && sudo apt-get upgrade -y
# Install necessary packages
sudo apt-get install -y supervisor
sudo nano /etc/supervisor/supervisord.conf Add the following lines to enable the web interface
[inet_http_server]
port=*:9001
Use Control-s to save the changes and control-x to exit nano.
IIC or I2C (I-squared-C, or I-two-C), is the interface that links all the sensors to the Raspberry Pi Zero 2 W
sudo nano /boot/firmware/config.txt
# Uncomment or add these lines to enable the hardware interfaces
dtparam=i2c_arm=on
#dtparam=i2s=on
dtparam=spi=on
# Set I2C Clock Speed
dtparam=i2c_arm_baudrate=10000
Use Control-s to save the changes and control-x to exit nano.
# Clone the project repository
git clone https://github.com/SteveBz/MoonRabbit
cd MoonRabbit/
# Set up Python virtual environment and activate it
python3 -m venv venv
. venv/bin/activate
sh install.sh
Navigate to a browser, open two tabs and type in the following IP adresesses:
<your ip address>:5000
<your ip address>:9001
Eg, like this, substituting your address for the example.
192.168.1.61:5000
192.168.1.61:9001
Some of the SCD30s come nicely calibrated, some are well out. Of the two I just one was rught with about 6 ppm, and one was out by 150 ppm.
As we don't know which is which, we have to calibrate them all. This is a major cost item. A bottle of calibration gas and a valve just cost me £250 as of 2024. For this you can calibrate about 4 Moon Rabbits.
I bought a 2000 ppm cylinder of CO2 and air calibration gas.