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