I am setting up a system to connect to up to 4 load cells using HX711 and the Bodge HX711 library on an Arduino Nano CH340 board. To determine how many load cells are connected, I do the following:
scale1.begin(DOUT1, CLK1);
scale2.begin(DOUT2, CLK2);
scale3.begin(DOUT3, CLK3);
scale4.begin(DOUT4, CLK4);
delay(2000))
if (scale1.wait_ready_timeout(200)) {
scale1.set_scale(calibration_factor_1);
scale1.set_offset(zero_factor_1);
lcd.print("1: ");
scale1connected = true;
}
if (scale2.wait_ready_timeout(200)) {
scale2.set_scale(calibration_factor_2);
scale2.set_offset(zero_factor_2);
lcd.setCursor(8, 0);
lcd.print("2: ");
scale2connected = true;
}
if (scale3.wait_ready_timeout(200)) {
scale3.set_scale(calibration_factor_3);
scale3.set_offset(zero_factor_3);
lcd.setCursor(0, 1);
lcd.print("3: ");
scale3connected = true;
}
if (scale4.wait_ready_timeout(200)) {
scale4.set_scale(calibration_factor_4);
scale4.set_offset(zero_factor_4);
lcd.setCursor(8, 1);
lcd.print("4: ");
scale4connected = true;
}
I was getting very inconsistent results and after probing and looking at the pin states in the serial output, it turns out that the Scale.begin must be setting the pinMode to INPUT instead of INPUT_PULLUP. In the library, it should only do this for ESP boards:
#if ARCH_ESPRESSIF
// ESP8266 doesn't read values between 0x20000 and 0x30000 when DOUT is pulled up.
#define DOUT_MODE INPUT
#else
#define DOUT_MODE INPUT_PULLUP
#endif
If I set the pin mode to INPUT_PULLUP after the Scale.Begin command, it works as expected.
Any idea why the library is not setting the pin mode correctly?