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
docs:techref:hardware:port.gpio:1-wire [2019/09/14 02:37] – [electrical Configuration] elux011docs:techref:hardware:port.gpio:1-wire [2024/09/18 09:35] (current) – [1-wire Bus] elux011
Line 4: Line 4:
 But 1-Wire devices can also be interfaced directly to Controllers from various vendors using a GPIO Pin. But 1-Wire devices can also be interfaced directly to Controllers from various vendors using a GPIO Pin.
  
-This guide will only cover 1-Wire Bus Connections because (as of Sep 13, 2019) it is the latest stable release available to Openwrt systems. The Device which got tested was a OrangePI PC+ running OpenWrt v18.06.4.+This guide will only cover 1-Wire Bus Connections  (as of Sep 13, 2019) up to the stable release v19.07.8. For newer Kernels (since v21.02.0) the Package "kmod-w1-gpio-custom" is no longer available. 
 +Therefore the Installation is a bit more extensive.   
 +The Device which got tested was a **OrangePI PC+** (a different method is recommended for the Raspberry Pi!)
  
-===== Installation =====+===== Installation up to v19.07.8=====
  
-In order to use a GPIO for the 1-Wire bus, e.g. for using [[https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf|B18S20 Sensors]] it is necessary to install several additional packages:+In order to use a GPIO for the 1-Wire bus, i.e. for using [[https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf|DS18B20 Sensors]] it is necessary to install several additional packages:
  
 <code> <code>
Line 16: Line 18:
  
  
-===== Configuration =====+===== Configuration up to v19.07.8=====
  
 Configure the GPIO pin connected to the data line of the sensor.   Configure the GPIO pin connected to the data line of the sensor.  
Line 30: Line 32:
 The last Zero of the sequence means "not open-drain" and should be set to "0". The last Zero of the sequence means "not open-drain" and should be set to "0".
  
-After modifying the file /etc/modules.d restart so that the kernel can load the modules.+After modifying the file /etc/modules.d restartso that the kernel can load the modules.
  
 When the 1-Wire bus is successfully set up, you should see in /sys/devices a directory called "w1_bus_master1". A second bus will appear as "w1_bus_master2" and so on.  When the 1-Wire bus is successfully set up, you should see in /sys/devices a directory called "w1_bus_master1". A second bus will appear as "w1_bus_master2" and so on. 
