ds18b20

package module
v0.0.0-...-4a8f84b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2020 License: Apache-2.0 Imports: 4 Imported by: 30 modules, 27 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

ds18b20

Get sensor data from ds18b20 connected to the Raspberry (GPIO w1 pin).

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
package main

import (
    "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)
        }
    }
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrReadSensor = errors.New("failed to read sensor temperature")

Functions

func Sensors

func Sensors() ([]string, error)

Sensors get all connected sensor IDs as array

func Temperature

func Temperature(sensor string) (float64, error)

Temperature get the temperature of a given sensor

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址