Multiple Load Cells setup where multiple items can be weighed and readings recorded

MY PROJECT :

Multiple Load Cells setup where multiple items can be weighed and readings recorded.

I have succeeded in taking readings on multiple load cells(4 wire),

Hardware : Arduino UNO R3 Clone, 4 wire LoadCells (1 Kg),

Screens : 16x2 LCD & a 0.96 Inch OLED

OBJECTIVE :

To connect more than 20 load cells and read separate weights of different items and record the same.

Currently I have setup 5 Load cells, I am observing strange behaviour,

0.96 inch OLED - works and displays upto 3 loadcells values, anything beyond 3 the screen does not populate at all. It does not even show the tare values

16 x 2 LCD - works and displays only upto 2 loadcells with readable values, anything beyond 2 the weighing does not take place, only dummy tare states (0.0 g) of the 4 loadcells are displayed.(weighing does not work).

At first I thought it could be a limitation of the UNO R3 board given its low specs. but when I noticed the difference between the 2 screens, I am wondering if this is some limitation of the screens ?

I would appreciate if the community experts guide me to the problem, A 3.2 inch resistive touch panel is on the way given(in transit) my ultimate objective is to connect and read more than 20 load cells on my setup, where a larger screen is a necessity.

Thanks in Advance.

Can you take a photo of a hand-drawn wiring diagram of just three load cells? My suspicion is you can't do what you plan.

Which load cell amplifier are you using?

No wiring diagram, no code to check.
How do you expect us to see your setup. A crystal ball?

Assuming you using HX711 boards.
Are you aware of the time it takes for a HX711 to read.
Default sample rate is 10Hz, so a round trip of five boards is already half a second.
Does your code wait for that before handing it over to the LCD.
Do you use the HX711-Multi library, so you can share all clock lines, saving pins.
Leo..

Oops !
Yes HX711 amplifier
Yes I have shared all clk lines to pin 2,
Library : HX711_ADC

void loop() {
  
  LoadCell1.update(); // retrieves data from the load cell
  float w1 = LoadCell1.getData();
  GetScale(LoadCell1, w1, 1, 5, 15);
;
;
;
;
  LoadCell(n).update();
  float w(n) = LoadCell(n).getData();
  GetScale(LoadCell(n), w(n), (n), 5, 55);

}

CODE :

Simple code which just calls GetScale() for each loadcell, … rinse and repeat.
Code works(freezes/reboot issues exist) for 3 loadcells on an OLED display & 2 loadcells on 16x2 LCD display.

Are you sure that library supports clock sharing.
The included Read_2x_load_cell example of the library suggests otherwise.

Please post full code.
We can't test snippets.
Leo..

Yes, Its reading 3 cells with the clk being shared.

HX711_ADC - for forum1.txt (2.6 KB)

You need to post your code.
Please use code tags to do so <CODE/>

type or paste code here

Yes I have shared all clk lines to pin 2,

How long are the wires for the clocks and data?

#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>

#include <HX711_ADC.h> // https://github.com/olkal/HX711_ADC

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define SCREEN_I2C_ADDRESS 0X3C
#define OLED_RESET_PIN -1

Adafruit_SSD1306 lcd(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET_PIN);

HX711_ADC LoadCell1(3, 2); // dt pin, sck pin
HX711_ADC LoadCell2(4, 2);
HX711_ADC LoadCell3(5, 2);
// HX711_ADC LoadCell4(6, 2);
// HX711_ADC LoadCell5(7, 2);
// HX711_ADC LoadCell6(8, 2);
// HX711_ADC LoadCell7(9, 2);

int taree = 13;
int a = 0;
float b = 0;

void setup() {
  lcd.begin(SSD1306_SWITCHCAPVCC, SCREEN_I2C_ADDRESS);
  lcd.clearDisplay();
  lcd.setTextColor(WHITE, BLACK);
  lcd.setTextSize(1);

  pinMode (taree, INPUT_PULLUP);

  LoadCell1.begin(); // start connection to HX711
  LoadCell2.begin();
  LoadCell3.begin();
  // LoadCell4.begin();
  // LoadCell5.begin();
  // LoadCell6.begin();
  // LoadCell7.begin();

  LoadCell1.start(1000); // load cells gets 1000ms of time to stabilize - move to loop
  LoadCell2.start(1000);
  LoadCell3.start(1000);
  // LoadCell4.start(1000);
  // LoadCell5.start(1000);
  // LoadCell6.start(1000);
  // LoadCell7.start(1000);


  ///////////////////////////////////// Load Cell Sequence 1-n from the bottom
  LoadCell1.setCalFactor(-2200);
  LoadCell2.setCalFactor(-2257);
  LoadCell3.setCalFactor(-2110);
  // LoadCell4.setCalFactor(-2265);
  // LoadCell5.setCalFactor(-2411);
  // LoadCell6.setCalFactor(-2257);
  // LoadCell7.setCalFactor(-2200);
  /////////////////////////////////////

}

