1-wire Bus

To provide 1-Wire Bus Connections between various 1-Wire- and Hostdevices different connection methods can be used. They can be connected to a Host using a bus converter. USB, RS-232 serial port interfaces are popular solutions for connecting 1-Wire Devices to the Hostdevice. 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.

In order to use a GPIO for the 1-Wire bus, i.e. for using DS18B20 Sensors it is necessary to install several additional packages:

opkg update
opkg install kmod-w1 kmod-w1-master-gpio kmod-w1-gpio-custom kmod-w1-slave-therm

Configure the GPIO pin connected to the data line of the sensor. The Section “Software” in this howto describes how to determine the GPIO.

Create/Edit /etc/modules.d/55-w1-gpio-custom, replace 19 with the GPIO which you determined in the last step. You can include several bus definitions up to a maximum of four, i.e.:

echo "w1-gpio-custom bus0=0,19,0 bus1=1,20,0" > /etc/modules.d/55-w1-gpio-custom

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.

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.

In case, it is a Sunxi Device and you like to connect e.g. Pin 29 (=PA7) Sunxi says:

(position of letter in alphabet - 1) * 32 + pin number

so the GPIO for PA7 would be ( 1 - 1) * 32 + 7 = 0 + 7 = 7 (since 'a' is the first letter). This results in the following configuration

echo "w1-gpio-custom bus0=0,7,0" > /etc/modules.d/55-w1-gpio-custom

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 and six DS18B20 Sensors.

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.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
  • Last modified: 2019/09/20 03:21
  • by elux011