Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yryz/ds18b20
Golang get temperature from ds18b20 sensor connected to a Raspberry PI (GPIO w1 pin).
https://github.com/yryz/ds18b20
ds18b20 golang raspberry raspberry-pi temperature-sensor
Last synced: about 1 month ago
JSON representation
Golang get temperature from ds18b20 sensor connected to a Raspberry PI (GPIO w1 pin).
- Host: GitHub
- URL: https://github.com/yryz/ds18b20
- Owner: yryz
- License: apache-2.0
- Created: 2016-05-22T05:45:46.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-05-27T15:44:35.000Z (over 4 years ago)
- Last Synced: 2024-09-29T00:44:22.261Z (about 2 months ago)
- Topics: ds18b20, golang, raspberry, raspberry-pi, temperature-sensor
- Language: Go
- Homepage:
- Size: 37.1 KB
- Stars: 64
- Watchers: 3
- Forks: 12
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ds18b20
Get sensor data from ds18b20 connected to the Raspberry (GPIO w1 pin).
![](https://raw.githubusercontent.com/yryz/ds18b20/master/pi-ds18b20.png)
## Usage
### Connect DS18B20
On the Raspberry Pi, you will need to add `dtoverlay=w1-gpio"` (for regular connection) or `dtoverlay=w1-gpio,pullup="y"` (for parasitic connection) to your /boot/config.txt. The default data pin is GPIO4 (RaspPi connector pin 7), but that can be changed from 4 to `x` with `dtoverlay=w1-gpio,gpiopin=x`.Here's what I did:
```
sudo echo dtoverlay=w1-gpio-pullup,gpiopin=4 >> /boot/config.txt
sudo modprobe w1_gpio && sudo modprobe w1_therm
```### Drivers
1-Wire drivers need to be loaded in order to create the connection between the physical sensor and the rPI.
You can load them from the terminal (or from the bin/modules.sh script).sudo modprobe wire
sudo modprobe w1-gpio
sudo modprobe w1-therm### Install
go get github.com/yryz/ds18b20### Code
```go
package mainimport (
"fmt""github.com/yryz/ds18b20"
)func main() {
sensors, err := ds18b20.Sensors()
if err != nil {
panic(err)
}fmt.Printf("sensor IDs: %v\n", sensors)
for _, sensor := range sensors {
t, err := ds18b20.Temperature(sensor)
if err == nil {
fmt.Printf("sensor: %s temperature: %.2f°C\n", sensor, t)
}
}
}
```