#include "HX711.h" #include #include #include "max6675.h" #include #include #include #include //Calibration constant for load cell #define calibration_factor -7050.0 //This value is obtained using the SparkFun_HX711_Calibration sketch //Pin definitions #define PIN1200 9 #define PIN2200 8 #define DOUT 3 #define CLK 2 //Load cell object allocations HX711 scale(DOUT, CLK); HX711 scale200(PIN1200, PIN2200); //LCD Object #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels #define OLED_RESET LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display //OLED Object Adafruit_ssd1306syp display(37,35); //Water value variable int value = 0; //Water level variable int adc_id = 0; //Clock object DS3231 rtc(A4, A5); //Pin allocation for thermocouple int ktcSO = 49; int ktcCS = 47; int ktcCLK = 45; //Constant for sd card const int chipSelect = 53; //Thermocouple object MAX6675 ktc(ktcCLK, ktcCS, ktcSO); void setup() { //Initializes LCD lcd.init(); lcd.backlight(); display.initialize(); //Begins serial output Serial.begin(9600); //Begins SD Card Output pinMode(53, OUTPUT); //Starts day and time clock rtc.begin(); //Initializes date and time //--------------------------- //rtc.setDOW(WEDNESDAY); //rtc.setTime(14,06,20); //rtc.setDate(1,2,2019); //--------------------------- // SD initialization if (!SD.begin(chipSelect)) { Serial.println("Card failed, or not present."); } else { Serial.println("Card initialized"); } //Sets scale calibrations and tares 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 scale200.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch scale200.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0 delay(500); } void loop() { display.clear(); // make a string for assembling the data to log: String dataString = ""; display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(0,0); display.println("Acuitive Technologies"); display.update(); //Sets position and prints date and time lcd.setCursor(0,2); lcd.print(rtc.getDateStr()); lcd.setCursor(0,3); lcd.print(rtc.getTimeStr()); //Adds date and time to datafile string dataString += String(rtc.getDateStr()); dataString += " -- "; dataString += String(rtc.getTimeStr()); dataString += ","; //Sets position and prints load cell 1 value lcd.setCursor(0,1); lcd.print("1: "); lcd.print(scale.get_units(), 1); //Adds load cell value to datafile string float scale1 = scale.get_units(); dataString += String(scale1); dataString += ","; //Sets position and prints load cell 2 value lcd.setCursor(9,1); lcd.print("2: "); lcd.print(scale200.get_units(), 1); //Adds load cell value to datafile string float scale2 = scale200.get_units(); dataString += String(scale2); dataString += ","; //Gets water level and prints to LCD float value = analogRead(adc_id); // get adc value lcd.setCursor(0,0); lcd.print("W: "); lcd.print(value); //Adds water level to datafile string dataString += String(value); dataString += ","; //Sets position and prints temperature in celsius lcd.setCursor(9,0); lcd.print("C: "); lcd.print(ktc.readCelsius()); //Adds temperature to datafile string int ktcread = ktc.readCelsius(); dataString += String(ktcread); //Open datafile File dataFile = SD.open("DataLog.txt", FILE_WRITE); //If the datafile is available, write to it: if (dataFile) { dataFile.println(dataString); dataFile.close(); } //If the file isn't open, pop up an error: else { Serial.println("error opening datalog.txt"); } }