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 will explain how to use 1-Wire on Khadas SBC. You will learn how to turn it on and how to get sensor data through 1-Wire.

Enable 1-Wire

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

e.g.

overlays=uart4 pwm_ao_a pwm_f i2c0 onewire

Reboot to effect.

For details on overlays, please refer to Device Tree Overlay.

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

GPIOH_5 - PIN37

VIM2

GPIOH_5 - PIN37

VIM3/3L

GPIOH_6 - PIN15

Edge1

GPIO4_A0 - PIN30

VIM4

GPIOT_19 - PIN37

Last modified: 2022/07/05 04:49 by frank