GithubHelp home page GithubHelp logo

airenas / ds18b20 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yryz/ds18b20

0.0 0.0 0.0 11 KB

Golang get temperature from ds18b20 sensor connected to a Raspberry PI (GPIO w1 pin).

License: Apache License 2.0

Go 100.00%

ds18b20's Introduction

ds18b20

Get sensor data from ds18b20 connected to the Raspberry (GPIO w1 pin). The sensor has possibility to retry reading on a failure.

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/airenas/ds18b20

Code

package main

import (
    "fmt"

    "github.com/airenas/ds18b20"
)

func main() {
    sensors, err := ds18b20.SensorIDs()
    if err != nil {
        panic(err)
    }

    fmt.Printf("sensor IDs: %v\n", sensors)

    for _, sID := range sensors {
        s, err := ds18b20.NewSensorR(sID, 3)
        if err != nil {
            panic(err)
        }
        t, err := s.Temperature()
        if err != nil {
            panic(err)
        } 
        fmt.Printf("sensor: %s temperature: %.2f\n", sID, t)
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.