Khadas Docs

Amazing Khadas, always amazes you!

User Tools

Site Tools


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

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
products:sbc:common:applications:gpio:1wire [2022/07/04 22:33]
hyphop [Get sensor data]
products:sbc:common:applications:gpio:1wire [2023/11/07 04:59] (current)
nick old revision restored (2023/11/07 04:42)
Line 3: Line 3:
 ===== Introduction ===== ===== 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.+This page introduces the usage of 1-Wire bus on [[products:sbc:common:applications:gpio:40pin-header|40-Pin Header]].
  
-===== Enable 1-Wire =====+===== 1-Wire Information =====
  
-Edit ''/boot/env.txt'' to add onewire to overlays.+You can find the default PIN used for ''1-Wire'' bus from the table below.
  
-e.g+|            PIN  ^  GPIO Name  ^  DT Overlays Node  ^  Device Node          ^ 
-```sh +^  VIM1/   37    GPIOH_5    |  onewire            /sys/bus/w1/devices 
-overlays=uart4 pwm_ao_a pwm_f i2c0 onewire+^  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 [[products:sbc:common:configurations:device-tree-overlay|Device Tree Overlay]]. 
 + 
 +<tabbox 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. 
 + 
 +```shell 
 +overlays=onewire
 ``` ```
-Reboot to effect.+<tabbox VIM3 with 5.15 kernel>
  
-<WRAP info > +Edit ''/boot/dtb/amlogic/kvim3.dtb.overlay.env'' to add onewire node to ''fdt_overlays'' node if it doesn't exist.
-For details on overlays, please refer to [[products:sbc:vim4:configurations:device-tree-overlay|Device Tree Overlay]]. +
-</WRAP>+
  
-===== Get sensor data ===== 
  
-<tabbox VIM1>  +e.g. To enable onewire, you need to add ''onewire'' to node ''fdt_overlays'' if it doesn't exist.
-**header**+
  
-''GPIOH5'' - PIN37 +```shell 
-<tabbox VIM2>  +fdt_overlays=onewire 
-''GPIOH5'' - PIN37 + 
-<tabbox VIM3/3L>  +``` 
-''GPIOH6'' - PIN15 + 
-<tabbox Edge1> +<tabbox VIM3L with 5.15 kernel> 
-''GPIO4_A0'' - PIN30 + 
-<tabbox VIM4>  +Edit ''/boot/dtb/amlogic/kvim3l.dtb.overlay.env'' to add onewire node to ''fdt_overlays'' node if it doesn't exist. 
-''GPIOT19'' - PIN37+ 
 + 
 +e.g. To enable onewire, you need to add ''onewire'' to node ''fdt_overlays'' if it doesn't exist. 
 + 
 +```shell 
 +fdt_overlays=onewire 
 + 
 +``` 
 + 
 +<tabbox 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. 
 + 
 +```shell 
 +fdt_overlays=onewire 
 + 
 +``` 
 +<tabbox 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. 
 + 
 +```shell 
 +fdt_overlays=onewire 
 + 
 +```
 </tabbox> </tabbox>
 +
 +<WRAP tip >
 +Reboot the system for this change to take effect.
 +</WRAP>
 +
 +
 +===== Get Sensor Data =====
  
 Here we attach a 1-Wire device ''DS18B20'' temperature sensor to the 1-Wire bus. Here we attach a 1-Wire device ''DS18B20'' temperature sensor to the 1-Wire bus.
  
-  * Enter the driver directory: +Enter the driver directory: 
-```sh+```shell
 khadas@Khadas:~$ cd /sys/bus/w1/devices khadas@Khadas:~$ cd /sys/bus/w1/devices
 khadas@Khadas:/sys/bus/w1/devices$ ls khadas@Khadas:/sys/bus/w1/devices$ ls
Line 44: Line 94:
 ``` ```
  
-  * You can see the node of ''ds18b20'' is ''28-0119395ebf91''. Enter this directory: +You can see the node of ''ds18b20'' is ''28-0119395ebf91''. Enter this directory: 
-```sh+```shell
 khadas@Khadas:/sys/bus/w1/devices$ cd 28-0119395ebf91 khadas@Khadas:/sys/bus/w1/devices$ cd 28-0119395ebf91
 khadas@Khadas:/sys/bus/w1/devices/28-0119395ebf91$ ls khadas@Khadas:/sys/bus/w1/devices/28-0119395ebf91$ ls
Line 51: Line 101:
 ``` ```
  
-  * Read ''w1_slave'' file will get the temperature value: +Read ''w1_slave'' file will get the temperature value: 
-```sh+```shell
 khadas@Khadas:/sys/bus/w1/devices/28-0119395ebf91$ cat w1_slave 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 : crc=d8 YES
Line 58: Line 108:
 ``` ```
  
-  * Physical pins of 1-Wire bus: 
  
 +===== 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 [[products:sbc:common:configurations:device-tree-overlay|Device Tree Overlay]]. 
Last modified: 2022/07/04 22:33 by hyphop