Coder Social home page Coder Social logo

hx711-rpi-py's Introduction

Raspberry Pi HX711 Python Bindings

Upload to PyPI

Python bindings for Raspberry Pi HX711 C++ Library

Sample Output

hx711.gif

The .gif above illustrates the output of a simple Python script on a Raspberry Pi Zero W where the HX711 chip was operating at 80Hz. In this example, each time the .weight function is called the median of three samples was used to calculate the weight in grams.

Examples

SimpleHX711 Example

from HX711 import *

# create a SimpleHX711 object using GPIO pin 2 as the data pin,
# GPIO pin 3 as the clock pin, -370 as the reference unit, and
# -367471 as the offset
hx = SimpleHX711(2, 3, -370, -367471)

# set the scale to output weights in ounces
hx.setUnit(Mass.Unit.OZ)

# constantly output weights using the median of 35 samples
while True:
    print(hx.weight(35)) #eg. 1.08 oz

AdvancedHX711 Example

from HX711 import *
from datetime import timedelta

# create an AdvancedHX711 object using GPIO pin 2 as the data pin,
# GPIO pin 3 as the clock pin, -370 as the reference unit, -367471
# as the offset, and indicate that the chip is operating at 80Hz
hx = AdvancedHX711(2, 3, -370, -367471, Rate.HZ_80)

# constantly output weights using the median of all samples
# obtained within 1 second
while True:
    print(hx.weight(timedelta(seconds=1))) #eg. 0.03 g

Install

  1. Install libhx711. Optionally, you can use this script.

  2. pip3 install hx711-rpi-py

Calibrate

There is a Python script in the src directory you can use to calibrate your load cell and obtain the reference unit and offset values referred to above. The simplest way to use it after installing hx711-rpi-py is as follows:

pi@raspberrypi:~ $ wget https://github.com/endail/hx711-rpi-py/blob/master/src/calibrate.py
pi@raspberrypi:~ $ python3 calibrate.py

When you no longer need it, simply rm calibrate.py to remove the calibration script.

Documentation

As the Python code relies upon the underlying C++ library, the documentation is identical. However, not all of the code is exposed to Python. An example is the Utility class, which is only meant for use within the C++ library. You can check precisely which functionality is accessible through Python in the bindings.cpp file.

hx711-rpi-py's People

Contributors

endail avatar

Watchers

 avatar

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.