Reef Discussion

Rob

Member
Apr 26, 2012
743
424
Software Install -One Wire File System [owfs]
These instructions should get the 1wire web interface functioning so that you can see any sensor connected to the 1wire bus from your windows machine using firefox or IE.

It does not cover how to setup the ethernet port as a fixed IP address etc however the initial sdcard image is already setup up dhcp so your home router will issue an ip address and get your raspberryPi connected to the web automatically. You should probably look at a fixed IP address and port forwarding however suggest you get owfs installed and running first as this is the most complex hardware/software section in getting the RPi monitoring data. Everything after this is just how you use the owfs data.

Software References
http://www.raspberrypi.org/downloads
http://wiki.temperatur.nu/index.php/OWFS_with_i2c_support_on_Raspberry_Pi_(English_version)
http://www.abelectronics.co.uk/owfs-and-compi/info.aspx
http://owfs.org/

General Notes
Windows : Instead of having a screen and keyboard connected to the RaspberryPi you can log into the RPi with a ssh client from a windows machine. This entire writeup only uses the command prompt and not the RPi desktop. You NEED putty on a windows machine that way you can simply cut and paste commands = not too much typing.

Putty.
To copy from windows (ie a command from this writeup) to putty
  • copy the text to the windows clipboard, standard windows stuff
  • in the putty window right click the mouse button pastes onto the command line.
To copy from putty (I used this to copy my commands into this writeup)
  • swipe the text to highlight it in putty (no need to click anything here just highlight it
  • in windows then simple use "paste" into your document
RaspberryPi has a text editor called nano, crtl o = saves, ctrl x = exit

Windows support packages
You will need :
  • Win32DiskImager to write the initial image to the SDcard
  • putty open source secure shell client to log into Raspberrypi.
Hardware Setup
The hardware setup is quite easy.

  • The standard 5VDC power supply connected to the RPi
  • Keyboard and monitor only needed for the first boot-up
  • Ethernet cable connected to your router
  • 1wire board simply plugged into the GPIO header (let RPi power it)
  • at least one DS18B20 temperature sensor
Create an SD card (time 10 minutes)
Its very easy to create an SDcard for the raspberrypi. Simply use a program called Win32DiskImager.exe and write an image to an sdcard. The program and image is available from the Raspberrypi downloads page.

I used the following image: 2013-02-09-wheezy-raspbian.img

First Boot (time 5 minutes)
This is the only time I connect a screen and keyboard to the Raspberrypi.

Initial power-up will show a menu, I set the following:
  • Change password
  • Change timezone
  • Enable ssh
  • Expand root partition
  • Update
Better find your IP address.
When you have completed this you will end up at a command prompt. Maybe a good idea to find the Rpi IP address so you can then use a putty client to log in and complete the rest of the setup using a windows machine.

root@raspberrypi:~# ifconfig
Will show you the assigned IP address.

NETWORK (@Clownfishy)
Although this guide does not go into network setup (better done elsewhere) a few tips may assist if using the nano style USB wifi adpaters

Enable Re-connect
By default the WiFi will not try and reconnect to your router if it drops the connections. Create a new script containing the commands below and run it in the background which will continually check for dropouts and reconnect if a drop is detected -

Code:
#!/bin/bash
 
while true ; do
if ifconfig wlan0 | grep -q "inet addr:"
then
sleep 60
else
echo "Network connection down! Attempting reconnection."
ifup --force wlan0
sleep 10
fi
done

Turn Off Power Saving
Add the following line to your interfaces file as the USB Wfif adapter can auto powerdown
wireless-power off



Setup I2C (time 2 minutes)
pi@raspberrypi:~# sudo -i
root@raspberrypi:~# nano /etc/modprobe.d/raspi-blacklist.conf
You need to add “#” before this line: blacklist i2c-bcm2708

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


Raspberrypi I2C Port Numbers
There is a difference between models sold before OCt 2012 when it comes to the I2C ports. Although the physical GPIO connections are the same I think they have added another port for maybe a camera or something, really do not know.

Raspberrypi GPIO Sold before October 2012 uses I2C port: 0
Raspberrypi Style A or B GPIO uses I2C port: 1


Install The 1wire support packages including I2C-tools (time 15 minutes)
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 1wire 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.


TEMPERATURE SENSORS

Install OneWireFileSystem OWFS (Time 40 minutes)

The link below uses the owfs version 2.8p17. I like this version as its been rock solid over the last 6 months. I did try the "latest version" however it did not work so went back to 2.8p17.

pi@raspberrypi:~# sudo -i
root@raspberrypi:~# cd /usr/src
root@raspberrypi:~# wget http://downloads.sourceforge.net/project/owfs/owfs/2.8p17/owfs-2.8p17.tar.gz
root@raspberrypi:~# tar zxvf owfs-2.8p17.tar.gz
root@raspberrypi:~# cd owfs-2.8p17
root@raspberrypi:~# ./configure (takes about 3 minutes)
root@raspberrypi:~# make (takes about 30 minutes)
root@raspberrypi:~# make install (takes about 2 minutes


Install startup script so owfs starts automatically
OWFS has a number of programs associated / available with it. I suggest you only start owserver and the web interface owhttpd. You can also try the fuse file system however get the above two services running first before messing around with fuses virtual file system stuff. The web interface provided by owhttpd is way better for testing.

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 startAquaPi.sh

Paste the follow text into the file startAquaPi.sh:

Code:
#!/bin/bash
 
### BEGIN INIT INFO
# Provides:          startAquaPi
# Required-Start:    $local_fs $syslog
# Required-Stop:    $local_fs $syslog
# Default-Start:    2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start OWFS at boot time
# Description:      Start OWFS at boot time
### END INIT INFO
 
# 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.


IMPORTANT
Older boards you need to change the owserver line above to use I2C port 0
/opt/owfs/bin/owserver -p 3001 --i2c=/dev/i2c-0:ALL

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

Manual starting of the owfs server (Should not be required just use the startup method above)
I hope I do not confuse people here however there is nothing stopping you manually starting owserver and owhttpd by simply issuing /opt/owfs/bin/owserver -p 3001 --i2c=/dev/i2c-1:ALL and /opt/owfs/bin/owhttpd -s 3001 -p 3002 on the command line. In fact any startup script simply types their commands for you when raspberrypi boots. However you can only have 1 instance of owserver and owhttpd running so do not install the startup script and then try and issue these start up commands manually without first stopping the programs if they are running. To see what programs are currently running

pi@raspberrypi ~ $ sudo -i
root@raspberrypi:~# ps -el
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
1 S 0 2023 1 0 80 0 - 11047 poll_s ? 00:00:02 owserver
1 S 0 2026 1 0 80 0 - 4905 poll_s ? 00:00:00 owhttpd

to stop a program use the kill command followed by the program number (PID) you want to kill.
root@raspberrypi:~# kill xxxx In the case above xxxx = 2023 and 2026 to kill both owfs services



Test owfs is functioning
We use the built in web interface owfs provides. There is NO need for apache at this stage.

reboot raspberrypi and make sure your still plugged into your home network
root@raspberrypi:/etc/init.d# shutdown -r now

From your windows machine go into firefox or internet explore 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.

aimg.photobucket.com_albums_v319_rjconway_owfs_web.jpg

If you got this far owfs is installed successfully. :) From this interface any sensor you attach to the 1wire interface will be automatically shown in the list together with all its parameters. No further owfs install or programming is required. Thus the simplicity of 1wire. The next section plugging in your first sensor.


