How to save serial monitor data to SD Card

I have made an arduino scale with the HX711 module and a load cell. I need to save the weight/mass data that appears on the serial monitor to an SD card using the MH-SD Card Module, in order to make it possible for me to generate a graph with the saved data. However I don't know how to do it. The code used for the scale can be found here:

It's the example sketch "Read_1x_load_cell"

(deleted)

Peter-CAD-HST:
Hello pedrokrause
How are you?
Did you ran the IDE examples for the usage of a SD-card shield ?
Best regards
Peter
and stay healthy

Yes, I did test the SD Card and it's functional.

You don't save the serial monitor data to SD, you save the same data you sent to the serial monitor. See the datalogger example in the IDE.

Nick_Pyner:
You don't save the serial monitor data to SD, you save the same data you sent to the serial monitor. See the datalogger example in the IDE.

I've tried to use the code of the datalogger example and I don't see yet how that could help.

I've tried to use the code of the datalogger example and I don't see yet how that could help.

In the code the code you referenced add the printing to the sd file where you print to the serial monitor. Of course you will need to add all the necessary sd code for setup and file creation, etc.

/*
   -------------------------------------------------------------------------------------
   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 <HX711_ADC.h>
#include <EEPROM.h>

//pins:
const int HX711_dout = 4; //mcu > HX711 dout pin
const int HX711_sck = 5; //mcu > HX711 sck pin

//HX711 constructor:
HX711_ADC LoadCell(HX711_dout, HX711_sck);

const int calVal_eepromAdress = 0;
long t;

void setup() {
  Serial.begin(57600); delay(10);
  Serial.println();
  Serial.println("Starting...");

  LoadCell.begin();
  float calibrationValue; // calibration value (see example file "Calibration.ino")
  calibrationValue = 696.0; // uncomment this if you want to set the calibration value in the sketch
#if defined(ESP8266)|| defined(ESP32)
  //EEPROM.begin(512); // uncomment this if you use ESP8266/ESP32 and want to fetch the calibration value from eeprom
#endif
  //EEPROM.get(calVal_eepromAdress, calibrationValue); // uncomment this if you want to fetch the calibration value from eeprom

  long stabilizingtime = 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);
  }
  else {
    LoadCell.setCalFactor(calibrationValue); // set calibration value (float)
    Serial.println("Startup is complete");
  }
}

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;

  // get smoothed value from the dataset:
  if (newDataReady) {
    if (millis() > t + serialPrintInterval) {
      float i = LoadCell.getData();
      Serial.print("Load_cell output val: ");
      Serial.println(i);
      //add SD printing here ************************************
      newDataReady = 0;
      t = millis();
    }
  }

  // receive command from serial terminal, send 't' to initiate tare operation:
  if (Serial.available() > 0) {
    float i;
    char inByte = Serial.read();
    if (inByte == 't') LoadCell.tareNoDelay();
  }

  // check if last tare operation is complete:
  if (LoadCell.getTareStatus() == true) {
    Serial.println("Tare complete");
  }

}

pedrokrause:
I don't see yet how that could help.

I'm afraid words fail me. All that is required is that you print the data to SD

myFile.print(dadedah);

as well as print to serial

Serial.print(dadedah);

Further to that, you might dispense with the SD altogether and send the data to a kosher teminal,, like Realterm, which can record it, even with timestamp included. You may also send data direct to Excel and display graphs therein live. See PLX v2 macro by Netdevil.