# One-wire DS1820 thermometer with BeagleBone Black & libmicrohttpd


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.


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 */

    [email protected] {
               target = < &am33xx_pinmux >;
               __overlay__ {
                    dallas_w1_pins: pinmux_dallas_w1_pins {
                        pinctrl-single,pins = < 0x150 0x37 >;

    [email protected] {
               target = < &ocp >;
               __overlay__ {
               [email protected] {
                   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 [email protected] 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


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


The main program works the following way:

  • Program is executed in a http server mode (using libmicrohttpd)
  • The thread (which collects the data from sensors) is run and saves data to sqlite db
    (if not exists, then is created)
  • If htttp request comes, it is parsed and proper action is performed
  • 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


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