Connecting the Temperature Sensors
I am going to connect three temperature sensors which use the dallas 18B20 device. I purchased the units from littlebird as they are very well sealed however you can make your own.
  1. Strapped to Heater
  2. Display Tank Temperature (located ion sump)
  3. Ambient Temperature
Hardware

1wire interface board
[Broken External Image]:http://www.abelectronics.co.uk/docs/stock/raspberrypi/1wirepi/1wire-1.jpg[Broken External Image]:http://www.abelectronics.co.uk/docs/stock/raspberrypi/1wirepi/1wire-4.jpg
acdn.shopify.com_s_files_1_0062_6682_products_11050_04_1024x109806f94b00a36d1ba4e5b0b38cb26a87.jpg


Wiring (water proof temperature sensor)
The 1wire board includes an ESD suppression device on both the data line (OW) and the negative line (RT) Thus the sensor negative is better connected to the RT terminal. All 1wire devices are just connected in parallel so you will have to connect all sensor cables together

Sensor 1Wire Board
Red -> 5VDC (Supply +ve)
Black -> RT (Return -ve)
White -> OW (1wire Data)

Display the Sensor Data
Just type again 192.168.x.x:3002 in firefox or IE as per the testing phase above. Calling up the web interface shows the following main display, choose a sensor (the DS18B20 temperature sensor ID always start with 28.xx).

aimg.photobucket.com_albums_v319_rjconway_owfs_web2.jpg

OK if you have reached here you have successfully installed owfs and can call up any 1wire connected sensor. (There are lots of different 1wire sensors available) You can run it like this until we get an interface installed which I will need another couple of weeks before I have time to write it up.

You need to label your sensors with their respective addresses 28.xxxxxxx as you will need to know the ID when it comes time to read the data via a script instead of looking at the web interface. The script will read the temperatures via owserver and push the data into a user defined web page.

Hardware and software are now installed and verified for 1wire devices. This data will be used in a bash script in the section "Logging Data".


