DS18B20 one wire

ad7zj
 
Posts: 6
Joined: Tue Dec 01, 2015 5:10 am

DS18B20 one wire

Wed Feb 14, 2018 7:56 am

Has anyone gotten one wire sensors like the DS18B20 temperature sensor working? I've installed the kmod-w1, kmod-w1-gpio-custom and kmod-w1-slave-therm packages. I'm running the 15.05 CC release. What pin should the sensor be connected to? I saw GPIO0 mentioned somewhere else on this forum, but I don't see anything in /sys/bus/w1/devices.

root@OpenWrt:~# lsmod | grep w1
w1_gpio 2112 0
w1_therm 2000 0
wire 14528 2 w1_therm

Any thoughts?

Vonger
 
Posts: 622
Joined: Sun Oct 19, 2014 6:00 am

Re: DS18B20 one wire

Mon Feb 19, 2018 12:47 am

Set the pin's pinmux to GPIO first.then it should work

ad7zj
 
Posts: 6
Joined: Tue Dec 01, 2015 5:10 am

Re: DS18B20 one wire

Thu Mar 01, 2018 6:52 am

The problem is the w1 driver doesn't have a pin assigned in the stock image. Theoretically you could use the w1-gpio-custom module to select a pin at runtime, but this didn't work - I believe the reason is because all the GPIOs are currently assigned to the gpio-export driver.

My solution was to modify the device tree file, removing GPIO12 from the gpio-export section and adding a section for w1-gpio. I think any unused GPIO should work as well: (note I'm working with LEDE 17.01.4)
Code: Select all
diff --git a/target/linux/ramips/dts/VOCORE.dtsi b/target/linux/ramips/dts/VOCORE.dtsi
index 36f784a..a62c19b 100644
--- a/target/linux/ramips/dts/VOCORE.dtsi
+++ b/target/linux/ramips/dts/VOCORE.dtsi
@@ -35,13 +35,6 @@
                        gpios = <&gpio0 9 0>;
                };
 
-               gpio12 {
-                       /* UARTF_DCD_N */
-                       gpio-export,name = "gpio12";
-                       gpio-export,direction_may_change = <1>;
-                       gpios = <&gpio0 12 0>;
-               };
-
                gpio13 {
                        /* UARTF_DSR_N */
                        gpio-export,name = "gpio13";
@@ -144,6 +137,11 @@
                        gpios = <&gpio0 11 0>;
                };
        };
+
+       w1-device {
+               compatible = "w1-gpio";
+               gpios = <&gpio0 12 0>;
+       };
 };
 
 &gpio1 {


This does require rebuilding the whole OS image. I started with LEDE 17.01.4. Build like you normally would, and also select kmod-w1, kmod-w1-master-gpio, and kmod-w1-slave-therm under Kernel Modules -> W1 Support. Build them as modules and then install them once the system is up and running.

I have had a DS18B20 sensor connected for about a week now and it's been working great.

Simple bash script for reading the one wire device:
Code: Select all
#!/bin/ash
tempMilliC=$(cat /sys/devices/w1_bus_master1/28-0516869c47ff/w1_slave | grep  -E -o ".{0,0}t=.{0,5}" | cut -c 3-)

let "tempMilliF = ((tempMilliC * 9)/5 + 32000)"
let "tempF = $tempMilliF/1000"
let "tempFtenth = $tempMilliF%1000"
echo "Temp milliF: $tempMilliF"
echo "{\"temperature\":$tempF.$tempFtenth}" > telemetry-data.json

Return to VoCore & VoCore+dock

Who is online

Users browsing this forum: No registered users and 0 guests