void loop() {

  LoadCell1.update(); // retrieves data from the load cell
  float w1 = LoadCell1.getData();
  GetScale(LoadCell1, w1, 1, 5, 15);

  LoadCell2.update();
  float w2 = LoadCell2.getData();
  GetScale(LoadCell2, w2, 2, 5, 25);

  LoadCell3.update();
  float w3 = LoadCell3.getData();
  GetScale(LoadCell3, w3, 3, 5, 35);

  // LoadCell4.update();
  // float w4 = LoadCell4.getData();
  // GetScale(LoadCell4, w4, 4, 5, 45);

  // LoadCell5.update();
  // float w5 = LoadCell5.getData();
  // GetScale(LoadCell5, w5, 5, 5, 55);

  // LoadCell6.update();
  // float w6 = LoadCell6.getData();
  // GetScale(LoadCell6, w6, 6, 5, 45);

  // LoadCell7.update();
  // float w7 = LoadCell7.getData();
  // GetScale(LoadCell7, w7, 7, 5, 55);

}

void GetScale(HX711_ADC LoadCell, float weight, int sensorNum, int x, int y){

  // Make weight positive for display
    if (weight < 0) {
        weight = -weight;
    }
  
  // lcd weight in grams
  
      lcd.setCursor(x, y);
      lcd.print(weight, 1);
      lcd.print("g");
  
 // Tare (zeroing)
        if (digitalRead (taree) == LOW)
        
  }

20 cms standard male-male jumper wires running through a breadboard so Vcc, Gnd & Clk can be shared to save pins on the board.

I have tested uncommenting the 4th loadcell definition line…

HX711_ADC LoadCell4(6, 2)

all other reference within the code to LoadCell4 have been commented out.

I guess the above pin definition of the 4th loadcell itself is causing the code to not proceed any further, even though it is compiling without errors.

BEING WISHFULL : I hope its some cap SET in the HX711_ADC LIBRARY limiting it to only 3 loadcells, and hoping that cap could be modified to accomodate more loadcells.

If three boards are working with a shared clock pin on that library,
did you think of trying another group of HX711 boards on a different clock pin.
The Uno has 16 available digital pins, not counting the I2C pins A4, A5.
Leo..

I believe you have a memory problem.
The Adafruit SSD1306 library allocates a 1024 byte buffer for the display. That plus the 898 bytes used by the rest of the program (when using 4 loadcells) only leaves 2048-1024-898=126 bytes for the program heap/stack and that is not enough

That is exactly what i tried, I just removed one HX711 board clk from shared and connected it to Pin 12, as already mentioned I just uncommented the pinout definition for the 4th cell with any other reference to the the 4th loadcell within the code still commented, result was the Screen wouldn’t display anything …

I suspect something on these exact lines ...

ATMega328P Processor
Memory:
AVR CPU at up to 16 MHz
32KB Flash
2KB SRAM
1KB EEPROM

Cool @jim-p … how do we calculate the 898 bytes, BTW it would be for 3 loadcells.
898/3 = 300 bytes / loadcell … 126bytes in sufficient for the 4th loadcell.

just to test this theory, any way i can reduce the ssd1306 library’s buffer allocation of 1024 bytes(I have uploaded the screen display, if the minimal display elements can enable the shrinking) ? If i can manage to save 200 bytes from that buffer I can put this theory to test.

What’s the alternative ?
Any possibility of increasing the memory by way of adding module ?
How do I accomplish the 20+ cells project requirement without making it bulky ?
Will a Mega board be the solution ?

If I can test this theory, then …
Uno R4 Minima,[15] ABX00080,(softer on the wallet, given its costing me between ($8-$10) boasts of **32kb SRAM

Maths**
300 *25 loadcells = 5000 bytes
32000 - 5000 = 17000 bytes to spare to accomodate a bigger LCD(need to display 25 loadcell readings) and its buffer overheads and other features I intend & hope to work into the code.

PS : turns out Uno Main has only 8000 bytes and expesive then the R4 Minima, 3000 bytes are present to spare but its cossting me more then the R4 Minima.

The IDE prints out the RAM usage in the output window.
This is with 4 loadcells

Sketch uses 15750 bytes (48%) of program storage space. Maximum is 32256 bytes.
Global variables use 898 bytes (43%) of dynamic memory, leaving 1150 bytes for local variables. Maximum is 2048 bytes.

@jim-p … Oh Wow, did you try my code with 4 loadcells ?
Do you have the hardware(HX711 & Loadcell) ?

or

just compiling the code in the IDE will throw up those numbers ?

Yes

It's difficult to estimate how much memory each load cell will use but for just one loadcell the RAM usage is 392 bytes.
392 x 20 = 7840 bytes.
If you use a bigger display then you will need to find out how much memory it needs but graphic displays tend to use more memory than the plain text displays

You could also use a MUX to connect the HX711 data signals. It would require some more code for switching but you only need to create one instance of the HX711

Hi Leo,

interesting library, but it is worth to read PR nr 2 as it has an important fix.

Note, all HX711 operate with the same gain, which probably match most applications.

Unfortunately it seems not to be maintained,

How much memory would your library use if 20 HX711s were instantiated?