How To Use 1-Wire

Take VIM1 as an example.

Enable 1-Wire Driver

Edit /boot/env.txt to add onewire to overlays.

e.g.

1
overlays=uart4 pwm_ao_a pwm_f i2c0 onewire

For details on overlays, please refer to how to use device tree overlays.

Uasge

Here we attach a 1-Wire device DS18B20temperature sensor to the1-Wire` bus.

Goto the driver directory:

1
2
3
khadas@Khadas:~$ cd /sys/bus/w1/devices
khadas@Khadas:/sys/bus/w1/devices$ ls
28-0119395ebf91 w1_bus_master1

You can see the node of ds18b20 is 28-0119395ebf91. Goto this directory:

1
2
3
khadas@Khadas:/sys/bus/w1/devices$ cd 28-0119395ebf91
khadas@Khadas:/sys/bus/w1/devices/28-0119395ebf91$ ls
driver id name power subsystem uevent w1_slave

Read w1_slave file will get the temperature value:

1
2
3
khadas@Khadas:/sys/bus/w1/devices/28-0119395ebf91$ cat w1_slave
b1 01 4b 46 7f ff 0c 10 d8 : crc=d8 YES
b1 01 4b 46 7f ff 0c 10 d8 t=27062

Physical pins of onewire bus:

GPIOH5 - PIN37
GPIOH5 - PIN37
GPIOH6 - PIN15