参考(抄袭)资料在这里
先接线,3.3v,gnd,数据输出脚,我是PG11
vim /boot/armbianEnv.txt
overlays=w1-gpio
param_w1_pin=PG11
param_w1_pin_int_pullup=
vim /etc/modules-load.d/modules.conf
w1-gpio
w1-therm
cd /sys/bus/w1/devices,ls能看到一个带数字的设备,里面有一个w1-slave文件,这个里面包含温度信息
golang代码参考这里
package main import (
"fmt"
"github.com/yryz/ds18b20"
"time"
) func main() {
sensors, err := ds18b20.Sensors()
if err != nil {
panic(err)
} fmt.Printf("sensor IDs: %v\n", sensors) for{
for _, sensor := range sensors {
t, err := ds18b20.Temperature(sensor)
if err == nil {
fmt.Printf("sensor: %s temperature: %.2f°C\n", sensor, t)
}
}
time.Sleep( * time.Second )
}
}