Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/endail/hx711-pico-mpy
MicroPython implementation of HX711 use via RP2040's state machine
https://github.com/endail/hx711-pico-mpy
hx711 iot load-cell loadcell micropython micropython-rpi-pico pio pioasm python raspberry-pi-pico raspberry-pi-pico-rp2040 rp2040 state-machine
Last synced: 3 months ago
JSON representation
MicroPython implementation of HX711 use via RP2040's state machine
- Host: GitHub
- URL: https://github.com/endail/hx711-pico-mpy
- Owner: endail
- License: mit
- Created: 2022-08-26T11:49:09.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-14T08:23:56.000Z (almost 2 years ago)
- Last Synced: 2024-10-31T09:50:16.650Z (3 months ago)
- Topics: hx711, iot, load-cell, loadcell, micropython, micropython-rpi-pico, pio, pioasm, python, raspberry-pi-pico, raspberry-pi-pico-rp2040, rp2040, state-machine
- Language: Python
- Homepage:
- Size: 39.1 KB
- Stars: 12
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hx711-pico-mpy
MicroPython port of [hx711-pico-c](https://github.com/endail/hx711-pico-c).
Implemented as a [single Python file](https://raw.githubusercontent.com/endail/hx711-pico-mpy/main/src/hx711.py) which you can drop into your project.
## Example
```python
from machine import Pin
from src.hx711 import *# 1. initalise the hx711 with pin 14 as clock pin, pin
# 15 as data pin
hx = hx711(Pin(14), Pin(15))# 2. power up
hx.set_power(hx711.power.pwr_up)# 3. [OPTIONAL] set gain and save it to the hx711
# chip by powering down then back up
hx.set_gain(hx711.gain.gain_128)
hx.set_power(hx711.power.pwr_down)
hx711.wait_power_down()
hx.set_power(hx711.power.pwr_up)# 4. wait for readings to settle
hx711.wait_settle(hx711.rate.rate_10)# 5. read values
# wait (block) until a value is read
val = hx.get_value()# or use a timeout
if val := hx.get_value_timeout(250000):
# value was obtained within the timeout period
# in this case, within 250 milliseconds
print(val)# or see if there's a value, but don't block if not
if val := hx.get_value_noblock():
print(val)# 6. stop communication with HX711
hx.close()```
## Alternatively, Use `with`
```python
with hx711(Pin(14), Pin(15)) as hx:
hx.set_power(hx711.power.pwr_up)
hx.set_gain(hx711.gain.gain_128)
hx711.wait_settle(hx711.rate.rate_10)
print(hx.get_value())
```