Building bbPool

The needs

As for poolDuino, I want to measure :

  • water pH, ORP and temperature
  • air temperature

and report that on my emoncms web site.

The hardware

Connecting temperature sensors to the BBB…

and reading the values…

Information for those two temp sensors can be found here for DS18B20 and here for AtlasScientific ones.

Connecting pH and ORP sensor

AtlasScientific pH and ORP stamps are using simple asynchronous serial communication protocol. For communicating with them, we will use 2 of the 4 UARTS available on the Beaglebone, UART1 & 4.

P1040843

Enabling UARTS

First, you need to enable UARTs 1 & 4. That’s easy :

Yeah… I know, but that’s easier like that : don’t need to type sudo before each command. But keep in mind you are root and you can destroy your Ubuntu. So think before you type !

Here, we can see UARTs are not enabled. So let’s enable them.

Reading from UART

I am a perl fan… so I’ll show a perl example, no python as I don’t know python and there is a handfull of examples using python…

I used Device::SerialPort library which is quite handy.

Code is here on GitHub. This code sets pH stamp in continuous reading and reads output every second.

Conclusion

I now have a Beaglebone connected to 2 temperature sensors, an ORP and a pH stamp, and I can read all those sensors value 🙂

I am working on a web GUI to display the information, send the info to my emoncms website and be able to configure the gizmo. So stay tune !

 

poolDuino hardware & software details

pH and ORP stamp are using standard serial communication to send data they read from the probe. So I used the SoftwareSerial library to get data processed by the arduino and I connected :

  • pH RX & TX pin respectively to pin 2 & 3 on the arduino
  • ORP TX & TX pin respectively to pin 5 & 6 on the arduino

Temperature sensor is an analog sensor which I connected to pin A0.

PoolDuino 640x480

Also, I connected power (3.3V) and ground to respective power lines of sensors.

Test code (which is way more complicated than it should be because I was first planning to use an arduino as the final solution… but then decided to go for a BeagleBone) can be found here : https://github.com/jsiobj/poolDuino

Connecting Atlas Scientific temperature sensor to the BeagleBone Black

For the beaglePool, I needed a waterproof temp sensor which I found at AtlasScientific, along with pH and ORP circuit. And I quite had hard time figuring out how all this works.

Important : Things are moving quite fast is Beaglebone “young” world and you can install several different distros on it. This article applies to Beaglebone Black running Ubuntu with a 3.8 kernel. See this post for more information on how I installed Ubuntu.

The simple part : Adapting output voltage

AtlasScientific sensor is an analog sensor which ranges from -20°C up to 133°C matching 0 to 3V. But Beaglebone Black analog input only support up to 1.8V. So first thing to do is to build a simple voltage divider with 2 resistors. I chose 1% tolerance resistor for better accuracy.

VoltDivider

Enabling Analog input on BeagleBone

There are a lot of ressources on the web but thing are changing fast in quite young Beaglebone’s world.

By default, analog inputs are not enabled. You need to configure the system to enable them. Doing so can be done easily (once you know how to do it…) by using Device Tree and Device Tree Overlays.

If you want to configure it manually you can issue this command

You can check this has been taken in account cat’ing slots file :

The last line show iio overlay has been loaded.

But, this configuration is not kept after a reboot. If you want to set it up once for all and have analog inputs enabled at next reboot, you need to modify uEnv.txt file located in /boot/uboot

Here, it is cape-bone-iio which has been added. The 2 other entries are here to enable UARTs which I am using for another purpose (ORP and pH sensor).

Important : This configuration apply to Beaglebone Black running Ubuntu. The file uEnv.txt may be different for Angström.

Connecting probe to Beaglebone Black

BBB Atlas Scientific Temp

Not much to say really…

  • Sensor is powered through 3.3V pin (P9.3)
  • Data line is connected to one end of the 10kΩ resistor
  • Pin P9.36 (AIN5) is connected in the middle of the voltage divider, between 10kΩ and 15kΩ resistor so that voltage remains below 1.8V
  • the other end of 15kΩ is connected to ADC Ground (P9.34)

Reading output and convert to °C

Once properly configured, you can read value of ADC’s output using a pseudo file (here analog input 5) :

