Coder Social home page Coder Social logo

crjeder / hx711_spi Goto Github PK

View Code? Open in Web Editor NEW
14.0 2.0 4.0 425 KB

This is a library for the hx711 chip. It uses SPI instead of bit banging for more reliability.

License: MIT License

Rust 100.00%
hx711 driver spi rust-lang rust-embedded embedded-hal-driver embedded-hal load-cells adc

hx711_spi's People

Stargazers

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

Watchers

 avatar  avatar

hx711_spi's Issues

update to embedded-hal 1.0.0

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Tweak to work on stm32f103

Hey! I've tried connecting it to an stm32f103 ("blue pill") board and ran into a couple of issues that this patch seems to address.

First ChAGain128 seemed to be missing a 0, noticed only because initially I tried with SPI mode 0 where the MOSI (used here as a clock driver) pin was going "high" in between bytes, resulting in an extra 1/0 transition.

That said running SPI in the mode 1 seems closer to the original intention of the code (not sure about rpi though).

This PR seems to fix it for me.

See a couple of screenshots below:

SPI mode 0 (the missing 0 fix already included)
SPI-mode0

SPI mode 1
SPI-mode1

Spi reader dont work for me :(

I wrote a test example for your library: https://github.com/pronvis/drawer-robot/blob/master/crates/companion/src/bin/hx711_spi_read.rs
And it reads absolutely noise:

└─ hx711_spi_read::app::hx711_read @ src/bin/hx711_spi_read.rs:135
DEBUG #26: DYMH-06 data: -221.92485
└─ hx711_spi_read::app::hx711_read @ src/bin/hx711_spi_read.rs:135
DEBUG #31: DYMH-06 data: -0.000035274
└─ hx711_spi_read::app::hx711_read @ src/bin/hx711_spi_read.rs:135
DEBUG #35: DYMH-06 data: -221.92485
└─ hx711_spi_read::app::hx711_read @ src/bin/hx711_spi_read.rs:135
DEBUG #40: DYMH-06 data: -0.000035274
└─ hx711_spi_read::app::hx711_read @ src/bin/hx711_spi_read.rs:135
DEBUG #44: DYMH-06 data: 184.93732
└─ hx711_spi_read::app::hx711_read @ src/bin/hx711_spi_read.rs:135
DEBUG #49: DYMH-06 data: 258.91226

but non-spi reader that is used here: https://github.com/pronvis/drawer-robot/blob/master/crates/companion/src/bin/hx711_read.rs
works fine. What could be wrong?
All the difference in pin connections is:
with spi:

PB13 <-> SCK
PB14 <-> DT

with non-spi:

PA7 <-> SCK
PA6 <-> DT

Introduce a feature to invert signal on SDO

Is your feature request related to a problem? Please describe.

I was trying to utilize the crate on ESP32-C3. The block!(hx711.read()) will always block. After digging around, I found the SDO of ESP32-C3 is always idle at HIGH and I haven't find a way to change the behavior. So I decided to use a MOSFET to hold the SDO at LOW when no data is transfered. However, the CS on ESP32-C3 is disabled after SDO pulled itself HIGH, the value I got is not correct.

using CS to hold SDO at LOW

Later I tried to invert the polarity of SDO with the MOSFET and change the code, it looks better now.

Invert SDO

Describe the solution you'd like

Introduce a new feature invert-sdo, and enable it will invert the signal on SDO, allowing external inverter. For example

#[cfg(not(feature = "invert-sdo"))]
let value = 0x00;
#[cfg(feature = "invert-sdo")]
let value = 0xFF;

Describe alternatives you've considered

Maybe there's a way to fix it on ESP32-C3's side.

Additional context

MOSFET model 1N60C, an additional 1kΩ resistor is used when inverting the SDO. SPI speed is 1MHz.

Edit: wrong resistor value

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.