Giter Club home page Giter Club logo

hx711-1's Introduction

Reading from an hx711 24-Bit ADC on a Raspberry Pi in Golang

This is based off https://github.com/rajmaniar/hx711 it extends the implementation by adding the ability to tare and calibrate the device. It's non-opinionated about the units that you are converting e.g. grams, pounds etc.

The HX711Attributes struct is introduced to handle keeping track of known device attribute data.

Both the tare and calibration use the median of the numberOfReadings retrieved because there are situations where a reading from the load cell can be a large spike which could throw off an average.

To tare the device you can use Tare(numberOfReadings int). To calibrate the device you can use Calibrate(numberOfReadings int, knownWeight float64).

Example:

import "github.com/rajmaniar/hx711"

func main() {
    
    clock := "gpio23"
    data := "gpio24"
    
    // existing attributes are known
    attributes := &HX711.Attributes{Tare: 1000, CalibratedReading: 2000, CalibratedWeight: 1500}
    
    h,err := hx711.NewWithKnownAttributes(data, clock)
    
    if err != nil {
        fmt.Printf("Error: %v",err)
    }
    
    for err == nil {
        var data int32
    
        // returns the reading based on the calibration attributes
        data, err = h.ReadCalibratedData()
        fmt.Printf("Read from HX711: %v\n",data)
        time.Sleep(250 * time.Millisecond)
    }
    fmt.Printf("Stopped reading because of: %v\n",err)
}

NB

  • h.Reset() will reset the chip
  • h.Gain is set to hx711.GAIN_A_128 by default

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.