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.
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
root@arm:/# echo cape-bone-iio > /sys/devices/bone_capemgr.9/slots
You can check this has been taken in account cat’ing slots file :
root@arm:/# cat /sys/devices/bone_capemgr.9/slots
4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G 5: ff:P-O-L Bone-Black-HDMI,00A0,Texas Instrument,BB-BONELT-HDMI
7: ff:P-O-L Override Board Name,00A0,Override Manuf,BB-UART1
8: ff:P-O-L Override Board Name,00A0,Override Manuf,BB-UART4
9: ff:P-O-L Override Board Name,00A0,Override Manuf,cape-bone-iio
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
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) :
root@arm:/# cat /sys/bus/iio/devices/iio\:device0/in_voltage5_raw
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 :
Voltage (in mV) = (ADC output/4096)*1800mV
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
- 1 “step” => (133+20)°C/4096 ~ 0.0373°C/mV
- 1076 => 1076*0.0373°C-20°C = 20,1348°C
Good ! Seems to work 🙂
It seems that there other pseudo files with Linux kernel < 3.8. You counf find those files in /sys/devices/ocp.*/helper.*/AIN* :
root@arm:/# find /sys/ -name *AIN*
Output of those files were directly mV :
root@arm:/# cat /sys/devices/ocp.3/helper.15/AIN5
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 !)