How to save Load cell data in SD card ?
nyeas001 opened this issue · 2 comments
nyeas001 commented
Hi ,
I am trying to measure load cell value using HX711 and Arduino Uno. I have been using your HX711 library and your examples.
Now, I am facing trouble to save the data in SD card. Here I have attached the code I am currently using. Do you have the code to save data in SD card? Please help.
I really appreciate any kind of help.
Thanks in advance.
/*
-------------------------------------------------------------------------------------
HX711_ADC
Arduino library for HX711 24-Bit Analog-to-Digital Converter for Weight Scales
Olav Kallhovd sept2017
-------------------------------------------------------------------------------------
*/
/*
Settling time (number of samples) and data filtering can be adjusted in the config.h file
For calibration and storing the calibration value in eeprom, see example file "Calibration.ino"
The update() function checks for new data and starts the next conversion. In order to acheive maximum effective
sample rate, update() should be called at least as often as the HX711 sample rate; >10Hz@10SPS, >80Hz@80SPS.
If you have other time consuming code running (i.e. a graphical LCD), consider calling update() from an interrupt routine,
see example file "Read_1x_load_cell_interrupt_driven.ino".
This is an example sketch on how to use this library
*/
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include "RTClib.h"
#include <HX711_ADC.h>
#if defined(ESP8266)|| defined(ESP32) || defined(AVR)
#include <EEPROM.h>
#endif
int row_excel = 0; // number of lines
//pins:
const int HX711_dout = 3; //mcu > HX711 dout pin
const int HX711_sck = 2; //mcu > HX711 sck pin
//HX711 constructor:
HX711_ADC LoadCell(HX711_dout, HX711_sck);
float calibrationValue;
const int calVal_eepromAdress = 0;
unsigned long t = 0;
void setup() {
Serial.begin(115200);
delay(10);
Serial.println();
// Serial.println("Starting...");
LoadCell.begin();
//Serial.println("Press T to tare");
LoadCell.tare();
float calibrationValue; // calibration value (see example file "Calibration.ino")
calibrationValue =122541;//123589.807812;//123589.007812;best for load less then 800 mg
unsigned long stabilizingtime = 20; //2000// preciscion right after power-up can be improved by adding a few seconds of stabilizing time
boolean _tare = true; //set this to false if you don't want tare to be performed in the next step
LoadCell.start(stabilizingtime, _tare);
if (LoadCell.getTareTimeoutFlag()) {
Serial.println("Timeout, check MCU>HX711 wiring and pin designations");
while (1);
Serial.println("Num of Rows,Timer (s),weight (grams)"); // column headers
}
else {
LoadCell.setCalFactor(calibrationValue); // set calibration value (float)
//Serial.println("Startup is complete");
Serial.println("Num of Rows,Timer (s),weight (grams)"); // column headers
}
}
void loop() {
static boolean newDataReady = 0;
const int serialPrintInterval = 0; //increase value to slow down serial print activity
// check for new data/start next conversion:
if (LoadCell.update()) newDataReady = true;
if (newDataReady) {
if (millis() > t + serialPrintInterval) {
float i = LoadCell.getData();
row_excel++; // row number + 1
Serial.print(row_excel);
Serial.print(",");
Serial.print(millis()/1000.000,3); // excel record timer
Serial.print(",");
Serial.println(i*1000, 4); //Up to 3 decimal points
newDataReady = 0;
t = millis();
}
}
// receive command from serial terminal, send 't' to initiate tare operation:
if (Serial.available() > 0) {
char inByte = Serial.read();
if (inByte == 't'|| inByte == 'T') {
LoadCell.tareNoDelay();
}
}
// check if last tare operation is complete:
if (LoadCell.getTareStatus() == true) {
Serial.println("Tare complete");
}
delay(100);
}
olkal commented
Hi
You can install the SdFat library from the Arduino library manager.
There are many examples included on how to save to SD card, like this:
https://github.com/greiman/SdFat/tree/master/examples/examplesV1/ReadWrite
olkal commented
I'm closing this as it's not an issue related to this library + no recent activity.