I have had my three beautiful pancake tortoises for a little over a week now, and their enclosure is monitored and controlled with a Raspberry Pi Zero and a Python program I wrote.
In this post I'm going to describe my setup, so maybe I can help others creating their own enclosure automation. Please note that this is not a ready made solution, you have to get your hands dirty, and get your soldering iron ready! The code is also not production ready yet, you need to know your way around the Pi.
My setup currently includes two temperature and humidity sensors (warm side, cool side) that are read every 5 minutes and measurements are stored in a PostgreSQL database. The UVB bulb and daylight LEDs are also controlled by the program. Basking light is currently manually controlled (I want a separate relay box for 220V AC), and - although configured - the thermostat is not used, because temperatures are high enough without a CHE this time of year.
These are the components I've used:
Currently I'm running Raspbian Lite, but any Raspberry compatible OS should suffice. The program I wrote is called TerraPi, and is open sourced under the MIT licence. I've almost named it TerraPin, but didn't want to make my pancakes jealous You can get the program from my GitHub page: https://github.com/sghctoma/terrapi. I will repeat here a warning from the README though:
Please note that this is by no means "production ready"! I am using it to control my enclosure, but it's still experimental. There is no proper error handling, no config validation, no installer, etc.
That said, it's been running for two weeks now without any problems. If you want something more thoroughly tested, and used for years though, you should give TerrariumPi a try! It also has much more functionality. This begs the question: why did I write my own? I wanted something simpler that I can easily maintain and extend, plus I could learn about interfacing the Pi with sensors, etc. this way.
The installation instructions are a bit vague, that is what I meant by writing "you need to know your way around the Pi" earlier. I am working on an installer, and a step-by-step guide, but it takes time. The README contains some useful information, and of course I am happy to answer any questions if you decide to give this a try.
ZooMed lamp modifications
I bought this specific lamp because it combines a T5 HO UVB bulb with some 6500K and red LEDs, and it seemed really easily serviceable from the user guide and videos I've seen. My plan was to de-solder the switches, and replace them with the relay board. As it turned out, I didn't even need to unsolder anything, since the switches use cable shoes, and the LED panels are connected with screw terminals.
The lamp has two two-way, and one three-way switches. One of the two-ways control the UVB bulb, and the other is for the blue LEDs. I don't want to use the latter, so did nothing with that switch. The three-way switch controls the 6500K and red LED: it's either off, 6500K only, or both red and 6500K. I had to make two decisions here:
These are the steps I had to take:
Please note that in this picture there is wiring for both the 6500K only, and the 6500K+red options. Since then I have removed the former, and there is only one red wire in the screw terminal (forgot to take a picture).
For the UVB light, I had to disconnect the cable shoes from the switch, and connect banana sockets to it. The picture was taken before applying heat shrink, so don't worry, I did not put those exposed wires back into the housing.
I ditched the UVB switch, and used the hole to make the banana plugs accessible.
That's it, the lamp is ready to be Pi-controlled. One side note though: I am planning to add support for the Energenie programmable power strips to TerraPi. Since the LED and UVB parts are on separate mains connectors, it will be possible to control the lights without these modifications. This is cheaper though.
The relay box
Not much to say here, I simply used some servo cables to connect the board to the Pi, and screwed the cables with the male banana plugs into the terminals. Than I drilled holes in the plastic box for the screws and cables, and put the whole thing together with nylon spacers and screws:
This is how it's connected to the Pi (GPIO pins 6, 13, 19 and 26 are used to control relay #1, #2, #3 and #4 respectively):
Sensors
Initially I tried to use the DHT22 sensor to measure temperature and humidity, bought two of them, put them on a breadboard, and started collecting data.
Temperature values were good, but humidity was way off: one of the sensors showed 17%, the other 27%, where the real value should have been around 50%. The salt-water calibration resulted in readings around 40% with the first sensor instead of the expected 75%. I have found out about the BME280 sensor after this disappointment, bought two of them too. Both showed 75% during calibration, so I started using them.
The chip is able to talk on two buses: SPI or I2C. The SPI port on the Raspberry is needed for an MCP3008 analog-digital converter, therefore I did not have to make a decision there I2C is a two-wire bus, which means 4 wires per chip (2 for I2C, plus Ground and 3.3V). I bought a couple of 2 meters long 4-pin 3.5 Jack male-female cables to use for this purpose. I snipped them near the female end, and first soldered the chip to the longer cable with the plug:
Than I soldered pin headers to the short cable with the socket. I2C devices need to be connected in parallel, if you want more of them on the same bus, so I have actually soldered two Jack sockets to the same pin headers. I have no picture of just this Y-cable, but you can see it in the first picture in this post.
I have not yet found a proper housing for these sensors, so right now they are attached to the side of the enclosure well out of tortoise reach. Of course this means that measured values are not the same as the ones the tortoises experience at ground level, but it is good enough for now. I'm planning to buy some plastic tubing, drill holes in it (so that humidity measurements can be accurate), and put the sensor inside.
Right now these are the only sensors I use, but I also have some UV sensors (GUVA-S12SD and ML8511) , and plan to get a weight sensor, so I don't have to write down every weight measurements. Not that it's too much work, I just like to build and try new stuff. I also have a camera under order for the Pi, so I can motion track my pancakes using OpenCV. (And have some other wild ideas, too. E.g. I have some stepper motors lying around here, so maybe there will be a Pi-controlled basking lamp height-adjustment someday. Which is totally unnecessary, but cool )
Putting it all together
After every component was ready, I just had to connect the relay board and the I2C Y-cable to the GPIO pins, connect the lamp's banana plugs to the sockets on the relay board, add power to the Pi via a USB cable, and start TerraPi.
The Pi is attached to the relay box, and the relay box to the ZooMed lamp with Velcro:
I also have a LAN cable connected, so that I can access the Pi via SSH, and use the dashboard.py script included with TerraPi that draws graphs from collected measurements:
I think that's all for now. This got rather lenghty, but I hope it was, or will someday be useful for somebody. Thanks for reading!
In this post I'm going to describe my setup, so maybe I can help others creating their own enclosure automation. Please note that this is not a ready made solution, you have to get your hands dirty, and get your soldering iron ready! The code is also not production ready yet, you need to know your way around the Pi.
My setup currently includes two temperature and humidity sensors (warm side, cool side) that are read every 5 minutes and measurements are stored in a PostgreSQL database. The UVB bulb and daylight LEDs are also controlled by the program. Basking light is currently manually controlled (I want a separate relay box for 220V AC), and - although configured - the thermostat is not used, because temperatures are high enough without a CHE this time of year.
These are the components I've used:
- Raspberry Pi Zero with the standard case
- 4 Channel Relay Module
- 2 x BME280 sensor modules
- 2 x 4 pin 3.5 Jack cable
- A small plastic box to house the relay. My DYS SE2205 quadcopter motors came in these little boxes that are the perfect size for the 4 channel relay module.
- T5 ReptiSun® LED UVB Terrarium Hood
- AWG 16 wires with banana plugs (salvaged from my quadcopter junkbox)
- Servo cables (also from the junkbox)
- Some male pin headers (can you guess where they came from? )
- Heat-shrink tubing (junkbox...)
- M3 nylon spacers, screws and nuts (these too..)
- Some extra strong Velcro
- Soldering iron
- Multimeter
- Heat gun (or a lighter, but I didn't say that! ) to shrink the tubes
- Wire cutter
- Phillips-head screwdriver
- Electric drill
Currently I'm running Raspbian Lite, but any Raspberry compatible OS should suffice. The program I wrote is called TerraPi, and is open sourced under the MIT licence. I've almost named it TerraPin, but didn't want to make my pancakes jealous You can get the program from my GitHub page: https://github.com/sghctoma/terrapi. I will repeat here a warning from the README though:
Please note that this is by no means "production ready"! I am using it to control my enclosure, but it's still experimental. There is no proper error handling, no config validation, no installer, etc.
That said, it's been running for two weeks now without any problems. If you want something more thoroughly tested, and used for years though, you should give TerrariumPi a try! It also has much more functionality. This begs the question: why did I write my own? I wanted something simpler that I can easily maintain and extend, plus I could learn about interfacing the Pi with sensors, etc. this way.
The installation instructions are a bit vague, that is what I meant by writing "you need to know your way around the Pi" earlier. I am working on an installer, and a step-by-step guide, but it takes time. The README contains some useful information, and of course I am happy to answer any questions if you decide to give this a try.
ZooMed lamp modifications
I bought this specific lamp because it combines a T5 HO UVB bulb with some 6500K and red LEDs, and it seemed really easily serviceable from the user guide and videos I've seen. My plan was to de-solder the switches, and replace them with the relay board. As it turned out, I didn't even need to unsolder anything, since the switches use cable shoes, and the LED panels are connected with screw terminals.
The lamp has two two-way, and one three-way switches. One of the two-ways control the UVB bulb, and the other is for the blue LEDs. I don't want to use the latter, so did nothing with that switch. The three-way switch controls the 6500K and red LED: it's either off, 6500K only, or both red and 6500K. I had to make two decisions here:
- Do I want to use the red and white LEDs separately?
- Do I want to be able to use the physical switches to turn on the light independently from the Pi?
These are the steps I had to take:
- unscrew the cable going from the switch to the terminal,
- solder a banana socket on the unscrewed cable,
- screw a cable with a banana socket into the terminal.
Please note that in this picture there is wiring for both the 6500K only, and the 6500K+red options. Since then I have removed the former, and there is only one red wire in the screw terminal (forgot to take a picture).
For the UVB light, I had to disconnect the cable shoes from the switch, and connect banana sockets to it. The picture was taken before applying heat shrink, so don't worry, I did not put those exposed wires back into the housing.
I ditched the UVB switch, and used the hole to make the banana plugs accessible.
That's it, the lamp is ready to be Pi-controlled. One side note though: I am planning to add support for the Energenie programmable power strips to TerraPi. Since the LED and UVB parts are on separate mains connectors, it will be possible to control the lights without these modifications. This is cheaper though.
The relay box
Not much to say here, I simply used some servo cables to connect the board to the Pi, and screwed the cables with the male banana plugs into the terminals. Than I drilled holes in the plastic box for the screws and cables, and put the whole thing together with nylon spacers and screws:
This is how it's connected to the Pi (GPIO pins 6, 13, 19 and 26 are used to control relay #1, #2, #3 and #4 respectively):
Sensors
Initially I tried to use the DHT22 sensor to measure temperature and humidity, bought two of them, put them on a breadboard, and started collecting data.
Temperature values were good, but humidity was way off: one of the sensors showed 17%, the other 27%, where the real value should have been around 50%. The salt-water calibration resulted in readings around 40% with the first sensor instead of the expected 75%. I have found out about the BME280 sensor after this disappointment, bought two of them too. Both showed 75% during calibration, so I started using them.
The chip is able to talk on two buses: SPI or I2C. The SPI port on the Raspberry is needed for an MCP3008 analog-digital converter, therefore I did not have to make a decision there I2C is a two-wire bus, which means 4 wires per chip (2 for I2C, plus Ground and 3.3V). I bought a couple of 2 meters long 4-pin 3.5 Jack male-female cables to use for this purpose. I snipped them near the female end, and first soldered the chip to the longer cable with the plug:
Than I soldered pin headers to the short cable with the socket. I2C devices need to be connected in parallel, if you want more of them on the same bus, so I have actually soldered two Jack sockets to the same pin headers. I have no picture of just this Y-cable, but you can see it in the first picture in this post.
I have not yet found a proper housing for these sensors, so right now they are attached to the side of the enclosure well out of tortoise reach. Of course this means that measured values are not the same as the ones the tortoises experience at ground level, but it is good enough for now. I'm planning to buy some plastic tubing, drill holes in it (so that humidity measurements can be accurate), and put the sensor inside.
Right now these are the only sensors I use, but I also have some UV sensors (GUVA-S12SD and ML8511) , and plan to get a weight sensor, so I don't have to write down every weight measurements. Not that it's too much work, I just like to build and try new stuff. I also have a camera under order for the Pi, so I can motion track my pancakes using OpenCV. (And have some other wild ideas, too. E.g. I have some stepper motors lying around here, so maybe there will be a Pi-controlled basking lamp height-adjustment someday. Which is totally unnecessary, but cool )
Putting it all together
After every component was ready, I just had to connect the relay board and the I2C Y-cable to the GPIO pins, connect the lamp's banana plugs to the sockets on the relay board, add power to the Pi via a USB cable, and start TerraPi.
The Pi is attached to the relay box, and the relay box to the ZooMed lamp with Velcro:
I also have a LAN cable connected, so that I can access the Pi via SSH, and use the dashboard.py script included with TerraPi that draws graphs from collected measurements:
I think that's all for now. This got rather lenghty, but I hope it was, or will someday be useful for somebody. Thanks for reading!