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?
DS18B20 one wire
- Vonger
- Posts: 885
- Joined: Sun Oct 19, 2014 6:00 am
Re: DS18B20 one wire
Set the pin's pinmux to GPIO first.then it should work
- ad7zj
- Posts: 16
- Joined: Tue Dec 01, 2015 5:10 am
Re: DS18B20 one wire
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)
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:
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
- GuiBacon
- Posts: 1
- Joined: Wed Oct 24, 2018 5:05 pm
Re: DS18B20 one wire
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
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
Last edited by GuiBacon on Wed Mar 16, 2022 9:26 pm, edited 2 times in total.
- ad7zj
- Posts: 16
- Joined: Tue Dec 01, 2015 5:10 am
Re: DS18B20 one wire
They can be directly connected using the w1 driver as I described above. What you describe is another way that should also work.
5 posts
Page 1 of 1
Who is online
Users browsing this forum: No registered users and 2 guests