This is an old revision of the document!
This document mainly introduces the usage of 1-Wire bus on 40-Pin Header.
You can find the default PIN used for 1-Wire bus from the table below.
PIN | GPIO(#number) | DT Overlays Node | Device Node | |
---|---|---|---|---|
VIM1/2 | 37 | GPIOH_5(#421) | onewire | /sys/bus/w1/devices |
VIM3/3L | 15 | GPIOH_6(#433) | ||
VIM4 | ||||
Edge1 | 30 | GPIO4_A0 |
In order to use the 1-Wire, you need to enable the 1-Wire function via Device Tree Overlay.
Edit /boot/env.txt
to add the onewire node to overlays
node if it doesn't exist.
Take VIM3 as an example to enable 1-Wire, you need to add onewire
node to overlays
node if it doesn't exist.
overlays=onewire
Edit /boot/dtb/amlogic/kvim4.dtb.overlay.env
to add onewire node to fdt_overlays
node if it doesn't exist.
e.g. Enable onewire, you need to add onewire
to node fdt_overlays
if it doesn't exist.
fdt_overlays=onewire
Reboot to effect.
If you want to use normal GPIO instead of 1-Wire, you can remove the 1-Wire node in device tree overlays configration file.
Here we attach a 1-Wire device DS18B20
temperature sensor to the 1-Wire bus.
Enter the driver directory:
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
. Enter this directory:
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:
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