WeIO and DS18B20 temp sensor (1wire)

As of today, there is not yet a library for 1-wire for WeIO but interrestingly enough, you can read 1-wire data through a standard UART.

WeIO & DS18B20 640x480

Here is what I done

  • Download tar package provided by Uros (one of the WeIO creator) here : http://we-io.net/downloads/ds18B20.tar
  • Import it into my WeIO
  • Modifiy main.py so that you don’t need to know ROM ID upfront and you can connect as many sensor as you want

  •  Run the code

 UART error… and hot fix !

There is still a problem with the UART. From time to time, it’ll throw some errors.

But re-running the program will work after 2 or 3 tries…

UPDATE :

The source of the problem was identified and will be fixed in upcoming release

To fix this problem, you can simply change the file : /weio/IoTPy/pyuper/ioboard.py, line 55  (a soft reset must be done after this change)

 Main sources of informations

Loading a custom device tree overlay on Ubuntu

Ok… After getting my 1-Wire temperature sensor to work (see this post), I spent hours trying to get my custom 1-wire virtual cape at boot time using uEnv.txt :

But I always get this error :

Working great from command line after booting :

Seems to be a bug in the kernel : http://hipstercircuits.com/enable-device-tree-overlay-on-startup-on-beaglebone-black/

So, quick and dirty solution (I don’t wan’t / know how to build a custom kernel…) : so I added the command into /etc/rc.local

Now it is loaded at boot time !
~

DS18B20 temperature sensor on a Beaglebone Black running ubuntu

It was quite of a challenge to make my DS18B20 to work with my BeagleBone Black on Ubuntu…

There are quite a few blogs and web sites (see below) which talks about 1-wire on BeagleBone and about Ubuntu on BeagleBone but not everything was in one place. So I thought I write this little procedure.

As you need to be root for most of those commands, you may want to open a root connection which will avoid having to type in “sudo” in front of each command :

BUT DON’T FORGET THAT YOU ARE ROOT AND YOU CAN BREAK YOUR UBUNTU !

Install Ubuntu and required package

Install Ubuntu : see this post for more details.

Install the devide tree compiler (dtc) :

Update dtc package (required on Ubuntu else you would get “dtc: invalid option — ‘@'” error) using instructions here :

Be aware that it installs a all bunch of package for building new dtc package. Also, actually, you may not need to install the dtc package as it seems Robert C. Nelson’s script is doing it for you.

Connecting the probe to the BBB

That’s simple :

  • VCC on VDD_3.3 i.e. P9.4 for instance
  • Ground on… ground i.e. P9.1 for instance
  • Data on P9.22 (that’s how we’ll configure the BeagleBone, don’t use another pin unless you know what to change in the DTS file we’ll see a bit later.)

BBB_DS18B20

Activating 1-wire

What’s interresting is that 1-wire driver is already installed in Ubuntu’s distro. To make sure it is, just try this :

But it is not associated to any pin. So first, create a device tree overlay definition for 1-wire activation (found here actually) on port P9.22 :

Then compile it and copy the compiled file to /lib/firmware :

(not sure why I had to specify the full path of dtc even though which dtc gives the correct path. May be a cache somewhere ?) Check which overlays are loaded :

Load the overlay

Check it is properly loaded :

Now you should see the device in /sys/bus/w1/devices

Almost there…

And the temperature is : 18,312°C !!!

References

I also used the following web sites / blogs to get all this to work :

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 🙂