HX711 amplifier, changing channels

Thread Starter

John P

Joined Oct 14, 2008
2,026
The HX711 is a commonly available instrumentation amplifier and A-D converter, which lots of vendors sell:
https://www.sparkfun.com/products/13879

I'm playing with some load cells and I got a few HX711's to interface them to an Arduino and a computer. The HX711 actually has 2 channels, A and B, and there's a procedure to switch between them, but at first I thought it didn't work. Then I found that I can switch channels, but every time I do, the device slows way down--the cycle after making a channel change, there's a delay of about 60msec, so if you alternate the channels, you get a full cycle in about 120msec or roughly 8 per second. I'm wondering if I've done this right, or if there's a better procedure to make it faster.

The HX711 has its own oddball serial interface. There's a data line and a clock line, and the device does conversions repeatedly, and sends the data line low when it completes a conversion. A processor has to watch for the lowgoing edge, then send clock pulses which clock out 24 bits of actual data. You can send 1, 2 or 3 extra clock pulses, which make selections for the next cycle--channel A at a gain of 64 or 128, or channel B at a gain of 32. It's those initial lowgoing edges that seem to get slowed down by changing channels. If you don't change channels, it runs at 80 cycles per second. (Or 10, using a selection pin, but I'm trying to use 80.)
 

Thread Starter

John P

Joined Oct 14, 2008
2,026
Thanks for taking an interest, Eric. Here is the Arduino sketch (to run on a Nano):
https://drive.google.com/file/d/1pSSCqkHmTQdK5IyGJj-rnSLOaH5VGiiH/view?usp=sharing

And since you showed yours, I'll show mine:
P2181244.JPGYou can see that the red and black wires coming away from the HX711 are spliced, to allow 2 load cells to be connected. Both cells are in view, temporarily attached to a bar with clamps. Just as you did, I made a change to the HX711 board to enable the 80Hz frequency, and it works if only 1 channel is used, but if the channels alternate, it slows way down.

The sketch is written to test my intended setup, which involves 6 load cells and 3 HX711's. At present it's not complete, and the Arduino is always reading the data just from the single amplifier, and saving it to every one of the 3 channel pairs in sequence. After every set of readings, the data for all the 6 channels is sent in a packet via the serial/USB port, but that's not relevant to the timing. A pin on the Nano is used to produce a pulse that's only sent during one channel's reading time, to verify on a scope that the alternation of channels is really happening. Of course the clock pulses can also be checked, and so can the TX pin. If you look at the code, you can see that I set up the data storage in a long variable per channel, but this is declared as a union which also lets me handle the data as 4 separate bytes, even though only 3 are needed to store the 24 bits from the HX711. This is just to make the code neater and doesn't really affect the operation. There are ways the code could be speeded up, but it doesn't seem as though the code is what's limiting the speed.
 
Last edited:
Top