{"id":18689264,"url":"https://github.com/endail/hx711-rpi-py","last_synced_at":"2025-06-15T13:08:12.694Z","repository":{"id":44581692,"uuid":"396795607","full_name":"endail/hx711-rpi-py","owner":"endail","description":"Python bindings for Raspberry Pi HX711 C++ Library","archived":false,"fork":false,"pushed_at":"2024-01-21T12:21:40.000Z","size":407,"stargazers_count":14,"open_issues_count":3,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-15T15:54:42.485Z","etag":null,"topics":["hx711","lgpio","load-cell","pybind11","python","raspberry-pi"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/endail.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-16T12:58:17.000Z","updated_at":"2025-03-31T22:40:30.000Z","dependencies_parsed_at":"2024-11-07T10:43:40.139Z","dependency_job_id":"db237d6e-412a-4057-b9e1-d9f5edf7ab2e","html_url":"https://github.com/endail/hx711-rpi-py","commit_stats":{"total_commits":297,"total_committers":2,"mean_commits":148.5,"dds":"0.23232323232323238","last_synced_commit":"c5bb28e510385d9005cb60e3f40cd19c9461f349"},"previous_names":[],"tags_count":64,"template":false,"template_full_name":null,"purl":"pkg:github/endail/hx711-rpi-py","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/endail%2Fhx711-rpi-py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/endail%2Fhx711-rpi-py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/endail%2Fhx711-rpi-py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/endail%2Fhx711-rpi-py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/endail","download_url":"https://codeload.github.com/endail/hx711-rpi-py/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/endail%2Fhx711-rpi-py/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259981478,"owners_count":22941149,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hx711","lgpio","load-cell","pybind11","python","raspberry-pi"],"created_at":"2024-11-07T10:41:55.741Z","updated_at":"2025-06-15T13:08:12.656Z","avatar_url":"https://github.com/endail.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Raspberry Pi HX711 Python Bindings\n\n[![Upload to PyPI](https://github.com/endail/hx711-rpi-py/actions/workflows/build_and_upload.yml/badge.svg)](https://github.com/endail/hx711-rpi-py/actions/workflows/build_and_upload.yml) [![Downloads](https://pepy.tech/badge/hx711-rpi-py)](https://pepy.tech/project/hx711-rpi-py)\n\nPython bindings for [Raspberry Pi HX711 C++ Library](https://github.com/endail/hx711)\n\n- Use with Raspberry Pi\n- Read from a HX711 using Python\n- Code tested inside [virtual Raspberry Pi Zero/3/4 environments](.github/workflows/build_and_upload.yml) on GitHub and builds automatically uploaded to PyPI\n- This repo automatically rebuilds when the C++ library is updated\n\n## Sample Output\n\n![hx711.gif](hx711.gif)\n\nThe .gif above illustrates the output of a [simple Python script](src/test.py) 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.\n\n## Examples\n\n```python\nfrom HX711 import *\n\n# create a SimpleHX711 object using GPIO pin 2 as the data pin,\n# GPIO pin 3 as the clock pin, -370 as the reference unit, and\n# -367471 as the offset\nwith SimpleHX711(2, 3, -370, -367471) as hx:\n\n  # set the scale to output weights in ounces\n  hx.setUnit(Mass.Unit.OZ)\n\n  # zero the scale\n  hx.zero()\n\n  # constantly output weights using the median of 35 samples\n  while True:\n    print(hx.weight(35)) #eg. 1.08 oz\n```\n\n### Alternative Syntax (w/out `with`)\n\n```python\nfrom HX711 import *\n\nhx = SimpleHX711(2, 3, -370, -367471)\nhx.setUnit(Mass.Unit.OZ)\nhx.zero()\nwhile True:\n  print(hx.weight(35))\n```\n\nKeep in mind that calling `.weight()` will return a `Mass` object, but you can do the following:\n\n```python\n# set the scale to output weights in ounces\nhx.setUnit(Mass.Unit.OZ)\n\n# obtain a median reading from 35 samples as a Mass object in ounces\nm = hx.weight(35)\n\n# number in ounces\nnum = float(m) # eg. 1.08\n\n# string representation of the Mass\ns = str(m) # eg. 1.08 oz\n\n# print the Mass object\nprint(m) # eg. 1.08 oz\n\n# change the unit to grams\nm.setUnit(Mass.Unit.G)\ngrams_as_str = str(m) # eg. 30.62 g\n\n# or obtain a new Mass object\nm2 = m.convertTo(Mass.Unit.KG)\nkgs_as_str = str(m2) # eg. 0.031 kg\n```\n\nThe list of different `Mass.Unit`s can be viewed [here](https://github.com/endail/hx711#mass).\n\n### Time-Based Sampling\n\nYou can use [`datetime.timedelta`](https://docs.python.org/3/library/datetime.html#timedelta-objects) to obtain as many samples as possible within the time period.\n\n```python\nfrom HX711 import *\nfrom datetime import timedelta\n\nwith SimpleHX711(2, 3, -370, -367471) as hx:\n  while True:\n    # eg. obtain as many samples as possible within 1 second\n    print(hx.weight(timedelta(seconds=1)))\n```\n\n### Options\n\n`.weight()`, `.zero()`, and `.read()` can all take an `Options` parameter. You can use this to fine tune how you want the scale to behave.\n\n```python\n\n# zero the scale by using the average value of all samples obtained within 1 second\nhx.zero(Options(\n  timedelta(seconds=1),\n  ReadType.Average))\n\n# obtain a raw value from the scale using the median of 100 samples\nnum = hx.read(Options(\n  100,\n  ReadType.Median))\n\n# obtain a Mass object using the median of three samples\n# all four statements below are equivalent\nm = hx.weight()\nm = hx.weight(3)\nm = hx.weight(Options())\nm = hx.weight(Options(\n  3,\n  ReadType.Median))\n\n# Options can also be created separately\nopts = Options()\nopts.timeout = timedelta(seconds=5)\nopts.stratType = StrategyType.Time\nm = hx.weight(opts)\n```\n\n## Install\n\n1. Install [libhx711](https://github.com/endail/hx711)\n\n2. `pip3 install --upgrade hx711-rpi-py`\n\n## Calibrate\n\nThere 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:\n\n```console\npi@raspberrypi:~ $ wget https://raw.githubusercontent.com/endail/hx711-rpi-py/master/src/calibrate.py\npi@raspberrypi:~ $ python3 calibrate.py [data pin] [clock pin]\n```\n\nSubstitute `[data pin]` and `[clock pin]` with the [GPIO pin numbers](https://pinout.xyz/) which are connected to the HX711's data pin and clock pin, respectively.\n\n## Documentation\n\nAs the Python code relies upon the [underlying C++ library](https://github.com/endail/hx711#documentation), the documentation is identical. However, not all of the code is exposed to Python. You can check precisely which functionality is accessible through Python in the [bindings.cpp file](src/bindings.cpp).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fendail%2Fhx711-rpi-py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fendail%2Fhx711-rpi-py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fendail%2Fhx711-rpi-py/lists"}