Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple HX711 sharing CLK? #40

Closed
SanderM2 opened this issue Aug 18, 2023 · 13 comments
Closed

Multiple HX711 sharing CLK? #40

SanderM2 opened this issue Aug 18, 2023 · 13 comments
Assignees
Labels
question Further information is requested

Comments

@SanderM2
Copy link

Is it possible to have multiple HX711 connected and have them all shared the same CLK pin?
I'm running out of pins on my arduino and sharing the CLK should be possible I think? Just not sure if this library supports it.

@RobTillaart RobTillaart self-assigned this Aug 18, 2023
@RobTillaart RobTillaart added the question Further information is requested label Aug 18, 2023
@RobTillaart
Copy link
Owner

RobTillaart commented Aug 18, 2023

Need to think about it and it is 10:30 pm here so I will come back to this tomorrow.
First thoughts are that it is safer to share data lines. (this is incorrect)
If the hx711 gets clock pulses it will act somehow
Good question, needs some datasheet checking.

(updated incorrect statement)

@SanderM2
Copy link
Author

I thought sharing the clock line was the right way to do it. The MCU can ignore data on the other data lines when it's not actively reading that one. So it shouldn't matter if other HX711 are responding, right?

Sharing data lines would mean we're going to connect all DOUT pins of each HX711 together? It's an output only pin so I don't think that's a good idea?

Would love to hear from you tomorrow. Have a good night!

@RobTillaart
Copy link
Owner

Oops you're right
You see it is definitely late :)

@RobTillaart
Copy link
Owner

RobTillaart commented Aug 19, 2023

@SanderM2

Read the data-sheet after a good sleep :)


Sharing data lines would mean we're going to connect all DOUT pins of each HX711 together?
It's an output only pin so I don't think that's a good idea?

WARNING: Sharing the data lines is NOT possible as it could cause short circuit. So definitely not a good idea.


Sharing the CLOCK lines will work and as said before it will have some side effects.
If these are acceptable depends on the project at hand and the setup.

The side effects I found so far: (page 4 and 5 datasheet)

  • The CLOCK is used to select channel and to select gain for the NEXT sample.
  • The CLOCK is used for power down.
  • After wake up after power down all HX711's will reset to channel A and gain 128.
    Thinking about it a bit longer, if one of the objects does a power down (or reset) it resets its internal states.
    However the other objects won't reset their internal state.

So in short, sharing the CLOCK line causes all HX711 modules share the same state.
This can introduce extra complexity if one uses mixed gains or channels.
If all HX711's use the same settings it should work, use power down/reset with care.


Alternative is to use a multiplexer e.g. HC4052

@RobTillaart
Copy link
Owner

The MCU can ignore data on the other data lines when it's not actively reading that one

Correct, if you create two HX711 objects with the library, only the object that calls read() will fetch data.

So it shouldn't matter if other HX711 are responding, right?

See the above side effects.

@RobTillaart
Copy link
Owner

FYI, I prepared some notes to add the above findings to the readme.md file.

@RobTillaart
Copy link
Owner

Another idea popped up, just to share.

If you add AND gates (74LS08) to the HX711's you can create multiple SELECT lines,
selecting only one HX711 at a time.
This can be extended many times.

      MCU                         AND GATE                 HX711
   +---------+                   +---------+             +---------+
   |     DIN |<--------+---------| OUT   A |<------------| OUT     |
   |         |         |         |         |             |         |
   |    SEL1 |==================>| B       |             |         |
   |         |         |         +---------+             |         |
   |     CLK |----+------------------------------------->| CLK     |
   |         |    |    |                                 +---------+
   |         |    |    |
   |         |    |    |
   |         |    |    |          AND GATE                 HX711
   |         |    |    |         +---------+             +---------+
   |         |    |    +---------| OUT   A |<------------| OUT     |
   |         |    |              |         |             |         |
   |    SEL2 |==================>| B       |             |         |
   |         |    |              +---------+             |         |
   |         |    +------------------------------------->| CLK     |
   |         |                                           +---------+
   +---------+ 

@RobTillaart
Copy link
Owner

Added example HX_loadcell_array.ino in develop branch.
Tested this (< 1 hour) with hardware and it worked without problems.

Will be integrated in master with an upcoming release (probably 0.3.8), timeline unknown.

@SanderM2
Copy link
Author

Thanks! ;-)

I've been experimenting with your library earlier today. With a single HX711 for testing now it seems like get_units(10) takes approximately 800ms. Isn't the HX711 supposed to be able to go faster?

@RobTillaart
Copy link
Owner

@SanderM2

With a single HX711 for testing now it seems like get_units(10) takes approximately 800ms.

The sensor blocks between reads, and it makes typically 10SPS (see below)

hx711.cpp about line 90

//  From datasheet page 4
//  When output data is not ready for retrieval,
//       digital output pin DOUT is HIGH.
float HX711::read()
{
  //  this BLOCKING wait takes most time...
  while (digitalRead(_dataPin) == HIGH) yield();

Can you run the HX_performance.ino sketch and post your output?


Isn't the HX711 supposed to be able to go faster?

The HX711 can be configured to 10 SPS or 80 SPS, however as all breakouts I have used
do not expose the RATE pin I have no way to let it go faster,
See - https://github.com/RobTillaart/HX711/tree/develop#10-or-80-sps

If there is an explicit need I have planned future support on the could list

@RobTillaart
Copy link
Owner

@SanderM2

If the blocking is a problem for your project you could

@RobTillaart
Copy link
Owner

@SanderM2
As the sharing CLK seems to work, I propose to close this issue.
Feel free to open an issue on the performance and support of the RATE pin in the library.

RobTillaart added a commit that referenced this issue Aug 26, 2023
- fix #41 #40 add example **HX_loadcell_array.ino**
  - test support array of loadcells.
- update readme.md
- add issue-count badge
- add PlatformIO badge
- minor edits
@RobTillaart
Copy link
Owner

As there is no additional questions/remarks I close the issue.
Feel free to reopen if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants