Khadas Docs

Amazing Khadas, always amazes you!

User Tools

Site Tools


Sidebar

products:sbc:common:applications:gpio:1wire

This is an old revision of the document!


1-Wire

Introduction

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

1-Wire Information

I2C PIN & GPIO(#number) DT Overlays Node Bus Number Device Node
VIM1/2 I2C A SCL(22) - GPIODV_25 (#474)
SDA (23) - GPIODV_24 (#473)
i2c0 0 /dev/i2c-0
I2C B SCL(25) - GPIODV_27 (#476)
SDA(26) - GPIODV_26 (#475)
- 1 /dev/i2c-1
VIM3/3L I2CM 3 SCL(22) - GPIOA_15 (#475)
SDA(23) - GPIOA_14 (#474)
i2c3 3 /dev/i2c-3
I2C AO SCL(25) - GPIOAO_2 (#498)
SDA(26) - GPIOAO_3 (#499)
- 4 /dev/i2c-4
VIM4 I2CM F SCL(22) - GPIOY_17 (#501)
SDA (23) - GPIOY_18 (#502)
i2cm_f 5 /dev/i2c-5
I2CM A SCL(25) - GPIOT_20 (#466)
SDA(26) - GPIOT_21 (#467)
i2cm_a 0 /dev/i2c-0

Enable 1-Wire Bus

You can enable 1-Wire bus via Device Tree Overlay.

VIM1/2/3/3L/Edge1

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

e.g.

overlays=uart4 pwm_ao_a pwm_f i2c0 onewire

VIM4

Edit /boot/dtb/amlogic/kvim4.dtb.overlay.env to add onewire to fdt_overlays node.

e.g.

fdt_overlays=onewire

Reboot to 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

Physical pins of 1-Wire bus:

VIM1/2

GPIOH_5 - PIN37

VIM3/3L

GPIOH_6 - PIN15

VIM4

GPIOT_19 - PIN37

Edge1

GPIO4_A0 - PIN30

Last modified: 2022/07/12 23:20 by nick