Raspberry Pi Vivarium monitoring / control project.
So I have now been looking for a Rasperry Pi Zero for well over 12 months, these things are as rare as unicorn farts in tornado. As such I have taken the decision to shelve Python monitoring Pythons (which is a shame as I loved the concept) and moved over to an ESP32 running C++
Please feel free to join me over on the following:
As a conclusion, I will probably pick this back up as a hobby using something other than a Pi Zero W - or I will conclude it once they become more freely available.
I have 3 (had 4 - 1 was a female and the others were starving themselves to try and get some, so she had to be rehomed) ball pythons and need to ensure the temperature and humidity are always at the right levels. So this project is starting life as a simple temperature/humidity sensor & recorder with web access, but over time could build up to include web-cams, temperature controller, over / under temperature alarms, door open sensors, you get the jist.
Pythons (Python Regius) are cold blooded reptiles originating from central Africa, which live in a vivarium (as it's normally too cold for in the UK) with a heater on one side (known as the warm side) and hides on both the warm and opposite side (the cool side). This warm / cold side provides a gradient temperature shift between so allowing the snake to move freely between in order to regulate it's own temperature - Sir David Attenborough would be proud!
Snakes don't have eyelid, so need moisture in the air to protect their eyes, and keep them hydrated, at around 50% - 60% moisture content.
They are covered in overlapping scales which need to be shed approximately every 4-6 weeks, known as ecdysis. End to end shedding cycles last about a week, and during this time it's best to have the moisture elevated (up to about 80% moisture), this aids in them shedding as the snake skin is moisturised. If the moisture is fine, the skin comes off in one. If the moisture is too low, the skin comes off in chunks in a "blow out". If the shed is a blow out, you may need to intervene in order to remove any old skin which remains after the shed has completed.
As We need to measure the humidity across the vivarium and the temperature at both ends, we will need 2 sensors per vivarium - so by my maths, that's 6 temperature sensors (+ spares to replace any faulty ones).
Wikipedia has some good stuff on Pythons, if you fancy a read
The following components, and a little skill will be required, please note I get most of my stuff from The Pi Hut but other parts are available from other stores (I have listed some of them in the Appendix):
- A Raspberry Pi
- DHT11 or DHT22 (or equivalent) temp/humidity probe
- Solderless Breadboard
- 10K resistors
- wire
- IDC plugs/Crimping tool
To make things more permanent:
- soldering iron
- heat shrink
Depending on how many vivarium's you want to monitor will denote the type of Raspberry Pi you'll need, I'm going for a Raspberry Pi 4, because I have a couple spare.
The DHT11 is a cheap sensor, but the DHT22 is more precise and will last longer, your call which one to opt for, there are others available and I found a quick comparison site on other alternatives (warning - this site contains electronic tech speak).
So after a rethink - I tried a Pi Pico, but this would need me to code the wi-fi. I then thought about an Pi Zero - but you cannot get hold of them for love nor money. Finally I thought about an ESP32 running MicroPython, this has built in wi-fi, but no real support for screen.
So back to the drawing board.
After various other projects (and a wait to see if I can get hold of a Pi Zero W/WH), I have picked this back up and decided to stick with an old Raspberry 3B+ which I had lying around - I will look to replace this with a more efficient Pi Zero W once they become available.
So the first delivery has arrived, and I'm quite impressed with the quality for the price.
So before we go and start hooking all of this together, let's just explore the temp sensor.
The first step will be to connect a basic DHT11/DHT22 (from here on in I will just call them DHTs) to the Pi.
Connecting the sensor to the Raspberry Pi is quite simple as follows:
- DHT pin 1 (left) > 3.3v (pin 1)
- Connect the 10K resistor across pins 1 and 2 on the DHT
- DHT pin 2 > GPIO Pin 7
- DHT pin 3 - Not connected
- DHT pin 4 (right) > ground (pin 6)
Download and install selected OS of choice - I downloaded Ubuntu Server.
Login using ubuntu / ubuntu and change the password.
By default ubuntu server is not connected to wi-fi, it should be using ethernet, but that's so old hat ;)
To find out the name of your wireless device, issue the command:
ls /sys/class/net
eth0 lo wlan0
sudo nano /etc/netplan/50-cloud-init.yaml
add the following to the end (ensure indents are followed)
wifis:
wlan0:
dhcp4: true
optional: true
access-points:
"[AccessPointSSID]":
password: "[AccessPointPassword]"
replacing [AccessPointSSID] and [AccessPointPassword] with the relevant details for your wifi
now issue the following commands
sudo netplan generate
sudo netplan apply
As always, you need to update and install Python (well, what other language would you use to monitor snakes?).
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential python-dev-is-python2 python3-pip git
In order to use the DHT we need to install some additional libraries
sudo pip3 install --upgrade Adafruit_DHT setuptools wheel
The source code for this is presently being developed - stay tuned.
Here are some stores to buy essentials from:
Probe sensor data comparison - note DHT22 is VERY similar to the AM2320, although the AM2320 is less accurate (2 - 3 deg C out and 5%-10% humidity out) - Also of interest is the fact that some of these devices can pull realtime data but their accuracy decreases over say 1s polling. For our requirements, 60s polling would be more than adequate, but if we perform 60 samples and then average it, this would be adequate as temp may drop if door is opened.
Install flask, flask_restful and json2html using
pip3 install flask pip3 install flask_restful pip3 install json2html pip3 install python-json-config
Swagger used with Swagger docs https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#operation-object
Swagger is set up to be visible on http://127.0.0.1:5002/api/v1/docs/ (port may be subject to change)