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 !)

WiFridge : the software

Arduino’s code

It can be found here on github. I won’t post it here. I hope comment in the code are sufficient to understand what I did. I will just describe main principles here.

Reading sensors

I used those libraries :

  • For 1-Wire, PJRC library which can be found here.
  • For DHT temp & humidity sensor, Adafruit library which can be found here.

WiFly

The goal is to send sensors data to an emoncms web site so that it can be historized and graphed. For that matter I built 2 web emoncms websites :

  • one on the internet on a shared hosting
  • one on a small and cheap Raspberry Pi

I know of 2 libraries for this WiFly module :

  • the one based on sparkun Sparkfun WiFly shield which can be found here
  • another one called WiflyHQ which can be found here

I first tried Sparkun lib but I could not get a stable web connection. It would eventually failed to connect to the destination web server after a random period of time. So I had a try for WiflyHQ. In the end, I still have stability problems but I find it easier to use as it kind of replicates all RN-XV functions whereas Sparkfun one tends to “hide” the bits and bytes but making it a bit more cryptic to me.

Also, samples in WiflyHQ makes use of a software serial port by default  whereas Wireless shield is using the hardware serial from the Arduino which is getting complex as you can’t really use the serial port for debugging without a risk of disturbing the Wifly module (see Hardware post here.)

Because of WiFly connection instability (it may be my code though wich is not… optimal…), I tried to use watchdog library to reboot both wifly and arduino in case something went wrong by entering an infinite loop which will eventually restart the arduino.. Not that efficient though… I still have some case where everything is stuck, not sending any data, but not rebooting… Or the wifly wont just properly reboot.

So I used the leds the try to grab some diagnostics information… but it does not really helped. It seems that the wifly will not get out of command mode from time to time. No idea why…

What’s next

Because of this instability, I want to try the quite new CC3000 wifi shield from Adafruit ! Just received it. I will migrate my code to work with that promising shield 🙂

 

 

From poolDuino to bbPool

My fisrt pool monitoring system was Arduino based (more info here.) It could collect pH, ORP and temperature from my pool and store it on an SD card. But I wanted to send all this data to some web site like my own emoncms.

So I needed Internet access. To do this with an Arduino, I either need

  • An Arduino Uno + an ethernet shield (~20€ + 35€ = ~55€)
  • An Arduino Ethernet (~60€)
  • An Arduino Uno + Wireless Shield + RN-XV Wifly (~20€ + +17€ + 44€ = 81€ )
  • An Arduino Yùn (~62€)

But…

  • If I want Wifi, I found RN-XV module difficult to use and quite instable (no sure though if it is my program, the libs I use or the wifly itself.)
  • A Raspberry Pi is less than 40€, has build in ethernet, is way more powerfull… and adding Wifi is ~20€

Problem though : Pi has only 1 UART available… and I needed 2. I known there are workarounds but having a look around, I stumbled upon BeagleBone Black (BBB) :

  • Build in ethernet
  • Many GPIO ports and several UARTs
  • Running Linux

And “only” 45€ !

So I decided I’ll give it a try : poolDuino is now becoming bbPool !

 

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.

WiFridge : hardware details

In this post, I will give the details of the WiFridge hardware : how to connect the probes to the Arduino. It follows the post here.

The hardware

Here is the bill of material :

  • 1 AM2302 Humidity & temperature sensor
  • 2 DS12B20 1-wire waterproof temperature sensor
  • 3 3mm LEDs (green, yellow, red)
  • 3 1kΩ resistor
  • 1 10kΩ resistor
  • 1 4.7Ω resistor
  • 1 Arduino Wireless shield
  • 1 RN-XV Wifly module
  • some solderless breadboard
  • a bunch of wires

Fritzing Wifridge

It is connected as describe on the previous figure (created mostly with Fritzing.)

  • AM2302 : data connected on digital input 3 for kitchen temperature and humidity connected to a 10kΩ pull-up resistor
  • both DS18B20 : data on digital input 2 for fridge and freezer temperature, connected to a 4.7Ω pull-up resistor
  • status leds on digital inputs 6, 9 and 10 (optionnal though, just here for displaying status when operating) through 1kΩ resistors.

The 3 sensors are also connected to ground and +5V through their corresponding wire.

WiFridge Front Final with notes

Also, to simplify debugging, I decided to connect WiFly UART to a software serial port on the Arduino so that the hardware serial is free for programming and debugging. I simply cut off the Rx and Tx legs on the shield and reconnected them to digital pin 7 & 8. But it is possible to only bend the legs so you can revert the process.

Wifridge Rx Tx cutoff 640x487

 That’s it for the hardware. In a coming post, I will describe the software part.

Introduction to one of my first Arduino based project : WiFridge…

… or why one would want its fridge to be connected to the internet !

This is one of my first Arduino based project. I had some issue in the past with my freezer that would let the temperature going to high for too long and I had no way of knowing before it was too late. I could barely detect it happened by using an ice cube in a glass that would melt in case of a huge temperature problem. That is why I decided to build the WiFridge : a wifi device that would monitor my fridge’s and freezer’s temperatures and send an alert in case anything goes wrong.

I first tried using an Arduino Ethernet because it was far less expensive than an arduino with a wifi shield. But… I have no ethernet port near my fridge and I did not want to have an ethernet cable across my kitchen… So I had a look on internet and decided to go for a RN-XV WiFly Module from Roving Networks and the ad-hoc shield.

WiFridge 1000x750

For the temperature part, I bought 2 DS18B20 sensors, in a waterproof package, coming with a 1m long cable and its 4.7k pull-up resistor. I also bought an DHT22/AM2302 temperature and humidity sensor so I can get my kitchen’s environnement data along with fridge’s and freezer’s temperatures. Both sensors are digital sensor. That is, they send the temperature (and humidity for the AM2302) in the form of bits, not an analog voltage. DS18B20 sensor is using 1-wire protocol which I found very nice because I can connect both DS18B20 sensor to the very same input.

Add a few leds for monitoring the status of the gizmo, a bit of soldering after some testing on a breadboard, a few lines of code, and that’s it, I got my WiFridge up and running, sending data to the internet…

In a coming post, I will go into more details, give a detailed schematic for the hardware, describe Arduino’s code that I used (I am still working on it though as I have some Wifi stability problems…) and how I sent data to my emoncms web sites (one local on a Raspberry Pi and one on a shared hosting.)

IP remote controlled power strip

Before discovering Arduino’s world, I found a nice ethernet relay board from a french manufacturer : the IPX800 v2. It is a bit expensive (~125€) but works out of the box : no programmation needed. Power it, connect through a brower, and it works !

It comes with (not an exhautive list, see here for more details.)

  • 8 outputs relays (250V / 10A)
  • 4 digital inputs that can be associated to the output (i.e. you can open / close the relays)
  • an ethernet port
  • an embedded tcp and web servers for remote control

What I did with it is a powerstrip for my audio/video system so that I can individually switch things on and off when needed with my smartphone and not leave them in standby mode.

ipx800 01 643x473

I first used the build in web site (with a bit of customization for switch names) and the started using OpenRemote software to build a nicer interface for my smartphone. From there I can individually switch on and of the 8 outlets.

Remote

But remote control is not always as handy as physical button. If you don’t have your phone around, or have not battery left… it is usefull to have a way of manually switching you amp & projector on when you want to watch your film ! So I added 4 buttons connected to the 4 digital inputs available…

IPX800 04 722x386

… and then configured the IPX to toggle the relays.

2013-08-27 20_12_27-gce.electronics relay board

And here I go : I now have an IP remote controlled power strip !

JS