Load cell example code

Does anyone have some example code for using 3 load cells to measure weight separately with 3 hx711 boards on an Arduino Mega? I've been looking on the internet for a while now and all I get are unsolved problems with using more than 2 hx711s? I understand I have to calibrate my own load cells by my self I just am confused on how to code it correctly. I didn't start any code myself, because I am still very puzzled.

Have you got a program with one load cell working ? Post it here if you have.

How about two load cells ? Have you got that working ?

What are the problems with more than two load cells ?

Library: Library: HX711

Code:

#include <Hx711.h>
Hx711 scale(A2, A3);

void setup() {
Serial.begin(9600);
}

void loop() {
Serial.print(scale.getGram(), 1);
Serial.println(" g");
delay(200);
}

This is code for one load cell. I haven't tried 2 yet, but I heard that if you get 2 working it will be easy to get to 3

Try this (untested)

#include <Hx711.h>
Hx711 scale1(A2, A3);
Hx711 scale2(A4, A5);

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  Serial.print("Scale 1 : \t");
  Serial.print(scale1.getGram(), 1);
  Serial.println(" g");
  Serial.print("Scale 2 : \t");
  Serial.print(scale2.getGram(), 1);
  Serial.println(" g");
  delay(200);
}

It should be obvious from the code which pins the second load cell should be connected to. If this works then you can extend it to 3 devices and it would be worth considering using an array of objects to keep the code simpler.

Array of Objects?

YoungsterSP:
Array of Objects?

In my code scale1 and scale2 are objects. It should be possible to create an array of such objects to tidy up the code and reduce it.

Where would this array be displayed? In the serial monitor? I actually did some research on putting my data into a table before all of this and I'm hoping this will help. I also want to know how to actually put my data into an array.

YoungsterSP:
Where would this array be displayed? In the serial monitor? I actually did some research on putting my data into a table before all of this and I'm hoping this will help. I also want to know how to actually put my data into an array.

The array that I am suggesting would not be displayed anywhere. Rather you would create an array of load cell objects and iterate through them with a common set of code rather than having code for each of them. It would be possible to put the data received in an array but that was not what I had in mind. Before you can display it you must read the load cells to acquire the data.

Put the idea of using an array of objects aside for now. Have you tried the code that I posted in reply #3 ? I cannot test it as I have neither the library or the load cells.

Does anyone know of a way and can explain how to put the data into an array or in a chart of sorts? This is to separate data coming from each load cell.

Instead of:
Scale1: 2g
Scale2: 5g
Scale1: 3g
Scale2: 6g

I want:
Scale1:2g Scale2: 5g
Scale2:3g Scale2: 6g

Does anyone know of a way and can explain how to put the data into an array or in a chart of sorts? This is to separate data coming from each load cell.

Have you managed to read 2 sensors yet ?

Since this is a school project, I need to go access the items at school so It will take me some time to go and test it. I'll get back to you in 2 weeks to see if it works or not. Thanks for helping out though.

Once you get it working with 2 or more sensors put the data into different variables for each sensor then you can think about how to display it.

In the declaration you can use the sam clock line an separate data lines. I'm on my phone right now but I will post the cod later. I have 16 working on a mega