Can I used two Hx711 modules with ESP32?

Status
Not open for further replies.

Thread Starter

Meca10

Joined Jun 15, 2021
27
Hello everyone

I tried to connect two HX711 modules using SPI comunication with HX711-multi library on ESP32. But when I compiled arduino HX711-multi library example it gave me errors. Someone give an advice about how made it.
 

Attachments

Last edited:

John P

Joined Oct 14, 2008
2,060
I have a project where I'm planning to connect 3 HX711's to an Arduino. I've been putting off connecting everything together, but it's got to happen eventually.

If anyone wants to know, the HX711 is an amplifier/interface for strain gauges. You get data from it via a serial data protocol that doesn't match any standard, though it's not really very complicated.
 

Thread Starter

Meca10

Joined Jun 15, 2021
27
Hi meca,
Tried your 'ino' file, it required the HX711-multi.h, so downloaded and installed from GitHub, it compiles OK.
Have not tried with HX711 hardware.
Let me know how it goes, I do have HX711's I could try.

E
Hi Eric

Thanks for your answer. I thought nobody answer me. I tried your script but it doesn't compile. Because my Arduino board configuration is for the ESP32. In your case you used the configuration for Arduino Uno.

My objective with these project is to used 2 of 3 SPI ports of the ESP32 for connect two HX711 modules and send these information through ESP's bluethooth. But actually I can connect one HX711 module using HX711 library.
 

Attachments

Last edited:

ericgibbs

Joined Jan 29, 2010
21,439
hi Meca,
As you say, the Arduino IDE with ESP32 selected reports an error when using HX711_multi.h

I have had no success in finding a solution, but one point was noted is the ESP internal clock is too high for HX711 operation.
This line needs to be added to reduce the clock rate.[ compliments of Andreas]
E
EG 1381.gif
 

Irving

Joined Jan 30, 2016
5,109
Yes you can BUT there is no device select on an HX711 so each one needs its OWN data clock and data input pins on the MCU. I've tried myself with a common clock but it causes so many issues as the devices get out of sync. Its not true SPI either.

I've not used the HX711_Multi header, just the standard one. Here's how I did it.

Dual HX711:
#include "HX711.h"

// HX711 circuit wiring
const int LOADCELL1_DOUT_PIN = 2;
const int LOADCELL1_SCK_PIN = 3;

const int LOADCELL2_DOUT_PIN = 4;
const int LOADCELL2_SCK_PIN = 5;

HX711 scale1;
HX711 scale2;

void setup() {
  Serial.begin(115200);
  scale1.begin(LOADCELL1_DOUT_PIN, LOADCELL1_SCK_PIN);
  scale2.begin(LOADCELL2_DOUT_PIN, LOADCELL2_SCK_PIN);
  Serial.println("Dual HX711 basic");
}

void loop() {

  if (scale1.is_ready()) {
    long reading = scale1.read();
    Serial.print("HX711 #1 reading: ");
    Serial.println(reading);
  } else {
    Serial.println("HX711 #1 not found.");
  }

  if (scale2.is_ready()) {
    long reading = scale2.read();
    Serial.print("HX711 #2 reading: ");
    Serial.println(reading);
  } else {
    Serial.println("HX711 #2 not found.");
  }

  delay(200);
}
 

ericgibbs

Joined Jan 29, 2010
21,439
hi Irving,
As you say, the regular hx711.h is no great problem with multiple HX711's , but the TS is wanting to use the hx711-multi.h version with multiple HX711's and an ESP32, compiled in the Arduino IDE.

If you have a Sketch to do that, I would appreciate a copy.

E
 

Irving

Joined Jan 30, 2016
5,109
hi Irving,
As you say, the regular hx711.h is no great problem with multiple HX711's , but the TS is wanting to use the hx711-multi.h version with multiple HX711's and an ESP32, compiled in the Arduino IDE.

If you have a Sketch to do that, I would appreciate a copy.

E
Hi Eric

Fair enough, though I personally wouldn't use that library, too complex, and the way he waits for each HX711 to be ready causes massive delays as noted.

Anyway, it won't compile for me...

1644011055299.png
 

ericgibbs

Joined Jan 29, 2010
21,439
hi Irving,
Thanks for trying and the positive feedback.
If I stumble across a method, I will post back.
I have no immediate application at this time.
E
 

Irving

Joined Jan 30, 2016
5,109
hi Irving,
Thanks for trying and the positive feedback.
If I stumble across a method, I will post back.
I have no immediate application at this time.
E
I'm not clear why this particular library is so critical. Its not an official one, just one of several on github that are 'in development'.

I do have a real application for two or more sensors read near coincidally so I've used commercially available HX711 boards, being careful to select ones that can be modded for 80Hz operation. I use the DOUT trailing edge as an interrupt and within the ISR generate 25 clock pulses at 2MHz to give an approx 15uS service interval per HX711. I use a separate clock & data pin pair per HX711. I found by experiment that a common clock causes far too many issues with mis-timing across parallel HX711 - as it says in the datasheet:

"PD_SCK clock pulses should not be less than 25 or more than 27 within one conversion period, to avoid causing serial communication error. "

Which means you have to wait until ALL DOUT go low before issuing clock pulses and reading DOUT on all HX711 simultaneously. If not there is the risk that there is a partial 'read' on the other HX711 should one become 'ready' during the read process which then throws everything out and can take several read cycles to get back in step.

I'll post my code shortly as its on another machine.
 
Status
Not open for further replies.
Top