Saving load cell reading to SD card

Hi all,

I am currently trying to learn about arduino but ended up with a problem while trying to save the data measured by the loadcell to an SD card.

From what I understand I need to save the values read by the load cell and turn them into an integer.

Could someone guide me on how I can do this?

Thanks

Usually, the signal from a Load Cell enters into a 24-bit Serial ADC. The Library function collects the data, processes it, and then saves it in a variable. What is the declaration of this variable? You can easily save that value in the SD Card.

You may follow this link for basic data read/write operation with SD Card.

I attached a photo showing part of my code as well as the library i used for the load cell (HX711.h)

I did understand that I need to make reference to the variable, but which variable? in the HX711 library there is only serial.print.

what am i missing?

thanks :slight_smile:

Below is the code of the loadcell (without inputting it into the sd card) in case you might need it

#include "HX711.h"
#define calibration_factor 209.0 //This value is obtained using the SparkFun_HX711_Calibration sketch
#define DOUT 30
#define CLK 52
HX711 scale(DOUT, CLK);
void setup() {
Serial.begin(9600);
Serial.println("HX711 scale demo");
scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
scale.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0
Serial.println("Readings:");
}
void loop() {
Serial.print("Reading: ");
Serial.print(scale.get_units(), 1); //scale.get_units() returns a float
Serial.print(" g"); //You can change this to kg but you'll need to refactor the calibration_factor
Serial.println();
}

jra12222:
in the HX711 library there is only serial.print.

what am i missing?

Only the fact that this is simpler than you think. Check the SD examples in the IDE.

Serial,print(variable):
myfile.print(variable):

same variable

The thing is that when i test the load cell on its own i do get a reading, however when i included it together with the coding of the SD card it keeps on reading only '0'

could it be because i'm using SCK pin for both arduino and loadcell?

could it be because i'm using SCK pin for both arduino and loadcell?

Yes. There doesn't seem to be any reason for using an SPI pin as the loadcell clock pin.

1. If you are using Arduino MEGA, the following is the recommended connection between the MEGA and SD Card. (Please recheck yourself the connection; 50, 51, 52 make the SPI Port.)

2. You must include SPI.h Library in your code, which is not there in your codes.

3 You codes contain:

#define DOUT  30
#define CLK  52
HX711 scale(DOUT, CLK);

There is a conflict of pin connection. CLK-pin of the HX711 Module should be moved to some other Pin : say, 32.

1 Like

jra12222:
could it be because i'm using SCK pin for both arduino and loadcell?

Very likely fatal. I understand the sensor is not an SPI device, and therefgore should not be allowed on the SPI bus. The SCK pin does not define it as an SPI device. I imagine there is a swag of alternative pins.....

Thanks everyone! it all worked great! thanks a lot,
May I ask another question? I was under the impression that you had to connect both SCK pins of the load cell and the sd card to a respective SCK pin. However from what you told me, and from what I tried this was not the case.
Does this mean that any port can be turned into a Serial clock? does it need to be digital or can it be analogue as well?
Finally, how do I know when to use an analogue pin and when to use a digital pin?

excuse me for all the stupid questions, im just trying to learn a bit about arduino.

Thanks again to all of you

If you want to read an analogue signal you must use an anaolgue pin, but analogue pins can be used for digital signals.

Does this mean that any port can be turned into a Serial clock?

Pin, not port. And it is NOT a Serial clock. It IS used to clock the data, but not in the same way that Serial clocks data.