-Within this directory you will find a number of files including "w1_master_slaves_count" which shows the number of devices connected to the 1-Wire bus, and "w1_master_slaves" which contains a list of the device identifiers.+Within this directory you will find a number of files including "w1_master_slaves_count" which shows the number of detected devices connected to the 1-Wire bus, and "w1_master_slaves" which contains a list of the device identifiers.
    
 In case, it is a Sunxi Device and you like to connect e.g. Pin 29 (=PA7) [[https://linux-sunxi.org/GPIO|Sunxi]] says: In case, it is a Sunxi Device and you like to connect e.g. Pin 29 (=PA7) [[https://linux-sunxi.org/GPIO|Sunxi]] says:
Line 41: Line 43:
  
 so the GPIO for PA7 would be ( 1 - 1) * 32 + 7 = 0 + 7 = 7 (since 'a' is the first letter). so the GPIO for PA7 would be ( 1 - 1) * 32 + 7 = 0 + 7 = 7 (since 'a' is the first letter).
 +
 +(Or you take a look with
 +<code>
 +cat /sys/kernel/debug/pinctrl/1c20800.pinctrl/pins
 +</code>
 +for the mappings...)
 +
 This results in the following configuration This results in the following configuration
 <code> <code>
Line 46: Line 55:
 </code>  </code> 
  
 +===== Installation as of v21.02.0 =====
  
 +There are several possible Ways to install.
 +The Way described here assumes, that an Image has been installed on a [[docs:guide-user:installation:installation_methods:sd_card|SD card]]. 
 +
 +**This Description again refers to an Orange Pi PC+, Pin "PA3" is to be used as W1 port conected with DS18B20 Sensors.** 
 +
 +First install the necessary several additional packages:
 +
 +<code>
 +opkg update
 +opkg install kmod-w1 kmod-w1-master-gpio kmod-w1-slave-therm
 +</code>
 +
 +As of v21.02.0 the Configuration of the Driver is done via the [[docs:guide-developer:defining-firmware-partitions|Device Tree]]. 
 +On your Computer you need a Device-Tree-Compiler installed. Several Linux Distributions have it available in the Repositys.
 +
 +The Device Tree can be changed as follows:
 +  * Connect the SD Card to your Computer and look at lsblk or dmesg to identify it. In most Cases, it would be something like /dev/sdX.
 +  * Mount and open the "20M" Boot Partition.
 +  * there are 3 Files in the Partition: boot.scr, dtb, uImage
 +  * Copy the File "dtb" to your Computer
 +  * decompile
 + 
 +<code>
 +dtc dtb  -O dts -I dtb -o OPi.dts
 +</code>
 +
 +  * You get a File named "OPi.dts". Edit the File. 
 +  * Inside the Section "pinctrl@1c20800" (the selected Pin "PA3" is within this range) you have to insert 
 +
 +<code>  w1-pins {
 +        pins = "PA3";
 +        function = "gpio_out";
 +        phandle = <0x2f>;
 +    };
 +</code>
 +
 + and at the end of the file (**but before the last bracket!**) add:
 +  
 +<code>
 +w1-gpio {
 + compatible = "w1-gpio";
 + label = "w1-gpio";
 + pinctrl-names = "default";
 + pinctrl-0 = <0x2f>;
 + gpios = <0xa 0x0 0x3 0x6>;
 + status = "okay";
 + };  
 +</code>
 +Notice: 
 +  -  phandle: you have to use a hex number following the highest number of phandle used in the file.
 +  -  gpios: the "0xa" ist the phandle of the used pinctrl, the "0x0" is the used Bank (0 = A...), the "0x3" is the hex number of the used Pin inside the bank, the "0x6" ist the Configuration of the Pin.
 +
 +  * compile
 +
 +<code>
 +dtc OPi.dts  -O dtb -I dts -o dtb
 +</code>
 +
 +  * copy the new "dtb" to the SD Card (overwrite the old "dtb")
 +  * Check the output of "dmesg" for (error) messages
 +<code>
 +...
 +kern.info kernel: [    7.610839] Driver for 1-wire Dallas network protocol.
 +...
 +kern.info kernel: [    7.688174] w1_master_driver w1_bus_master1: Attaching one wire slave 28.0416a43244ff crc be
 +...
 +</code>
 +
 +         
 ===== electrical Configuration ===== ===== electrical Configuration =====
  
-To connect 1Wire Device to a Host it is necessary to connect a Pullup Resistor of 4.7 kOhm between the Bus Line and the 3.3V VCC Line. +To connect 1Wire Devices to a Host it is necessary to connect a Pullup Resistor of 4.7 kOhm between the Bus Line and the 3.3V VCC Line. 
-On the Internet, other values ​​are given also, here it works well with 4.7kOhm.+On the Internet, other values ​​are given also, here it works well with 4.7kOhm and six DS18B20 Sensors.
  
-{{http://r-ost.de/owrt/w1_wd.png?306x211}}+{{:media:doc:howtos:w1-ds18b20.png?direct}}
  
 It is also possible to operate the 1-Wire Bus with just the Gnd and Bus Lines, with the Sensors deriving power "parasitically" from the Bus Line. For further information, read the datasheet of the device. It is also possible to operate the 1-Wire Bus with just the Gnd and Bus Lines, with the Sensors deriving power "parasitically" from the Bus Line. For further information, read the datasheet of the device.
 +For longer cables, the use of an insulator such as ADUM1201 is recommended.
  
  
  • Last modified: 2019/09/14 02:37
  • by elux011