HUMIDITY SENSORS


awww.adafruit.com_adablog_wp_content_uploads_2011_06_dhtsensors_t.jpg

Using a DHT22 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. Wiring is as per the link below, remember to use 3.3V and NOT 5VDC

Accuracy: I do not know how accurate it is, I would trust a 1wire DS18B20 temperature sensor more than this device however its a cheap way of getting humidity. Real world results, 3xDS18B20 connected to the RPi and the DHT22 -1wire sensors data 21.5,21.6,21.8 DHT22 was showing 22.1

Usage: I will probably use this to sense the house humidity & temps, then look at relationships to the qty of ATO I am using.

Connecting the DHT22 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

Pullup Resistor. You need to place a 4.7k resister between the data line and the 3.3V. I just soldered this at the sensor wires and used heat shrink to neaten it up.



Software install (Time 5 minutes)
Reference : 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 %
root@raspberrypi:#

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

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.

Hardware and software are now installed and verified for HDT22 Humidity device. This data will be used in a bash script in the section "Logging Data"




The following section is NOT completed
Enable Serial Port for connection to Atlas Scientific devices
The atlas scientific devices use a serial connection for communications. I have the pH, orp and the flow board and use a 3rd party flow sensor for $10.00. (BTW The flow sensor is monitoring my ATO). Each Atlas device needs its own serial connection as they are not addressable. As the RPi only has 1 serial port you need to be able to switch this serial port between multiple devices. Atlas has recognised this and created a serial port connector board which allows up to 4 devices to share a single serial port. (i.e. 4 port multiplexor) This board connects to the RPi serial tx/rx and also uses two digital outputs to allow you to select which of its 4 devices you wish to communicate to.

The Atlas devices use TTL level 3.3 - 5VDC for its serial port which is the level of the RPi GPIO pins. Do NOT connect these devices direct to your PC's serial port or a max232 chip (+/- ~15v)

Thus for multiple Atlas devices you need to setup the software for a couple of things:
  1. Disable RPi using the serial port as its terminal and stop it sending messages to the port
  2. Enable the GPIO library so we can turn on/off some IO pins. Two command outputs will be required to the serial port connector board to switch between its devices.
Disable Console Messages
Reference: abelectronics.co.uk

Install GPIO Library
Reference: WiringPi

Simple GPIO Test
You Will need to test that you can actually control the GPIO pins. Suggest you get a single LED with say a 370ohm resistor and connect it between the GPIO PIN and GND to the pin you want to test. Make sure you can turn on / off the GPIO pins. These "output" pins will be connected onto the Atlas serial port board to enable selecting which device the RPi will communicate to.

To test the GPIO pins I would use the command line options below. This is also the commands used within the script we shall use to eventually read the Atlas devices with.

pi@raspberrypi ~ $ sudo -i
root@raspberrypi:~# gpio -g mode 17 out
root@raspberrypi:~# gpio -g write 17 1 (turn ON)
root@raspberrypi:~# gpio -g write 17 0 (turn OFF)

Do NOT continue until you can prove you can switch on/off at least two outputs (GPIO 17 & 18) and you know the corresponding physical GPIO pins.

Connection of the Hardware
Reference: Atlas document for connection diagram, Atlas Serial board

Note. As the GPIO pins run at 3.3VDC it is important to run the Atlas serial board and sensors at 3.3V. There are Atlas boards, (I think conductivity) that need 5VDC so you would need some additional electronics or level shifter to convert the 5V to 3.3V. The only GPIO pin that would cause issues is the serial receive pin of the RPi..
  • After testing out two GPIO pins, (I used GPIO 17 and 18) connect these to the inputs S0 & S1
  • Connect the Tx Rx pins from the GPIO to the serial board Tx Rx (you have to cross them, tx->rx and rx<-tx)
  • Connect the 3.3VDC and GND from the GPIO header pins to the Serial board VCC and GND
  • Make sure the serial board E (enable) input is connected to GND
Testing of the Serial Connection
TBA


Logging Data
 
This is brilliant' I will give it a go today :-)

