#One-wire DS1820 thermometer with BeagleBone Black & libmicrohttpd

0. List of contents

1. Preface

Some time ago I’d an opportunity to play around with BBB. The program presented in this article is collecting data from DS18B20 sensors and stores them in sqlite database. Data is accessible via http (jQuery mobile). I was in hurry while writing the code, so article’s content might seem a bit messy. Additionally you may set an alarm, whenever temperature exceeds defined boundaries you’ll be notified by email.

2. Requirements

3. DTBO, w1 driver

Reading data is handled by “w1” kernel module. In order to load that module with proper configuration I have used the device tree structure available in linux kernel from the version 3.8. as below:


/ {
	compatible = "ti,beaglebone", "ti,beaglebone-black";
	part-number = "BB-W1";
	version = "00A0"; 

	/* state the resources this cape uses */
	exclusive-use =
		/* the pin header uses */
		/* the hardware IP uses */

	fragment@0 {
               target = <&am33xx_pinmux>;
               __overlay__ {
					dallas_w1_pins: pinmux_dallas_w1_pins {
						pinctrl-single,pins = < 0x150 0x37 >;

	fragment@1 {
               target = <&ocp>;
               __overlay__ {
		       onewire@0 {
			       compatible      = "w1-gpio";
			       pinctrl-names   = "default";
			       pinctrl-0       = <&dallas_w1_pins>;
			       status          = "okay"; 

			       gpios = <&gpio1 2 0>;

That configuration was compiled to dtbo object which is loaded as kernel module, commands:

dtc -O dtb -o BB-W1-00A0.dtbo -b 0 -@ BB-W1-00A0.dts 
cp BB-W1-00A0.dtbo /lib/firmware/ 
echo BB-W1:00A0 > /sys/devices/bone_capemgr.9/slots 

You may check your configuration by executing:

cat /sys/bus/w1/devices/DEVICE_ID/w1_slave

4. Wiring

The picture below presents how to wire aith arduino, but the same schema may be applied to beaglebone black. We just connect to specified GPIO port (i.e P9.22).
Pictures below show how I did it:

IMG_20140111_163544 IMG_20140111_163534
IMG_20140111_163510 IMG_20140111_163319

4. Server

The main program works the followind way:

  1. Program is executed in a http server mode (using libmicrohttpd)
  2. The thread (which collects the data from sensors) is run and saves data to sqlite db
    (if not exists, then is created)
  3. If htttp request comes, it is parsed and proper action is performed
  4. If sensor will notice temperature out of bound then the mail is sent to the user. (via msmtp)

Built-in http server also handles images, js, css, html files.
Current data are update via post request (every 2 seconds is sent from the client – polling).

Click to see source code

5. Frontend

Frontend is fairly simple. Just open your browser on address pointing to your BBB and you’re done.

desktop2 desktop1
android android1


  1. Hi Mateusz,
    Can you supply the actual web pages that will work with the sqlite data base?
    The ones in the developement tree have hard-coded values in them. I assume that there are version that get processed somehow in Http.c and the values get replaced with the current ones? I assume too that it will involve changes to the Http.c file as well. Thanks!

Leave a Comment.