TerrariumPI — Adding a Sensor

Stuart Brown
5 min readJan 12, 2019

--

OK, this is the part that I was dreading, the electronics! In my last post I went though how to set up your RaspberryPi and install TerrariumPI, in this post I’m going to go through adding a temperature and humidity sensor.

I’ve already mentioned that the electronics aspect of this project is where I have the steepest learning curve, partly this is because I have no knowledge and partly because the RPi/electronics newbie is confronted by so many acronyms! The first three that scared me where:

  1. GPIO
  2. I2C
  3. 1-Wire (OK this isn’t an acronym, but it is still shrouded in mystery!)

GPIO

Not so scary after all it seems — General Purpose Input Output. I found pinout to be a fantastic reference for figuring out which pins do what.

I2C

This seems to be a (now open) protocol for connecting devices (including sensors, other micro-controllers etc) to a primary micro-controller. Devices take power (3.3v, 5v, or both), a SCL (serial clock, I assume this is to regular the timings that measurements are taken but that’s a guess!) and SDA (serial data which presumably is responsible for controlling the flow of data between components).

It seems that you can set up multiple I2C components in parallel, connecting the SDA and SDC from one to that of another. I’m not entirely sure if you can do with the same with power or if you have to take a power feed from another RPi GPIO pin but I hope you can otherwise you will start to run out of GPIO pins pretty quickly.

I found this video quite helpful for a newbie introduction to I2C:

1-Wire

I still don’t really know what this is and haven’t had to red up on it yet. I’m assuming that it’s similar to I2C but requires 1 wire (presumably plus another for power?)!

Adding your first sensor, what not to do!

First up I decided to go with the super-cheap DH22 temperature and humidity sensor which turned out to be a mistake. It featured in a lot of RPi/temperature/humidity tutorials I read through but none of these were using TerrariumPI where there are a number of reported issues in the issue queue.

In terms of pure RPi compatibility it was fine. I was able to wire it up easily after a quick read of a rototron tutorial. I was also able to get a temperature and humidity reading when connected to the RPi via SSH but using the example scripts in the Adafruit library which comes bundled with TerrariumPi.

For example, once you have SSH’d into your RPi (open your terminal and type ssh pi@<RPILANIP>, and enter the password — raspberry by default if you haven’t changed it. Then type cd Adafruit_Python_DHT/examples and then sudo python test.py. This should print the temperature and humidity to your terminal. Unfortunately however these sensors were not recognised by TerrariumPI

Adding a sensor, take 2!

On the advice of the project maintainer I purchased:

  1. 1-Wire Humidity and Temperature sensor and
  2. 1-Wire Shield for WeMos D1

In both cases I purchased the most complete, works-out-of-the-box options I could!

I have to say that the customer support from Taaralabs was awesome and Mart put up with my newbie questions about what on earth I was supposed to do with the things I had bought. What I was really after, and what Mart provided, was a map of which GPIO pins mapped to which connections on the 1-Wire shield (as an aside I assume that ‘shield’ is just a generic term used to refer to the board onto which the electronic components are fixed, rather than a description of some ‘shielding’ functionality they perform. I may be wrong though).

The mapping of 1-Wire board to RPi GPIO is below

1-Wire board | Raspberry PI

GND | 9 (GND)
5V | 2 (5V)
3.3V | 1 (3.3V)
D1 | 5 (SLC)
D2 | 3 (SDA)

This was all very easy to connect. I wasn’t sure whether both 3.3v and 5v connections would need to be made but apparently they do. Quoting Mart

1-Wire network works at 5V signal levels but IO levels of modern microcontrollers, including Raspberry-PI’s is 3.3V. TaaraLabs.eu/ow1 board includes a level converter to fix that problem. Both sides (high and low) need to have a power source for it to work and this is why this board needs both 3.3V and 5V power input.

1 Wire humidity and temperature sensor connected to 1 wire shield (via RJ45) and wired to RPi

As a really pleasant surprise I found that when I went to the dashboard on my TerrariumPI I found that the sensor had been automatically recognised. I had thought I would have to find the address of the sensor and then add it manually, but no — all done for me :)

One small aspect of configuration that you will need to do is set the thresholds in the sensors > settings menu. This will remove the red ‘warning’ label above your sensor readings.

The settings I chose for the sensor

On the dashboard of your TerrariumPI you should now see something similar to this:

Woot! It works!

Next steps

So, all’s well that ends well! Now that I have a sensor added my next step will be to try and do something (e.g. turn a light on and off) based on the readings from that sensor. I have purchased https://www.modmypi.com/raspberry-pi/relays-and-home-automation-1032/relay-boards-1033/8-channel-12v-relay-module) which I hope will be able to do the job. However reading the TerrariumPI docs, it looks like I should have something like Universal AC MAINS Dimmer — MPDMv4.1 if I want to replicate a dimming thermostat as is preferable for my Deep Heat projectors etc.

Anyway, lots more reading to be done!

--

--