Regarding the the cabling of the temp sensor, how did you cable yours to the 1 wire board as I can't work this out with my very limited knowledge of electronics. In fact' I think I have blown my temp sensor as the end of it has blown up like a small balloon.......too much power going to it I think. :(


Again many thanks for all your help.
Sent from my Nexus 10 using Tapatalk 2
 

Rob

Member
Apr 26, 2012
743
424
NO, I have a few of these and they do not seem to be sealed. Better to:
  • make your own, simply buy the DS18B20 and silicon it into a nylon tube (see below)
  • buy the ones from littlebird electronics
aimg.photobucket.com_albums_v319_rjconway_1wire_temp_1.jpg
 

Rob

Member
Apr 26, 2012
743
424
@MagicJ yes I did make it about 5+ years ago. using a nylon or stiff tube just fill with silicon.
There is a trick to building these and that is to cut a slit in the top of the tube about 25 mm. Its difficult to explain however feed the wires into the tube so they come out the bottom then down the slit so the outer insulation is all the way down the slit. Solder the DS18B20 to the wires then pull the wires up out of the slit. That way the cables outer insulation is better positioned just at the top of the tube. I then silicon the top of the tube as well and added an insulator from a DC power jack.

@Clownfishy Sounds like you have stuffed the sensor is its expanded. How did you wire it ? Surprised the 5VDC fuse on the raspberrypi is not blown if you have pumped enough power into it for the sensor to physically expand :(

I have now edited the instructions above and added a section in connecting the sensors to the 1wire board,
 
Thanks for the update. When "sudo update-rc.d startAquaPi.sh defaults"

I get -

insserv: warning: script 'K01owstart.sh' missing LSB tags and overrides
insserv: warning: script 'owstart.sh' missing LSB tags and overrides

Apache is running as this is all I get when trying to access the webserver -
It works!

This is the default web page for this server.
The web server software is running but no content has been added, yet.
 
Not sure how, but the sensor still seems to be working -

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: -- -- -- -- -- -- -- --
 

Rob

Member
Apr 26, 2012
743
424
OK, its good that I2C is recognizing the board thats good news

It does NOT need Apache or any other packages other than I provided above.

I think your error is something to do with a previous install as the above instructions do not use owstart.sh if you have already tried to install owfs previously you better delete either owstart.sh or startAquapi as you have two instances both trying to startup the same program owfs. You better find the command to remove startup scripts its probably a switch in the update-rc.d script and remove one of them. the above script is exactly what I am using on my new SDCARD. I would remove the owstart script

On a command prompt just start owfs manually by issuing the following two commands, however you may find your previous installation using owstart is interfering with startAquapi. You can only have one startup file.


For style A Raspbberypi
/opt/owfs/bin/owserver -p 3001 --i2c=/dev/i2c-0:ALL
/opt/owfs/bin/owhttpd -s 3001 -p 3002

For style B Raspbberypi
/opt/owfs/bin/owserver -p 3001 --i2c=/dev/i2c-1:ALL
/opt/owfs/bin/owhttpd -s 3001 -p 3002
 

Rob

Member
Apr 26, 2012
743
424
see previous post I edited with more info, I suggest you try and remove the startup scripts as having two startup scripts will clash with one another as they are both trying to start the same device.
 

Rob

Member
Apr 26, 2012
743
424
I know its not helpful as there is no change control however I have edited the instructions a few times tonight to add and expand the comments and will keep doing so.
 

Rob

Member
Apr 26, 2012
743
424
yes RPi model A uses 0 in all its I2C commands.

Its a shame BUS0 is not showing up, have you disconnected the fried sensor ? I would think your software is now installed OK. I am concerned that the 1wire board is also fried if BUS0 is not showing up. I assume you have not touched the jumper on the 1wire board and its still in place ? only power connection is via the raspberrypi 5VDC plug pack.

Bus.0 is the actual 1wire device driver chip which is located on the 1wire board, it is NOT a sensor its the driver that converts I2C to 1wire.

Do you remember how you connected the sensor which caused it to heat up. ? red (+) black (-) is very common for electronic connection so don't quite understand what you did to cause the sensor to actually deform :confused:
 
Damn, I may have fired my board then:(. For some reason I cannot even see the web interface now. I have removed the sensor and still not web interface. I cannot remember how I cannected it as I was trying all sorts of ways. Note to self, if you do not know what your doing, wait until the instructions are available:confused:

I am going to trash my SD card and them start from scratch to see what I can get.
 
Update, reinstalled all the software and the web interface is working. I do not get the bus.0 in the view so as you have said, I may have fried the board. I have ordered another sensor and will contact the makers of the board to see what they think

Sent from my Nexus 10 using Tapatalk 2
 
For information, if anyone is using a WIPI USB WiFi adapter, you may need to add -

wireless-power off

To your etc/network/interfaces file. I was getting a lot of drop outs and thought it was my power adaptor but it turns out this is a known problem with these adapters. I will have added this to my config and so far, no dropouts......will keep you updated.

Sent from my Nexus 10 using Tapatalk 2
 

Rob

Member
Apr 26, 2012
743
424
I have started to add the Atlas Interface to the software setup guide, I will just keep amending the software setup post, on page 5 of this thread.

@Clownfishy Good tip about the wifi, glad you can now install and see the owfs web interface. The only thing software wise I can think of is the owserver not connecting to the interface board. With the problems you had with your wiring it may be easier to try another board. I assume you understand the I2C port stuff now.