Hi there!

Welcome to my website.

I decided upon buying a Raspberry Pi. For those who don’t know what it is, the Raspberry Pi is a credit-card sized computer.  It’s a nice little PC which can be used for many things for a small price.

As my hobby is keeping aquariums, I was wondering if I could use it to build a Aquarium Monitor.
On this blog I will keep you informed about the progress in building this aquarium monitor.

So I hope you stay tuned and follow me on the way to success ! (hopefully)

The Aquarium monitor

The aquarium monitor.
What should it do, or better what would I like it to do.

  • Measure the water temperature
  • Measure the room temperature and humidity (nice to have)
  • Measure the Ph
  • Switch lights with clock
  • Dim some leds (moonlight)
  • Feed the fish
  • A nice web interface

Feel free to add some ideas.

Setup the Raspberry Pi

The hardware needed for setup:

  • raspberry pi
  • fast SD card minimum 4Gb
  • 5V/1A power supply
  • monitor and keyboard (only during first setup)
  • network cable connected to your router

Windows software

  • Win32DiskImager to write the initial image to the SDcard
  • SD Formatter to format your sd card

Creating the sd card

    • Format your sd card using SD Formatter
    • Download an image file, I used 2013-07-26-wheezy-raspbian
    • Write image to sd card using Win32DiskImager

Note: The built ­in Windows formatting tool will only format the first partition that Windows can read ­ not the entire disk. For this reason I advise using the official SD Card Association Formatting Tool.

First boot

Boot your newly created sd card with the monitor, keyboard and network connected.
After initial power-up set the following:

  • Expand root partition
  • Enable overscan if needed
  • Change Timezone
  • Enable boot into desktop
  • Configure keyboard
  • Change locale if needed
  • Change password
  • Enble ssh

Should you ever need to run the initial setup again you can start it by entering the following code: pi@raspberrypi:~#sudo raspi-config

After the setup you better find out your ip-address. To do this open a console windows and enter the following code: pi@raspberrypi:~#ifconfig

As of now I won’t be using the monitor and keyboard anymore. To connect to raspberry pi I will be using ssh on my windows laptop.

Software resources


Let’s Measure

Next step is connecting some sensors and try to get some measurements.
On my search for the rights sensors I came up with these sensors.
For the water temperature I used the waterresistant type of the DS18B20.

To measure the room temperature you could use the normal DS18B20, but because I also wanted to measure the humidity I went for the AM2302. This is a low cost combined temperature and humidity sensor.

Because later I also want to connect a ph sensor (serial communication) I bought this nice add-on board from ABelectronics. The Com Pi supports RS232 and 1-Wire® protocols. A 5V buffered I2C port is also provided on the board.

Let’s get on with the software.

Set up I2C
pi@raspberrypi:~# sudo -i
root@raspberrypi:~# nano /etc/modprobe.d/raspi-blacklist.conf
Add “#” before this line: blacklist i2c-bcm2708

root@raspberrypi:~# nano /etc/modules
add a new line containing only the following 7 characters i2c-dev

Install the 1wire support packages including I2C-tools
root@raspberrypi:~# apt-get install automake autoconf autotools-dev gcc-4.7 libtool libusb-dev libfuse-dev swig python2.6-dev tcl8.4-dev php5-dev i2c-tools

Reboot and test I2C interface is working
Having the 1wire board connected onto the RPi we can see if the I2C 1wire bus master is recognized. Each I2C device has an address so simply scanning the I2C addresses should show the DS2482-100 which is used in these 1wire expansion modules. The response below shows the DS2482-100 is at address 18.

root@raspberrypi:/etc/init.d# shutdown -r now
pi@raspberrypi:~# sudo -i
root@raspberrypi:/etc/init.d# i2cdetect -y 1 (use "i2cdetect -y 0" for older boards)

0 1 2 3 4 5 6 7 8 9 a b c d e f
00: — — — — — — — — — — — — —
10: — — — — — — — — 18 — — — — — — —
20: — — — — — — — — — — — — — — — —
30: — — — — — — — — — — — — — — — —
40: — — — — — — — — — — — — — — — —
50: — — — — — — — — — — — — — — — —
60: — — — — — — — — — — — — — — — —
70: — — — — — — — —

Do not go past this step until the 1wire board is recognised and you know I2C bus is running. The 1wire board connected to the RPi is at I2C address 18. You do not need to remember this the owfs software automatically finds the I2C bus master.

