Code Monkey home page Code Monkey logo

hx711-pico-mpy's Introduction

hx711-pico-mpy

MicroPython port of hx711-pico-c.

Implemented as a single Python file which you can drop into your project.

Example

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

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())

hx711-pico-mpy's People

Contributors

endail avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

spencerrightsma

hx711-pico-mpy's Issues

Multiple sensors

Althought the library works great for a single sensor, it does not yet seem to scale to support multiple sensors/instances of the libraray.
When I tried this I received only values from one adc on both instances.

More than 2 sensors possible ?

Thank you for the great code and support.

I found also that thinks get a little tricky when using 2 sensors on 1 pico.

Then I read this helpful thread:
#3

Is it possible also to run even more than 2 sensors on 1 pico (I'd like to go up to 4, perhaps even 8 if that's possible) ?

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.