/** * Read/record temperatures of 6 sensors * DS18B20 using their addresses */ #define DEBUG 1 // set to 1 to trace activity via serial console const char DELIMITER = ','; // value delimiter in file #include #include volatile bool adcDone; ISR(WDT_vect) { Sleepy::watchdogEvent(); } ISR(ADC_vect) { adcDone = true; } #define SLEEP_DURATION 1000 * 0.25 // was 1000ms * 30 in DavidHeafHivesMonitor but changed for this HX711 version /** 4 lines pasted from HX711_ADC example Read_1x_load_cell_pins_3_2_cal_138 */ #include //HX711 constructor (dout pin, sck pin) HX711_ADC LoadCell(3, 2); long t; /** * We need OneWire library to access DS18B20 sensors * the library must be placed in libraries directory * in the sketchs directory of Arduino IDE (settings menu) * * cf: https://github.com/PaulStoffregen/OneWire/archive/master.zip */ #include /** * We also need DallasTemperature library * cf: https://github.com/milesburton/Arduino-Temperature-Control-Library */ #include /* * The data wire of DS18B20 (often yellow?) is wired to pin 8 (D8) of Arduino * a 4,7kOhm resistor is wired between Vcc and D8 */ #define ONE_WIRE_BUS 8 /** * Cretae a oneWire instance to be able to * communicate with OneWire devices * Nb: not only Maxim/Dallas sensors */ OneWire oneWire(ONE_WIRE_BUS); /** * Passing Onewire instance to our new * sensors object DallasTemperature */ DallasTemperature sensors(&oneWire); /** * Each sensors has its own adresses on bus, * cf: https://git.io/vwM2x * to scan the addresses ex: adresse : 0x28, 0x42, 0x6B, 0x1C, 0x07, 0x00, 0x00, 0x34 adresse : 0x28, 0xED, 0x0B, 0x2A, 0x07, 0x00, 0x00, 0x1C adresse : 0x28, 0xF7, 0x9D, 0x29, 0x07, 0x00, 0x00, 0x2B 10 Sensors received unwired 22 November 2017 */ /** DeviceAddress temperature1 {0x28, 0xEE, 0xF2, 0xA2, 0x12, 0x15, 0x01, 0xE7}; DeviceAddress temperature2 {0x28, 0xEE, 0x7B, 0xA6, 0x12, 0x15, 0x01, 0xD1}; DeviceAddress temperature3 {0x28, 0xEE, 0xDC, 0xA8, 0x12, 0x15, 0x01, 0xA6}; DeviceAddress temperature4 {0x28, 0xEE, 0x8E, 0x8E, 0x12, 0x15, 0x01, 0xC9}; DeviceAddress temperature5 {0x28, 0xEE, 0x55, 0xA5, 0x12, 0x15, 0x01, 0x03}; DeviceAddress temperature6 {0x28, 0xEE, 0x35, 0xA2, 0x12, 0x15, 0x01, 0x94}; DeviceAddress temperature7 {0x28, 0xEE, 0xFC, 0xA9, 0x12, 0x15, 0x01, 0xD1}; DeviceAddress temperature8 {0x28, 0xEE, 0xFE, 0x98, 0x12, 0x15, 0x01, 0x95}; DeviceAddress temperature9 {0x28, 0xEE, 0xF4, 0xA2, 0x12, 0x15, 0x01, 0x7B}; */ DeviceAddress temperature10 {0x28, 0xFF, 0x65, 0xAF, 0x00, 0x17, 0x04, 0x5B}; /** * Writing on SD card * * SD card uses SPI bus: * MOSI - pin 11 * MISO - pin 12 * CLK or SCK - pin 13 * CS - pin 4 * * SPI for Serial Peripheral Interface * * created 24 Nov 2010 * modified 9 Apr 2012 * by Tom Igoe * cf: https://www.arduino.cc/en/Tutorial/Datalogger */ #include //#include #include "SdFat.h" SdFat SD; // Arduino Uno pin 4 // cf: https://www.arduino.cc/en/Reference/SPI const int chipSelect = 4; bool sDisReady = false; // only try to write if sd is ready (detected) /** * Tiny RTC module (clock) * * DS3231 on I2C bus * with lithium battery CR1225 * * Arduino I2C port is on * pin A4 and A5 * * Analog pin A5 <-> SCL (blue wire) * Analog pin A4 <-> SDA (green wire) */ #include /** * We are using the library RTClib * cf: https://github.com/adafruit/RTClib/archive/master.zip */ #include "RTClib.h" RTC_DS3231 RTC; void setup(void) { // Serial port initialisation (to communicate with computer) #if DEBUG Wire.begin(); Serial.begin(9600); Serial.println("start"); #endif pinMode(5, OUTPUT); // for blinking LED if(SD.begin(chipSelect)) { sDisReady = true; } // sensors initialisation sensors.begin(); /* The following 7 lines from 'void setup' of Read_1x_load_cell_pins_3_2_cal_138 * Duplicate or irrelevant lines commented out. */ // Serial.begin(9600); // Serial.println("Wait..."); LoadCell.begin(); long stabilisingtime = 2000; // tare preciscion can be improved by adding a few seconds of stabilising time LoadCell.start(stabilisingtime); LoadCell.setCalFactor(20.2); // user set calibration factor (float) // Serial.println("Startup + tare is complete"); } void loop(void) { /* // The following 9 lines from the void loop of HX711_ADC example Read_1x_load_cell_pins_3_2_cal_138 * //update() should be called at least as often as HX711 sample rate; >10Hz@10SPS, >80Hz@80SPS //longer delay in sketch will reduce effective sample rate (be carefull with delay() in loop) LoadCell.update(); //get smoothed value from data set + current calibration factor if (millis() > t + 250) { float i = LoadCell.getData(); Serial.print("Load_cell output val: "); Serial.println(i); t = millis(); } */ /* The HX711 library calculates a running average of 16 weight samples. The following lines update the running average so that when the 16th sample is taken it is up to date. */ LoadCell.update(); Sleepy::loseSomeTime(SLEEP_DURATION); LoadCell.update(); Sleepy::loseSomeTime(SLEEP_DURATION); LoadCell.update(); Sleepy::loseSomeTime(SLEEP_DURATION); LoadCell.update(); Sleepy::loseSomeTime(SLEEP_DURATION); LoadCell.update(); Sleepy::loseSomeTime(SLEEP_DURATION); LoadCell.update(); Sleepy::loseSomeTime(SLEEP_DURATION); LoadCell.update(); Sleepy::loseSomeTime(SLEEP_DURATION); LoadCell.update(); Sleepy::loseSomeTime(SLEEP_DURATION); LoadCell.update(); Sleepy::loseSomeTime(SLEEP_DURATION); LoadCell.update(); Sleepy::loseSomeTime(SLEEP_DURATION); LoadCell.update(); Sleepy::loseSomeTime(SLEEP_DURATION); LoadCell.update(); Sleepy::loseSomeTime(SLEEP_DURATION); LoadCell.update(); Sleepy::loseSomeTime(SLEEP_DURATION); LoadCell.update(); Sleepy::loseSomeTime(SLEEP_DURATION); LoadCell.update(); Sleepy::loseSomeTime(SLEEP_DURATION); String tolog = builString(); #if DEBUG Serial.println(tolog); // send "file line" to computer serial Serial.flush();delay(5); // needed to flush serial when woke up #endif if (sDisReady) { /** * Opening the file * Nb: only one file can be opened * the file name is : journal.csv */ File dataFile = SD.open("journal.csv", FILE_WRITE); // we can write if the file can be open : digitalWrite(5, HIGH); // Turn on the LED if (dataFile) { dataFile.println(tolog); dataFile.close(); digitalWrite(5, LOW); // Turn off the LED //Sleepy::loseSomeTime(8); } } Sleepy::loseSomeTime(12000); // time to sleep. Replaced 'SLEEP_DURATION' in brackets with a value Sleepy::loseSomeTime(30000); Sleepy::loseSomeTime(30000); Sleepy::loseSomeTime(30000); Sleepy::loseSomeTime(30000); Sleepy::loseSomeTime(30000); } /** * we build the string that we will write on sd Card * the output will be a file line * time,t1,t2,t3,t4,t5,t6, */ String builString() { String dataString = buildTime(); dataString += DELIMITER; sensors.requestTemperatures(); // asking temperatures /** * temperature1 is an array of first sensor adresse elements * * cf: https://git.io/vwM2x to scan addresses */ /** SENSORS 1 to 9 NOT USED dataString += String(sensors.getTempC(temperature1)); dataString += DELIMITER; dataString += String(sensors.getTempC(temperature2)); dataString += DELIMITER; dataString += String(sensors.getTempC(temperature3)); dataString += DELIMITER; dataString += String(sensors.getTempC(temperature4)); dataString += DELIMITER; dataString += String(sensors.getTempC(temperature5)); dataString += DELIMITER; dataString += String(sensors.getTempC(temperature6)); dataString += DELIMITER; dataString += String(sensors.getTempC(temperature7)); dataString += DELIMITER; dataString += String(sensors.getTempC(temperature8)); dataString += DELIMITER; dataString += String(sensors.getTempC(temperature9)); dataString += DELIMITER; */ dataString += String(sensors.getTempC(temperature10)); dataString += DELIMITER; // following lines added to original DavidHeafHivesMonitorV1.3 etc from HX711_ADC.ino to add weight value to SD card printout LoadCell.update(); float i = LoadCell.getData(); dataString += i; dataString += DELIMITER; return dataString; } /** * build a string with time */ String buildTime() { String dateString = ""; DateTime now = RTC.now(); dateString += String(now.year()); dateString += "-"; int month = now.month(); if(month<10) { dateString += "0"; } dateString += month; dateString += "-"; int day = now.day(); if(day<10) { dateString += "0"; } dateString += day; dateString += "T"; // need for spreadsheet time format int hour = now.hour(); if(hour<10) { dateString += "0"; } dateString += hour; dateString += ":"; int minute = now.minute(); if(minute<10) { dateString += "0"; } dateString += minute; dateString += ":"; int second = now.second(); if(second<10) { dateString += "0"; } dateString += second; return dateString; }