hx711

package module
v0.0.0-...-cc6ce7b Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2016 License: BSD-3-Clause Imports: 1 Imported by: 0

README

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

This is a simple package to read the value from the HX711 load cell amplifier like this one from sparkfun

It uses the primitives from HWIO and the protocol from the HX711 data sheet

I've only tested this on a rPi Zero (GPIO at pin 16 & 18) and it's (obviously) missing a lot of high-level things are tare, calibrate, etc.

Feel free to submit pull requests with new features.

Example:
import "github.com/rajmaniar/hx711"

func main() {

   	clock := "gpio23"
   	data := "gpio24"
   
   	h,err := hx711.New(data,clock)
   
   	if err != nil {
   		fmt.Printf("Error: %v",err)
   	}
   
   	for err == nil {
   		var data int32
   		data, err = h.ReadData()
   		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

Documentation

Index

Constants

View Source
const (
	GAIN_A_128 = 1
	GAIN_B_32  = 2
	GAIN_A_64  = 3
)

Variables

This section is empty.

Functions

This section is empty.

Types

type HX711

type HX711 struct {
	Clock string
	Data  string
	Gain  int
	// contains filtered or unexported fields
}

func New

func New(data string, clock string) (*HX711, error)

New instantiates a new object

func (*HX711) OnReady

func (h *HX711) OnReady() error

OnReady Blocks until the chip is ready to send data

func (*HX711) ReadData

func (h *HX711) ReadData() (int32, error)

ReadData gets a 24bit signed int from the chip

func (*HX711) Reset

func (h *HX711) Reset() error

Reset / Wakeup the chip

func (*HX711) SetGain

func (h *HX711) SetGain() error

SetGain sets the gain after data has been read

func (*HX711) Sleep

func (h *HX711) Sleep() error

Sleep the chip until you need

Jump to

Keyboard shortcuts

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