Khadas Docs

Amazing Khadas, always amazes you!

User Tools

Site Tools


Sidebar

products:sbc:vim4:applications:gpio:1wire

VIM4 1-Wire Bus

Introduction

This page introduces the usage of 1-Wire bus on 40-Pin Header.

1-Wire Information

You can find the default PIN used for 1-Wire bus from the table below.

PIN GPIO Name DT Overlays Node Device Node
VIM1/2 37 GPIOH_5 onewire /sys/bus/w1/devices
VIM3/3L 15 GPIOH_6
VIM4 37 GPIOT_19
VIM1S 36 GPIOZ_8
Edge1 30 GPIO4_A0

Enable 1-Wire Bus

In order to use the 1-Wire, you need to enable the 1-Wire function via Device Tree Overlay.

VIM1/2/3/3L/Edge1

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

VIM3 with 5.15 kernel

Edit /boot/dtb/amlogic/kvim3.dtb.overlay.env to add onewire node to fdt_overlays node if it doesn't exist.

e.g. To enable onewire, you need to add onewire to node fdt_overlays if it doesn't exist.

fdt_overlays=onewire

VIM3L with 5.15 kernel

Edit /boot/dtb/amlogic/kvim3l.dtb.overlay.env to add onewire node to fdt_overlays node if it doesn't exist.

e.g. To enable onewire, you need to add onewire to node fdt_overlays if it doesn't exist.

fdt_overlays=onewire

VIM4

Edit /boot/dtb/amlogic/kvim4.dtb.overlay.env to add onewire node to fdt_overlays node if it doesn't exist.

e.g. To enable onewire, you need to add onewire to node fdt_overlays if it doesn't exist.

fdt_overlays=onewire

VIM1S

Edit /boot/dtb/amlogic/kvim1s.dtb.overlay.env to add onewire node to fdt_overlays node if it doesn't exist.

e.g. To enable onewire, you need to add onewire to node fdt_overlays if it doesn't exist.

fdt_overlays=onewire

Reboot the system for this change to take effect.

Get Sensor Data

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

Disable 1-Wire to Use GPIO

If you want to use normal GPIO instead of 1-Wire, you can remove the 1-Wire node in Device Tree Overlay.

2022/06/29 09:38
Last modified: 2022/09/19 04:40 by nick