One-wire on Raspberry Pi with FreeBSD 11

One new thing arriving in the FreeBSD 11 is a support for 1-Wire devices.
To check it I used Raspberry Pi Model B and DS18B20 temperature sensors.

Here is a description how to work with it.

Checking DS18B20

Before trying to connect new devices to Raspberry Pi with FreeBSD it’s a good idea to check that this devices work.

Let’s connect this temperature sensor to the Arduino first. On the next pictures we can see a connection of the DS18B20 to the Arduino:

uno-ds18b20

SDIM2217

I connected Data pin from DS18B20 to digital pin 10 on Arduino, Vdd pin to +5V, GND to GND and put 4k7 resistor between Data and Vdd pins.

To work with 1-wire in Arduino we need to install OneWire library. We can do it from Arduino IDE. After that we can load example sketch “DS18x20_Temperature”.

On the next picture we can see the result:

arduino-ds18b20.png

We can see chip name, id and current temperature. It works!

Connecting DS18B20 to the Raspberry Pi

FreeBSD supports for 1-Wire hardware through GPIO. FreeBSD doesn’t support “parasite power” mode for DS18B20 sensors. This mean that we should powered it by an external supply on the VDD pin. But GPIO pins in the Raspberry Pi are 3V3 not 5V like Arduino. That’s why we should connect Vdd pin to 3v3, not to 5V.

On the next pictures we can see a connection of the DS18B20 to the Raspberry Pi:

pi-ds18b20_bb

I connected Data pin from DS18B20 to pin 4 on Raspberry Pi, Vdd pin to +3V3, GND to GND and put 4k7 resistor between Data and Vdd pins.

How to setup software

Physical connection is a small part of the deal. We need to setup software. But the first step is getting source code. After that we can change kernel config and FDT description.

Changing FDT

For Raspberry Pi Model B we need to modify file /usr/src/sys/boot/fdt/dts/arm/rpi.dts:

rpi_dts

4 in the third string is a number of pin we will use for connecting 1-wire devices.

After changing this file we need to build and install new FDT file:

make-dtb

Changing kernel

For Raspberry Pi Model B we need to modify kernel file /usr/src/sys/arm/conf/RPI-B:

rpi-b

We need to add devices owcow and ow_temp into our kernel.

After that we can compile and install new kernel:

kern.build

make-installkernel1

Checking the result

After reboot we can check the result.

dmesg.ow.temp

We see  our devices. System detected our DS18B20 sensor and added device for it.
Without 1-wire devices connected or with incorrectly connected we can see other result:

dmesg-nowire

Working with the sensor

To get information from the sensor we should use sysctl utility:

sysctl.ow.temp.png

When we connect two sensor to our one-wire bus we will see them both:

sysctl.2.ow.temp

The Raspberry Pi Model B with two DS18B20 connected to it is on the next picture:

SDIM0088

That’s all folks!

 

 

Advertisements

16 thoughts on “One-wire on Raspberry Pi with FreeBSD 11

  1. Vadim, thanks for a great tutorial. I have a Raspberry Pi 2 so the files & environmental variables are a little different. Here’s what I did to get it working on a Pi 2.

    1) update source
    svn update /usr/src
    2) modify /usr/src/sys/boot/fdt/dts/arm/rpi2.dts using Vadim’s instructions
    3) make new RPI2dts file
    cd /usr/src
    setenv MACHINE arm
    ./make_dtb.sh /usr/src/sys /usr/src/sys/boot/fdt/dts/arm/rpi2.dts .
    cp /boot/msdos/rpi2.dtb /boot/msdos/rpi2dtb.old
    cp rpi2.dtb /boot/msdos
    4) modify /usr/src/sys/arm/conf/RPI2 using Vadim’s instructions
    5) build/install new kernel
    setenv ARCH armv6
    make buildkernel KERNCONF=RPI2
    cp -r /boot/kernel /boot/kernel.old
    make installkernel KERNCONF=RPI2
    6) reboot to new kernel (success!)
    7) check dmesg output

  2. Hi Vadim. Is it possible, to get this temperature data another way, but dmesg, on RPI 2B? May be something like digitemp? I think that dmesg is easy, but not handly. Thanks!

  3. You can do this a little more simply. Once you edit your rpi.dts or rpi2.dts file, rebuld the rpi dtb module:

    cd sys/modules/dtb/rpi
    make
    sudo make install
    sudo cp /boot/dtb/rpi*.dtb /msdos

    then update your loader.conf file:

    echo ‘load_ow=”yes”‘ >> /boot/loader.conf
    echo ‘load_owc=”yes”‘ >> /boot/loader.conf
    echo ‘load_ow_temp=”yes”‘ >> /boot/loader.conf

    then reboot. While you can kldload the kernel modules any time, you have to reboot for the dtb change to take effect.

    sudo reboot

    Glad it is working out for you. My own temperature network in the house over the old phone lines project has stalled due to higher household priorities…

    • Thank you! Your solution is very good for released systems.
      But FreeBSD 11 is not released yet. Its source code and behavior change very often.
      That’s why I prefer to completely rebuild a kernel in it.

  4. I heard that minimal pull up resistor for Rpi is 1.2k, can you advice me with this question ? I was trying to connect about 150m 1-wire on Rpi without additional power source for 2 months. Is it possible just with Rpi 3.3v?

    • FreeBSD doesn’t support parasitic mode for the temperature sensor: “Strong pull-up functionality needed to support parasitic mode is not
      implemented.”
      I think this can be a problem for your situation.

  5. I saw an example where there was no DTS manipulation but all was done via loader:

    —– loader.conf —–
    . . . . . .
    hint.gpio_ow.0.pin=4
    load_ow=”yes”
    load_owc=”yes”
    load_ow_temp=”yes”
    . . . . . .

    I haven’t 18b20 right now to check whether this trick is work or no, but it would be very pleasant.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s