1-Wire IO Card Configuration

Using the DS2482 one wire master chips on i2c bus via the kernels w1-gpio-ds2482 driver

For this test I have hooked up a temperature sensor to the 1W ports

First Let's check the bus master devices have all been detected :

root@raspberrypi:~# i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- 0c -- -- --
10: -- -- -- -- -- -- -- -- 18 19 -- -- -- -- -- --
20: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- 2f
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- UU -- -- -- -- -- --
50: 50 51 52 53 54 55 56 57 -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

This looks good as the 1-Wire bus masters have been detected

1W bus 1 => 0x19
1W bus 0 => 0x18

Create a device tree overlay for the DS2482 chips in /root/device-tree/ds2482.dts

/dts-v1/;
/plugin/;

/ {
    compatible = "brcm,bcm2835";

    fragment@0 {
        target = <&i2c1>;
        __overlay__ {
            status = "okay";
            #address-cells = <1>;
            #size-cells = <0>;

            w1_master_0: ds2482@18 {
                compatible = "maxim,ds2482";
                reg = <0x18>;
                status = "okay";
            };

            w1_master_1: ds2482@19 {
                compatible = "maxim,ds2482";
                reg = <0x19>;
                status = "okay";
            };
        };
    };
};

Compile the overlay:

sudo dtc -@ -I dts -O dtb -o /boot/overlays/ds2482.dtbo /root/device-tree/ds2482.dts

Enable the required kernel module:

echo "w1-gpio-ds2482" | sudo tee -a /etc/modules

Add the overlay to boot config:

echo "dtoverlay=ds2482" | sudo tee -a /boot/config.txt

Reboot the unit

sudo reboot

After reboot, check your 1-Wire devices are detected:

ls /sys/bus/w1/devices/

You should see your bus masters and any connected devices, for example:

root@raspberrypi:~# ls /sys/bus/w1/devices/ -l
total 0
lrwxrwxrwx 1 root root 0 Feb  4 13:57 28-00000adde5c9 -> ../../../devices/w1_bus_master1/28-00000adde5c9
lrwxrwxrwx 1 root root 0 Feb  4 13:34 28-00000adeacb6 -> ../../../devices/w1_bus_master2/28-00000adeacb6
lrwxrwxrwx 1 root root 0 Feb  4 13:20 w1_bus_master1 -> ../../../devices/w1_bus_master1
lrwxrwxrwx 1 root root 0 Feb  4 13:20 w1_bus_master2 -> ../../../devices/w1_bus_master2

To read the temperature from a DS18B20 sensor:

cat /sys/bus/w1/devices/28-00000adeacb6/temperature
27750    # This equals 27.75°C

To trigger a new bus scan for newly connected devices:

echo 1 > /sys/bus/w1/devices/w1_bus_master1/w1_master_search
echo 1 > /sys/bus/w1/devices/w1_bus_master2/w1_master_search

Note that this kernel-based approach is more reliable than OWFS and doesn't require any additional services to be running.

Contact us now to discuss your project

Ready to order, contact us today for pricing or samples

Contact Us