Install OneWireFileSystem OWFS
pi@raspberrypi:~# sudo -i
root@raspberrypi:~# cd /usr/src
root@raspberrypi:~# wget http://sourceforge.net/projects/owfs/files/latest/download
root@raspberrypi:~# tar zxvf owfs-latest.tgz
root@raspberrypi:~# cd owfs-2.8pxx
root@raspberrypi:~# ./configure
root@raspberrypi:~# make
root@raspberrypi:~# make install

Install startup script so owfs starts automatically
We are going to start the owserver and the web interface owhttpd.

owserver: you specify the port it will transmit on “-p 3001” coupled with the interface to connect to. OWFS can use serial, usb or I2C. In our instance we use the I2C interface and we start the server up at port 3001.

owhttpd : You specify the server to connect to via a port number -s 3001 and the port the web interface will respond to -p 3002

Create the startup script
root@raspberrypi:~# cd /etc/init.d
root@raspberrypi:/etc/init.d# nano startOWFS.sh

Paste the follow text into the file startOWFS.sh:


# Starts OWFS
/opt/owfs/bin/owserver -p 3001 --i2c=/dev/i2c-1:ALL
/opt/owfs/bin/owhttpd -s 3001 -p 3002

# Setup Serial Port
stty -F /dev/ttyAMA0 raw 38400 cs8 -ignpar -cstopb eol 255 eof 255

The reference to the stty command is to setup the serial port for later connect to the Atlas Scientific pH and orp devices. Easier to add this now than go back at a later stage and edit this file. There is a couple more edits required to get the serial port running for Atlas serial devices so will add this section later.

root@raspberrypi:/etc/init.d# chmod +x startAquaPi.sh
root@raspberrypi:/etc/init.d# update-rc.d startAquaPi.sh defaults

Test owfs is functioning
We use the built in web interface owfs provides.
Reboot Raspberry Pi and make sure your still plugged into your home network
root@raspberrypi:/etc/init.d# shutdown -r now

From your windows machine go into webbrowser and type into the address bar
192.168.x.x:3002 (replace x.x with your RPi address and you should see the owfs interface).
If you get this than owfs is successfully installed. Any sensor you connect to the 1wire interface will show in this screen. In the screenshot you see that I connected a sensor with id 10.1D1754020800

Connecting the sensor to the 1wire board
Red -> 5VDC (Supply +ve)
Black -> RT (Return -ve)
White -> OW (1wire Data)

If you use multiple sensors, just connect them in parallel.

The temperatur / humidity sensor
Using a AM2302 sensor it is easy to get the temperature and humidity values. Adafruit have written a small program where you specify the pin and sensor type and it returns the values of temperature and humidity.

Software install
adafruit.DHT11/22 software-install

Install Tips:
Make sure your in the directory where you want to save the adafruit programs before git clone.
pi@raspberrypi ~ $ sudo -i
root@raspberrypi:# cd (to a place where you want to save the program)
root@raspberrypi:# apt-get install git-core
root@raspberrypi:# git clone git://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code.git
root@raspberrypi:# cd Adafruit-Raspberry-Pi-Python-Code
root@raspberrypi:# cd Adafruit_DHT_Driver

Now issue the command to interrogate the device which is type 22 on pin 4
root@raspberrypi:# ./Adafruit_DHT 22 4
Using pin #4
Data (40): 0x1 0xfd 0x0 0xdb 0xd9
Temp = 21.9 *C, Hum = 50.9 %

Now try the following
root@raspberrypi:# ./Adafruit_DHT 22 4 | grep "Temp" | cut -f4,8 -d " "
21.9 50.9

The above command pipes the results to grep, finds a line starting with Temp which in turn pipes the results to cut, which separates the line into fields by using a space ” ” and returns the 4th and 8th field.

Connecting the AM2302 Sensor
The sensor is easily connected to a GPIO pin on the RPi. adafruit DHT11/22 wiring

Pin 1 3.3V
Pin 2 Data -> GPIO pin 4 (or other pin, you can choose)
Pin 4 Gnd

If you use the AM2302 sensor no pull-up resistor is needed because one is already present in the housing.
If the DHT22 sensor is used then a pull-up resistor is needed. Place a 4k7 resistor between the 3V3 and the dataline.

Hardware and software are now installed and verified for the AM2302 Humidity device.