How to configure 1-Wire support
I want to port my little 1-Wire based temperature sensor app over from my RPi.
I have a DS18B20 temp sensor connected to the GPIO connector of my Raspberry Pi 3.
I used the steps of this Adafruit lesson to get things working;
https://learn.adafruit.com/adafruits-raspberry-pi-lesson-11-ds18b20-temperature-sensing/overview
How can I do the same on the ROC-RK3328-CC?
I've built a kernel with the W1 drivers "compiled in" (as opposed to compiled as modules).
After rebooting the new kernel, I see the W1 drivers in /sys/bus/w1/drivers
.
But, despite having a DS18B20 connected to the GPIO header:
pin-1 = +3.3v
pin-6 = GND
pin-7 = CLK
I do not see the sensor under /sys/bus/w1/devices
like I do on the RPi.
I suspect this has something to do with the Device Tree.
On the RPi I can tell the bootloader to add a DT Overlay (w1-gpio) by adding dtoverlay=w1-gpio
to the /boot/config.txt
file.
Near as I can tell, we don't have a similar ability to incorporate DT Overlays at boot time on the roc-rk3328-cc, right?
So, I'm guessing the GPIO pin's signal isn't being correctly routed (or made visible to) the W1 kernel driver. And to do so, will probably require some sort of modification to the kernel/arch/arm64/boot/dts/rockchip/rk3328-roc-cc.dts
.
Anybody gotten 1-Wire support working on this board?
Any Device Tree guru's out there that know what mods have to be made to the Device Tree (.dts) files?
Comments
I was ultimately able to get things working.
As I suspected, the Device Tree needed to be tweaked to define the mapping of GPIO header pin -to- CPU GPIO port.
I decided to take a crack at making the necessary changes to the Device Tree. Much to my amazement, it works!
DT code is confusing, and not very well documented.
Here is a link to my customized rk3328-roc-cc.dts incase others are interested;
https://gist.github.com/pdfruth/099f3ecf93530bf8dbd355a969e3ba78
Although it took a couple days to research, and countless trial & error tests, the code changes were ultimately pretty short-n-sweet. The changes all come down to these two new blocks of code;
.....
onewire {
compatible = "w1-gpio";
gpios = <&gpio1 28 GPIO_ACTIVE_HIGH>; /* GPIO1_D4 */
pinctrl-names = "default";
pinctrl-0 = <&rk3328_w1_pin>;
};
.....
w1 {
rk3328_w1_pin: rk3328-w1-pin {
rockchip,pins = <1 28 RK_FUNC_GPIO &pcfg_pull_none>;
};
};
.....
To use it, simply download it and copy it to
kernel/arch/arm64/boot/dts/rockchip
replacing the existing file. Then rebuild the kernel [*1]Once in place, you can follow the Adafruit 1-Wire temperature sensor tutorial for RPi almost step-by-step (see my opening post).
I was able to install nodejs and then run this simple Javascript without any trouble at all. It "Just worked";
filename = ds18b20-test.js
------ snip ------
var sensor = require('ds18x20');
var moment = require('moment');
var now = moment().format("YYYY-MM-DDTHH:mm:ss.SSSZZ");
console.log("now " + now);
var listOfDeviceIds = sensor.list();
console.log("DeviceId[0] = " + listOfDeviceIds);
var ctemp = sensor.get( listOfDeviceIds[0] );
var ftemp = ((ctemp * 9) / 5) + 32;
console.log("Current temp in F: " + ftemp);
------ snip ------
Output;
[*1] There's plenty of good guidance on building a kernel at; http://wiki.t-firefly.com/ROC-RK3328-CC/linux_compile_firmware.html#compiling-kernel
Great documentation! Can you point me to documentation on header pin 7 mapping to chip 1 GPIO 28?
I get it: D4 ==> (8*3 + 4) ==> 28