BeagleBone Black 1-Wire Temperature with Debian 8 (Jessie), Kernel 4.1.x and No Capemgr

2015-05-17

Note: There are far easier ways to get 1-wire temperature sensors working on the Beaglebone Black. If you are just starting out I strongly recommend using the official Debian distro provided at BeagleBoard.org. Stick to the 3.8.13-boneXX kernel and get your 1-wire interface working via capemgr. A good tutorial is at HipsterCircuits. This guide may be of assistance if you need to use a newer kernel which doesn’t have capemgr. I assume you are familiar with the BBB, linux and compiling software.

I bought a Beaglebone Black a few years ago and decided to resurrect it as a controller for my latest hobby - homebrewing beer. As I’m currently brewing extract and partial mash beers, the most useful improvement would be better monitoring and eventually control of the fermentation temperature.

This guide covers setting up a bleeding-edge Debian install on your Beaglebone Black, including:

Problems

Install Debian 8 (Jessie)

Grab an image from Robert C Nelson’s elinux.org. I chose the latest Debian Jessie console flasher image. This automagically flashes your board with Debian for SD-card free operation.

Write the image to an SD card using dd:

# dd bs=1M if=BBB-eMMC-flasher-debian-8.0-console-armhf-2015-05-04-2gb.img of=<the_sd_card>

Once the flash has finished (all leds on), remove SD card, turn BBB off then back on.

Login to the BBB via serial console, SSH or USB gadget.

Upgrade your kernel

# apt-get update
# apt-cache search linux-image | grep bone

Look for the latest 4.1.x-boneXX kernel and execute:

# apt-get install linux-image-4.1.x-boneXX

Reboot and make sure everything looks OK via dmesg.

Rebuilding the device tree with 1-wire support

We will be using Robert C Nelson’s dtb-rebuilder tool to rebuild our device tree without needing to recompile our kernel. The following will give us a 1wire bus on port P9.22.

$ git clone https://github.com/RobertCNelson/dtb-rebuilder.git
$ cd dtb-rebuilder
$ git checkout 4.1.x

Name the following file am335x-boneblack-minimal-1wire.dts and place it in the dtb-builder/src/arm directory. This file was created by me by studying the am335x-boneblack-replicape.dts device tree file. I cut and pasted the stuff I wanted, and removed anything that looked non-critical. 4.1.x kernel is bringing back some kind of capemgr but I couldn’t get it working, so this solution doesn’t use the capemgr at all. I think it also cuts out things like HDMI so make sure you are logged in over some kind of remote shell.

/*
 * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

/dts-v1/;

#include "am33xx.dtsi"
#include "am335x-bone-common-no-capemgr.dtsi"

/ {
        model = "TI AM335x BeagleBone Black";
        compatible = "ti,am335x-bone-black", "ti,am335x-bone", "ti,am33xx";
};

#include "am335x-boneblack-1ghz.dtsi"

&ldo3_reg {
        regulator-min-microvolt = <1800000>;
        regulator-max-microvolt = <1800000>;
        regulator-always-on;
};

&mmc1 {
        vmmc-supply = <&vmmcsd_fixed>;
};

&am33xx_pinmux {
        pinctrl-names = "default";
        pinctrl-0 = <&clkout2_pin>;
};

#include "am335x-peripheral-emmc.dtsi"
#include "am335x-bone-pinmux-emmc.dtsi"

&rtc {
        system-power-controller;
};

/* 1-WIRE YEA BOY */

/ {
        ocp {
                P9_22_pinmux {status = "disabled"; }; /* Dallas 1W */
        };
};

/ {
        onewire {
                compatible      = "w1-gpio";
                pinctrl-names   = "default";
                pinctrl-0       = <&dallas_w1_pins>;
                status          = "okay";
                gpios           = <&gpio0 2 0>;
        };
};

&am33xx_pinmux {
        dallas_w1_pins: pinmux_dallas_w1_pins {
                pinctrl-single,pins = <0x150 0x37>;
        };
};

Run make all in the dtb-rebuilder folder and copy the resulting am335x-boneblack-minimal-1wire.dtb file to /boot/dtbs/4.1.x-boneXX/. Edit your /boot/uEnv.txt file, uncomment the dtb line and change it to dtb=am335x-boneblack-minimal-1wire.dtb. Reboot your device and verify that /sys/bus/w1/ exists. If it does, then congrats!

Reading a temperature

Look in your /sys/bus/w1/devices/ folder for the folder that relates to your sensor eg 28-000004a8a972. Run:

$ cat /sys/bus/w1/devices/<your_device_id>/w1_slave
3e 01 4b 46 7f ff 02 10 6c : crc=6c YES
3e 01 4b 46 7f ff 02 10 6c t=19875

The t=19875 means the temperature is 19.875 degrees. Victory!

WiFi Setup with ConnMan

Make sure wifi adapter is detected. Check the output of dmesg for errors relating to wifi, run lsusb -v for detailed info on your wifi dongle, and check that the wireless extensions are working by running iwconfig.

Set up your wifi device using connmanctl. The below commands will get you connected to a WPA2 wireless network with a static IP.

$ connmanctl
connmanctl> enable wifi
(connmanctl will report success or failure)
connmanctl> scan wifi
(connmanctl will report success or failure)
connmanctl> services
(connmanctl will list available wifi networks and wired connections)
connmanctl> agent on
(connmanctl will report success or failure)
connmanctl> connect <wifi_service_name>
(connmanctl will prompt for WPA pre shared key)
connmanctl> config <wifi_service_name> --ipv4 manual <ip_address> <subnet_mask> <default_gateway>
connmanctl> config <wifi_service_name> --nameservers <nameserver_ip_address>
connmanctl> exit