The Raspberry Pi takes over a greenhouse

First Test

The first test of the trial construction used a current version of Raspbian plus I2C drivers and I2C tools on the Raspberry Pi. The driver comes from the WiringPi library. (See the box titled "Installing WiringPi." You should get the I2C tools from the usual package sources for the system by entering:

sudo apt-get install i2c-tools

Installing WiringPi

The WiringPi Project [9] offers a library to access the Rasp Pi GPIO. The individual pins of the interface can be read and written using simple commands and a C API. Additionally, WiringPi has a driver for the I2C bus used in this project. However, this nifty library is not yet found in the package sources for Raspbian. It is a good idea when starting the project to download and compile the software sources from GitHub as set forth in Listing 1. Afterward, you can read all of the ports using a command such as gpio readall (Listing 2).

Listing 1

Installing WiringPi

$ sudo apt-get update
$ sudo apt-get upgrade
$ git clone git://git.drogon.net/wiringPi
$ cd wiringPi
$ ./build

Listing 2

Reading All Ports

$ gpio readall
 +-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 |   IN | 1 |  3 || 4  |   |      | 5V      |     |     |
 |   3 |   9 |   SCL.1 |   IN | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 1 | ALT0 | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | ALT0 | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |   IN | 0 | 11 || 12 | 0 | IN   | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | IN   | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI |   IN | 0 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO |   IN | 0 | 21 || 22 | 0 | IN   | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK |   IN | 0 | 23 || 24 | 1 | IN   | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 1 | IN   | CE1     | 11  | 7   |
 |   0 |  30 |   SDA.0 |   IN | 1 | 27 || 28 | 1 | IN   | SCL.0   | 31  | 1   |
 |   5 |  21 | GPIO.21 |   IN | 1 | 29 || 30 |   |      | 0v      |     |     |
 |   6 |  22 | GPIO.22 |   IN | 1 | 31 || 32 | 0 | IN   | GPIO.26 | 26  | 12  |
 |  13 |  23 | GPIO.23 |   IN | 0 | 33 || 34 |   |      | 0v      |     |     |
 |  19 |  24 | GPIO.24 |   IN | 0 | 35 || 36 | 0 | IN   | GPIO.27 | 27  | 16  |
 |  26 |  25 | GPIO.25 |   IN | 0 | 37 || 38 | 0 | IN   | GPIO.28 | 28  | 20  |
 |     |     |      0v |      |   | 39 || 40 | 0 | IN   | GPIO.29 | 29  | 21  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+

For some time now, it has been necessary to activate kernel support for the optional I2C module with the Raspberry Pi configuration tool. You can call this tool via sudo raspi-config and set the option under 8 Advanced Options | A7 I2C to Yes. Afterward, you should close the tool and restart the system with the command sudo reboot. To load the I2C driver and test whether the devices connected to the bus report correctly, enter:

gpio load i2c
i2cdetect -y 1

In the example from Listing 3, the PCF8574 (0x3f) and the two LM75 temperature sensors (0x48 and 0x49) respond quickly. To test the digital inputs, you can read them every two seconds with:

watch i2cget -y 1 0x3f

Listing 3

I2C Driver Test

$ gpio load i2c
$ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 3f
40: -- -- -- -- -- -- -- -- 48 49 -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

The bit will be set to 1 depending on which input has voltage. The inputs correspond to the four lower value bits. To test the outputs, you should set the higher value bits to 0. In this way, you can gradually turn on the outputs (Listing 4).

Listing 4

Turning On Outputs

$ i2cset -y 1 0x3f 0xef
$ i2cset -y 1 0x3f 0xdf
$ i2cset -y 1 0x3f 0xbf
$ i2cset -y 1 0x3f 0x7f
$ i2cset -y 1 0x3f 0xff

Reading the two LM75 sensors requires a little more work and has already been described in detail in a previous article [10]. That article contains a full description of how the LM75 works with the Raspberry Pi, as well as tips for control and testing.

Conclusion

The RPi-ified greenhouse gets all new hardware with this update. Even though the upgrade does not bring additional functionality to the first design described in 2014, the new project makes it easier to expand the hardware. This means there is ample opportunity to develop this project further. For instance, controlling the greenhouse could be addressed in a home automation scenario. Look for new greenhouse projects in future articles.

Buy this article as PDF

Express-Checkout as PDF

Pages: 6

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content