Home › Forums › Mayfly Data Logger › Low Cost EC sensor Station upgrade › Reply To: Low Cost EC sensor Station upgrade
2020-04-24 at 11:03 AM
#14095
<h4 class=”user-nicename”>@chuckkir</h4>
Thanks Chuck for offering to help with my coding issues. I have two sets of code that I am currently testing with my Low Cost Sensor Station. Simple_logging.ino is working on my mayfly platform which I am using to test the compensation routines to convert the raw data from the AtlasScientific EC sensor and the RTD temperature probe to µS and ºC.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
/***************************************************************************** simple_logging.ino Written By: Sara Damiano (sdamiano@stroudcenter.org) Development Environment: PlatformIO Hardware Platform: EnviroDIY Mayfly Arduino Datalogger Software License: BSD-3. Copyright (c) 2017, Stroud Water Research Center (SWRC) and the EnviroDIY Development Team This sketch is an example of logging data to an SD card DISCLAIMER: THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN. *****************************************************************************/ // ========================================================================== // Defines for the Arduino IDE // In PlatformIO, set these build flags in your platformio.ini // ========================================================================== // ========================================================================== // Include the base required libraries // ========================================================================== #include <Arduino.h> // The base Arduino library #include <EnableInterrupt.h> // for external and pin change interrupts #include <LoggerBase.h> // The modular sensors library // ========================================================================== // Data Logger Settings // ========================================================================== // The name of this file const char *sketchName = "simple_logging.ino"; // Logger ID, also becomes the prefix for the name of the data file on SD card const char *LoggerID = "TestRTD"; // How frequently (in minutes) to log data const uint8_t loggingInterval = 1; // Your logger's timezone. const int8_t timeZone = -5; // Eastern Standard Time // NOTE: Daylight savings time will not be applied! Please use standard time! // ========================================================================== // Primary Arduino-Based Board and Processor // ========================================================================== #include <sensors/ProcessorStats.h> const long serialBaud = 115200; // Baud rate for the primary serial port for debugging const int8_t greenLED = 8; // MCU pin for the green LED (-1 if not applicable) const int8_t redLED = 9; // MCU pin for the red LED (-1 if not applicable) const int8_t buttonPin = 21; // MCU pin for a button to use to enter debugging mode (-1 if not applicable) const int8_t wakePin = 10; // MCU interrupt/alarm pin to wake from sleep // Set the wake pin to -1 if you do not want the main processor to sleep. // In a SAMD system where you are using the built-in rtc, set wakePin to 1 const int8_t sdCardPwrPin = -1; // MCU SD card power pin (-1 if not applicable) const int8_t sdCardSSPin = 12; // MCU SD card chip select/slave select pin (must be given!) const int8_t sensorPowerPin = 22; // MCU pin controlling main sensor power (-1 if not applicable) // Create the main processor chip "sensor" - for general metadata const char *mcuBoardVersion = "v0.5b"; ProcessorStats mcuBoard(mcuBoardVersion); // ========================================================================== // Maxim DS3231 RTC (Real Time Clock) // ========================================================================== #include <sensors/MaximDS3231.h> // Includes wrapper functions for Maxim DS3231 RTC // Create a DS3231 sensor object, using this constructor function: MaximDS3231 ds3231(1); #include <sensors/ExternalVoltage.h> const int8_t ADSPower = sensorPowerPin; // Pin to switch power on and off (-1 if unconnected) const int8_t ADSChannel = 2; // The ADS channel of interest const float dividerGain =1; // Default 1/gain for grove voltage divider is 10x // const uint8_t ADSi2c_addr = 0x48; // The I2C address of the ADS1115 ADC const uint8_t VoltReadsToAvg = 1; // Only read one sample ExternalVoltage extvolt(ADSPower, ADSChannel, dividerGain, 0x48, VoltReadsToAvg); //================================================== // Atlas Scientific EZO //============================================= //#include <sensors/AtlasScientificEC.h> #include <sensors/AtlasScientificpH.h> //create EZO Object //AtlasScientificEC atlasEC(22, 0x64, 5); //I2C for EC = 0x64; pH = 0x63 AtlasScientificpH atlaspH(22, 0x63, 5); /* float calculateVariableValue(void) { float calculatedResult = -9999; // Always safest to start with a bad value calculatedResult = -30.141*extvolt + 75.359; return calculatedResult; } Variable *calculatedVar = new Variable(calculateVariableValue); */ Variable *variableList[] = { new ProcessorStats_SampleNumber(&mcuBoard), new ProcessorStats_FreeRam(&mcuBoard), new ProcessorStats_Battery(&mcuBoard), new MaximDS3231_Temp(&ds3231), new ExternalVoltage_Volt(&extvolt), //new Variable(calculateVariableValue) //new AtlasScientificEC_Cond(&atlasEC), new AtlasScientificpH_pH(&atlaspH), //new MaximDS3231_Temp(analogRead(A0)) // Additional sensor variables can be added here, by copying the syntax // for creating the variable pointer (FORM1) from the <code>menu_a_la_carte.ino</code> example // The example code snippets in the wiki are primarily FORM2. }; // Count up the number of pointers in the array int variableCount = sizeof(variableList) / sizeof(variableList[0]); // Create the VariableArray object VariableArray varArray; // ========================================================================== // The Logger Object[s] // ========================================================================== // Create a logger instance Logger dataLogger; // ========================================================================== // Working Functions // ========================================================================== // Flashes the LED's on the primary board void greenredflash(uint8_t numFlash = 4, uint8_t rate = 75) { for (uint8_t i = 0; i < numFlash; i++) { digitalWrite(greenLED, HIGH); digitalWrite(redLED, LOW); delay(rate); digitalWrite(greenLED, LOW); digitalWrite(redLED, HIGH); delay(rate); } digitalWrite(redLED, LOW); } // ========================================================================== // Main setup function // ========================================================================== void setup() { // Start the primary serial connection Serial.begin(serialBaud); // Print a start-up note to the first serial port Serial.print(F("Now running ")); Serial.print(sketchName); Serial.print(F(" on Logger ")); Serial.println(LoggerID); Serial.println(); Serial.print(F("Using ModularSensors Library version ")); Serial.println(MODULAR_SENSORS_VERSION); // Set up pins for the LED's pinMode(greenLED, OUTPUT); digitalWrite(greenLED, LOW); pinMode(redLED, OUTPUT); digitalWrite(redLED, LOW); // Blink the LEDs to show the board is on and starting up greenredflash(); // Set the timezones for the logger/data and the RTC // Logging in the given time zone Logger::setLoggerTimeZone(timeZone); // It is STRONGLY RECOMMENDED that you set the RTC to be in UTC (UTC+0) Logger::setRTCTimeZone(0); // Set information pins dataLogger.setLoggerPins(wakePin, sdCardSSPin, sdCardPwrPin, buttonPin, greenLED); // Begin the variable array[s], logger[s], and publisher[s] varArray.begin(variableCount, variableList); dataLogger.begin(LoggerID, loggingInterval, &varArray); // Set up the sensors Serial.println(F("Setting up sensors...")); varArray.setupSensors(); // Create the log file, adding the default header to it // Do this last so we have the best chance of getting the time correct and // all sensor names correct dataLogger.createLogFile(true); // true = write a new header // Call the processor sleep dataLogger.systemSleep(); } // ========================================================================== // Main loop function // ========================================================================== void loop() { dataLogger.logData(); } |
Here is the code I currently have deployed on GMI_EC1 and GMI_test which is uploading the raw sensor data to MonMW.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
/***************************************************************************** DWRI_CitSci.ino Written By: Sara Damiano (sdamiano@stroudcenter.org) Development Environment: PlatformIO Hardware Platform: EnviroDIY Mayfly Arduino Datalogger Software License: BSD-3. Copyright (c) 2017, Stroud Water Research Center (SWRC) and the EnviroDIY Development Team This sketch is an example of logging data to an SD card and sending the data to both the EnviroDIY data portal as should be used by groups involved with The William Penn Foundation's Delaware River Watershed Initiative DISCLAIMER: THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN. *****************************************************************************/ // ========================================================================== // Defines for the Arduino IDE // In PlatformIO, set these build flags in your platformio.ini // ========================================================================== #ifndef TINY_GSM_RX_BUFFER #define TINY_GSM_RX_BUFFER 64 #endif #ifndef TINY_GSM_YIELD_MS #define TINY_GSM_YIELD_MS 2 #endif // ========================================================================== // Include the base required libraries // ========================================================================== #include <Arduino.h> // The base Arduino library #include <EnableInterrupt.h> // for external and pin change interrupts #include <LoggerBase.h> // The modular sensors library // ========================================================================== // Data Logger Settings // ========================================================================== // The name of this file const char *sketchName = "DWRI_CitSci.ino"; // Logger ID, also becomes the prefix for the name of the data file on SD card const char *LoggerID = "GMI_EC2"; // How frequently (in minutes) to log data const uint8_t loggingInterval = 5; // Your logger's timezone. const int8_t timeZone = -5; // Eastern Standard Time // NOTE: Daylight savings time will not be applied! Please use standard time! // ========================================================================== // Primary Arduino-Based Board and Processor // ========================================================================== #include <sensors/ProcessorStats.h> const long serialBaud = 115200; // Baud rate for the primary serial port for debugging const int8_t greenLED = 8; // MCU pin for the green LED (-1 if not applicable) const int8_t redLED = 9; // MCU pin for the red LED (-1 if not applicable) const int8_t buttonPin = 21; // MCU pin for a button to use to enter debugging mode (-1 if not applicable) const int8_t wakePin = 10; // MCU interrupt/alarm pin to wake from sleep // Set the wake pin to -1 if you do not want the main processor to sleep. // In a SAMD system where you are using the built-in rtc, set wakePin to 1 const int8_t sdCardPwrPin = -1; // MCU SD card power pin (-1 if not applicable) const int8_t sdCardSSPin = 12; // MCU SD card chip select/slave select pin (must be given!) const int8_t sensorPowerPin = 22; // MCU pin controlling main sensor power (-1 if not applicable) // Create the main processor chip "sensor" - for general metadata const char *mcuBoardVersion = "v0.5b"; ProcessorStats mcuBoard(mcuBoardVersion); // ========================================================================== // Wifi/Cellular Modem Settings // ========================================================================== // Create a reference to the serial port for the modem HardwareSerial &modemSerial = Serial1; // Use hardware serial if possible // Modem Pins - Describe the physical pin connection of your modem to your board const int8_t modemVccPin = 23; // MCU pin controlling modem power (-1 if not applicable) const int8_t modemStatusPin = 19; // MCU pin used to read modem status (-1 if not applicable) const int8_t modemLEDPin = redLED; // MCU pin connected an LED to show modem status (-1 if unconnected) // Network connection information const char *apn = "hologram"; // The APN for the gprs connection // For the Sodaq 2GBee R6 and R7 based on the SIMCom SIM800 // NOTE: The Sodaq GPRSBee doesn't expose the SIM800's reset pin #include <modems/Sodaq2GBeeR6.h> const long modemBaud = 9600; // SIM800 does auto-bauding by default Sodaq2GBeeR6 modem2GB(&modemSerial, modemVccPin, modemStatusPin, apn); // Create an extra reference to the modem by a generic name (not necessary) Sodaq2GBeeR6 modem = modem2GB; // ========================================================================== // Maxim DS3231 RTC (Real Time Clock) // ========================================================================== #include <sensors/MaximDS3231.h> // Create a DS3231 sensor object MaximDS3231 ds3231(1); //================================================== // Atlas Scientific EZO //============================================= #include <sensors/AtlasScientificEC.h> //create EZO Object AtlasScientificEC atlasEC(22, 0x64, 5); // ========================================================================== // Creating the Variable Array[s] and Filling with Variable Objects // ========================================================================== #include <sensors/ExternalVoltage.h> const int8_t ADSPower = sensorPowerPin; // Pin to switch power on and off (-1 if unconnected) const int8_t ADSChannel = 2; // The ADS channel of interest const float dividerGain =1; // Default 1/gain for grove voltage divider is 10x // const uint8_t ADSi2c_addr = 0x48; // The I2C address of the ADS1115 ADC const uint8_t VoltReadsToAvg = 1; // Only read one sample //float testVar = 2.123; // Create an External Voltage sensor object ExternalVoltage extvolt(ADSPower, ADSChannel, dividerGain, 0x48, VoltReadsToAvg); Variable *variableList[] = { new MaximDS3231_Temp(&ds3231), new ProcessorStats_Battery(&mcuBoard), new Modem_RSSI(&modem), new ExternalVoltage_Volt(&extvolt), //Proxy for Senorex RTD Temperature new AtlasScientificEC_Cond(&atlasEC), //raw uncompensated EC // new Modem_SignalPercent(&modem), }; // *** CAUTION --- CAUTION --- CAUTION --- CAUTION --- CAUTION *** // Check the order of your variables in the variable list!!! // Be VERY certain that they match the order of your UUID's! // Rearrange the variables in the variable list if necessary to match! // *** CAUTION --- CAUTION --- CAUTION --- CAUTION --- CAUTION *** const char *UUIDs[] = // UUID array for device sensors { "242afd8d-fa49-4b8e-9a97-17f9c2dd0677", // Temperature (EnviroDIY_Mayfly_Temp) "1aeb9498-66a3-4b68-b41c-0160aa94e627", // Battery voltage (EnviroDIY_Mayfly_Batt) "534a9a46-c122-48ac-892f-e7bd340fdef3", // Received signal strength indication (Sodaq_2GBee_RSSI) "f5d30b8e-fce5-42c8-aad4-530845b5646b", // Temperature (SensorexTemp) "cf26c1bd-2dad-411a-8d2b-4e4b94808084" // Specific conductance (SensorexCond) }; const char *registrationToken = "8cb70410-d480-4a05-a4dd-a810fe816ce6"; // Device registration token const char *samplingFeature = "8f5a37a7-4729-43b5-bdbb-043d6a5ed90e"; // Sampling feature UUID // Count up the number of pointers in the array int variableCount = sizeof(variableList) / sizeof(variableList[0]); // Create the VariableArray object VariableArray varArray(variableCount, variableList, UUIDs); // ========================================================================== // The Logger Object[s] // ========================================================================== // Create a new logger instance Logger dataLogger(LoggerID, loggingInterval, &varArray); // ========================================================================== // A Publisher to WikiWatershed // ========================================================================== // Device registration and sampling feature information can be obtained after // registration at http://data.WikiWatershed.org // Create a data publisher for the EnviroDIY/WikiWatershed POST endpoint #include <publishers/EnviroDIYPublisher.h> EnviroDIYPublisher EnviroDIYPOST(dataLogger, &modem.gsmClient, registrationToken, samplingFeature); // ========================================================================== // Working Functions // ========================================================================== // Flashes the LED's on the primary board void greenredflash(uint8_t numFlash = 4, uint8_t rate = 75) { for (uint8_t i = 0; i < numFlash; i++) { digitalWrite(greenLED, HIGH); digitalWrite(redLED, LOW); delay(rate); digitalWrite(greenLED, LOW); digitalWrite(redLED, HIGH); delay(rate); } digitalWrite(redLED, LOW); } // Read's the battery voltage // NOTE: This will actually return the battery level from the previous update! float getBatteryVoltage() { if (mcuBoard.sensorValues[0] == -9999) mcuBoard.update(); return mcuBoard.sensorValues[0]; } // ========================================================================== // Main setup function // ========================================================================== void setup() { // Start the primary serial connection Serial.begin(serialBaud); // Print a start-up note to the first serial port Serial.print(F("Now running ")); Serial.print(sketchName); Serial.print(F(" on Logger ")); Serial.println(LoggerID); Serial.println(); Serial.print(F("Using ModularSensors Library version ")); Serial.println(MODULAR_SENSORS_VERSION); Serial.print(F("TinyGSM Library version ")); Serial.println(TINYGSM_VERSION); Serial.println(); // Start the serial connection with the modem modemSerial.begin(modemBaud); // Set up pins for the LED's pinMode(greenLED, OUTPUT); digitalWrite(greenLED, LOW); pinMode(redLED, OUTPUT); digitalWrite(redLED, LOW); // Blink the LEDs to show the board is on and starting up greenredflash(); // Set the timezones for the logger/data and the RTC // Logging in the given time zone Logger::setLoggerTimeZone(timeZone); // It is STRONGLY RECOMMENDED that you set the RTC to be in UTC (UTC+0) Logger::setRTCTimeZone(0); // Attach the modem and information pins to the logger dataLogger.attachModem(modem); modem.setModemLED(modemLEDPin); dataLogger.setLoggerPins(wakePin, sdCardSSPin, sdCardPwrPin, buttonPin, greenLED); // Begin the logger dataLogger.begin(); // Note: Please change these battery voltages to match your battery // Set up the sensors, except at lowest battery level if (getBatteryVoltage() > 3.4) { Serial.println(F("Setting up sensors...")); varArray.setupSensors(); } // Sync the clock if it isn't valid or we have battery to spare if (getBatteryVoltage() > 3.55 || !dataLogger.isRTCSane()) { // Synchronize the RTC with NIST // This will also set up the modem dataLogger.syncRTC(); } // Create the log file, adding the default header to it // Do this last so we have the best chance of getting the time correct and // all sensor names correct // Writing to the SD card can be power intensive, so if we're skipping // the sensor setup we'll skip this too. if (getBatteryVoltage() > 3.4) { Serial.println(F("Setting up file on SD card")); dataLogger.turnOnSDcard(true); // true = wait for card to settle after power up dataLogger.createLogFile(true); // true = write a new header dataLogger.turnOffSDcard(true); // true = wait for internal housekeeping after write } // Call the processor sleep Serial.println(F("Putting processor to sleep\n")); dataLogger.systemSleep(); } // ========================================================================== // Main loop function // ========================================================================== // Use this short loop for simple data logging and sending void loop() { // Note: Please change these battery voltages to match your battery // At very low battery, just go back to sleep if (getBatteryVoltage() < 3.4) { dataLogger.systemSleep(); } // At moderate voltage, log data but don't send it over the modem else if (getBatteryVoltage() < 3.55) { dataLogger.logData(); } // If the battery is good, send the data to the world else { dataLogger.logDataAndPublish(); } } |