1076 it the raw ADC value, that is a value between 0 and 4096 (12 bits ADC.) So to get value in mV you’ll need to convert this value :

But… what we need it temperature (in °C), not mV…

Given probe Datasheet :

  • 0 is -20°C
  • 3V is 133°C but remember… we scaled it down to 1.8V

So :

  • 1 “step” => (133+20)°C/4096 ~ 0.0373°C/mV
  • 1076 => 1076*0.0373°C-20°C = 20,1348°C

Good ! Seems to work 🙂

Important

It seems that there other pseudo files with Linux kernel < 3.8. You counf find those files in /sys/devices/ocp.*/helper.*/AIN* :

Output of those files were directly mV :

Also, when overlay is loaded after boot time from the shell, I can see /sys/devices/ocp.*/helper.*/AIN* files. When load at boot time using uEnv.txt, they just don’t exists while /sys/bus/iio/devices/iio\:device0/in_voltage*_raw does.

Don’t ask me why… Anyway, those pseudo files seem deprecated.

References I used (thanks !)

Let’s build a pool monitoring system : poolDuino

Because my parents have a quite expensive pool monitoring system that is not even able to grah collected data, I decided to have a look at what I can do.

What do I need to measure ?

  • pH
  • ORP (redox)
  • temperature

Well… temperature is easy. There are plenty of easy to use sensors available. It becomes a bit tricky for pH and ORP. Actually, you can’t just connect an ORP or pH sensor directly to an Arduino as you would with a temperature sensor. pH and ORP probes are generating very small voltage and current. Their output needs to be amplified quite a lot.

As I am not an electronics specialist, I desperately looked for some “pre-build” pH and ORP sensor that would be quite easy to use. There are quite a few very nice and smart projects around :

  • LeoPhi : only pH though, no ORP
  • phDuino : still only pH
  • Arduiarium : got pH, ORP, EC,  1wire, I2C… a bit of an overkill for what I needed
  • and probably many more…

I finally found Atlas Scientific pH and ORP stamps : not that expensive (before I had to pay VAT on parcel collection plus a fee… for VAT collection !), very nicely build, small, easy to use… Exactly what I needed.

orp&ph 640x480

I then build a first prototype using an Arduino Ethernet. Not that I will be using ethernet capability but it has an SD card slot so that I could record collected data on a 2Gb SD. I would just have to connect the Arduino to a power source and plunge the 3 probes in the pool.

PoolDuino 640x480

I left the probe for around a day and a half running and took the SD card back, loaded the data into a Google Fusion table which gives the following results :

[iframe width=”510″ height=”100″ scrolling=”no” frameborder=”no” src=”https://www.google.com/fusiontables/embedviz?containerId=gviz_canvas&q=select+col0%2C+col3+from+1zWy-wOUpEFkmKwPhjUALB4IOt2t_-BQKA_-HaLE+order+by+col0+asc&viz=GVIZ&t=AREA&rmax=250&uiversion=2&gco_forceIFrame=true&gco_hasLabelsColumn=true&width=510&height=100″]

[iframe width=”510″ height=”100″ scrolling=”no” frameborder=”no” src=”https://www.google.com/fusiontables/embedviz?containerId=gviz_canvas&q=select+col0%2C+col1+from+1zWy-wOUpEFkmKwPhjUALB4IOt2t_-BQKA_-HaLE+order+by+col0+asc&viz=GVIZ&t=AREA&rmax=250&uiversion=2&gco_forceIFrame=true&gco_hasLabelsColumn=true&att=true&width=510&height=100″]

[iframe width=”510″ height=”100″ scrolling=”no” frameborder=”no” src=”https://www.google.com/fusiontables/embedviz?containerId=gviz_canvas&q=select+col0%2C+col2+from+1zWy-wOUpEFkmKwPhjUALB4IOt2t_-BQKA_-HaLE+order+by+col0+asc&viz=GVIZ&t=AREA&rmax=250&uiversion=2&gco_forceIFrame=true&gco_hasLabelsColumn=true&width=510&height=100″]

Works great ! The pH drop is due to adding (a bit too much) pH minus solution as pH was a bit high.