/*
LiquidCrystal Library - display() and noDisplay()
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
library works with all LCD displays that are compatible with the
Hitachi HD44780 driver. There are many of them out there, and you
can usually tell them by the 16-pin interface.
This sketch prints "Hello World!" to the LCD and uses the
display() and noDisplay() functions to turn on and off
the display.
The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 4
* LCD D5 pin to digital pin 5
* LCD D6 pin to digital pin 6
* LCD D7 pin to digital pin 7
* LCD R/W pin to ground
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
Library originally added 18 Apr 2008
by David A. Mellis
library modified 5 Jul 2009
by Limor Fried (http://www.ladyada.net)
example added 9 Jul 2009
by Tom Igoe
modified 22 Nov 2010
by Tom Igoe
modified 7 Nov 2016
by Arturo Guadalupi
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/LiquidCrystalDisplay
*/
// include the library code:
#include <LiquidCrystal.h>
#include "HX711.h"
#include <SD.h>
#include "RTClib.h"
#include <EEPROM.h>
#define calibration_factor 697.05 //This value is obtained using the SparkFun_HX711_Calibration sketch
#define LOADCELL_DOUT_PIN 2
#define LOADCELL_SCK_PIN 3
HX711 scale;
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 9, en = 8, d4 = 7, d5 = 6, d6 = 5, d7 = 4;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
String filename;
File myFile;
RTC_PCF8523 rtc;
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Starting...");
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
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:");
Serial.begin(9600);
Serial.println("test");
lcd.println("Init SD Card...");
pinMode(10, OUTPUT);
if (!SD.begin(10)){
lcd.println("Init failed");
return;
}
lcd.println("Init done");
#ifndef ESP8266
while (!Serial); // wait for serial port to connect. Needed for native USB
#endif
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
while (1) delay(10);
}
if (! rtc.initialized() || rtc.lostPower()) {
Serial.println("RTC is NOT initialized, let's set the time!");
// When time needs to be set on a new device, or after a power loss, the
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
//
// Note: allow 2 seconds after inserting battery or applying external power
// without battery before calling adjust(). This gives the PCF8523's
// crystal oscillator time to stabilize. If you call adjust() very quickly
// after the RTC is powered, lostPower() may still return true.
}
rtc.start();
DateTime now = rtc.now();
filename = "T-" + String(now.hour()) + String(now.minute()) + String(now.second()) + ".csv";
myFile = SD.open( filename, FILE_WRITE);
if (myFile){
Serial.println("success");
}
else{
Serial.println("fail");
}
myFile.print("Thrust test, values in grams(g)\n");
myFile.close();
}
void loop() {
myFile = SD.open(filename, FILE_WRITE);
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Reading: ");
lcd.println(scale.get_units(), 1); //scale.get_units() returns a float
lcd.print(" g"); //You can change this to kg but you'll need to refactor the calibration_factor
lcd.println();
myFile.print(String(scale.get_units()) + '\n');
delay(500);
myFile.close();
}