Page 1 of 1

DS18B20 one wire

Posted: Wed Feb 14, 2018 7:56 am
by ad7zj
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?

Re: DS18B20 one wire

Posted: Mon Feb 19, 2018 12:47 am
by Vonger
Set the pin's pinmux to GPIO first.then it should work

Re: DS18B20 one wire

Posted: Thu Mar 01, 2018 6:52 am
by ad7zj
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
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

Re: DS18B20 one wire

Posted: Wed Oct 24, 2018 5:29 pm
by GuiBacon
Hi....You cannot physically connect them directly. You need to use a 1-Wire to RS232 adapter.
The adapter will have a manual that describes how RS232 commands correspond to 1-Wire commands. You also need to read the manual for the temperature sensor to see what commands you need to use and how the data is formatted.
For an experienced programming, it would be two full days of work.

turnkey pcb

Re: DS18B20 one wire

Posted: Fri Oct 26, 2018 11:32 pm
by ad7zj
They can be directly connected using the w1 driver as I described above. What you describe is another way that should also work.