Home › Forums › Mayfly Data Logger › Interference between HYDROS CTD and Yosemitech Turbidity Sensor › Reply To: Interference between HYDROS CTD and Yosemitech Turbidity Sensor
Hi @aufdenkampe,
I have followed your advice and I think this is working, i.e., I am no longer having problems with -9999 values for the CTD.
However, the complex loop code is preventing publication of data to MMW. I’m sure this is something simple, but I can’t seem to figure it out.
I have tracked the issue to line 483 where the code checks to see if the modem is connected to the internet, i.e., ‘if(modem.connectInternet())’. The lights on the modem don’t seem to power up at all, and the loop just continues reading sensor values and storing it on the SD card. Am I missing something in the setup loop?
Thanks again for your help.
James
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 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 |
/***************************************************************************** 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 // ========================================================================== #ifndef TINY_GSM_RX_BUFFER #define TINY_GSM_RX_BUFFER 64 #endif #ifndef TINY_GSM_YIELD_MS #define TINY_GSM_YIELD_MS 2 #endif #ifndef MQTT_MAX_PACKET_SIZE #define MQTT_MAX_PACKET_SIZE 240 #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 //#include <Adafruit_ADS1015.h> //Adafruit_ADS1115 ads; /* Use this for the Mayfly because of the onboard 16-bit ADS1115 */ //#include <AltSoftSerial.h> //#include <YosemitechModbus.h> // ========================================================================== // Data Logger Settings // ========================================================================== // The name of this file const char *sketchName = "08_Kokako.ino"; // Logger ID, also becomes the prefix for the name of the data file on SD card const char *LoggerID = "Kokako"; // How frequently (in minutes) to log data const uint8_t loggingInterval = 2; // Your logger's timezone. const int8_t timeZone = 12; // 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 = A7; // 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 = -1; // MCU pin controlling modem power (-1 if not applicable) //const bool useCTSforStatus = false; // Flag to use the XBee CTS pin for status const int8_t modemStatusPin = 19; // MCU pin used to read modem status (-1 if not applicable) const int8_t modemResetPin = 20; // MCU pin connected to modem reset pin (-1 if unconnected) const int8_t modemSleepRqPin = 23; // MCU pin used for modem sleep/wake request (-1 if not applicable) const int8_t modemLEDPin = redLED; // MCU pin connected an LED to show modem status (-1 if unconnected) // // Network connection information // Network connection information const char *apn = "m2m"; // The APN for the gprs connection // const char *wifiId = "Dare_Family"; // The WiFi access point, unnecessary for gprs // const char *wifiPwd = "119HarveyStreet"; // The password for connecting to WiFi, unnecessary for gprs // ========================================================================== // The modem object // Note: Don't use more than one! // ========================================================================== //#elif defined MS_BUILD_TESTING && defined MS_BUILD_TEST_XBEE_LTE_B // For the u-blox SARA R410M based Digi LTE-M XBee3 // NOTE: According to the manual, this should be less stable than transparent // mode, but my experience is the complete reverse. #include <modems/DigiXBeeLTEBypass.h> //#include <modems/SodaqDigiXBeeLTEBypass.h> const long modemBaud = 9600; // All XBee's use 9600 by default const bool useCTSforStatus = false; // Flag to use the XBee CTS pin for status // NOTE: If possible, use the STATUS/SLEEP_not (XBee pin 13) for status, but // the CTS pin can also be used if necessary DigiXBeeLTEBypass modemXBLTEB(&modemSerial, modemVccPin, modemStatusPin, useCTSforStatus, modemResetPin, modemSleepRqPin, apn); // Create an extra reference to the modem by a generic name (not necessary) DigiXBeeLTEBypass modem = modemXBLTEB; // ========================================================================== // ========================================================================== // 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); // ========================================================================== // Meter Hydros 21 Conductivity, Temperature, and Depth Sensor // ========================================================================== /** Start [hydros21] */ #include <sensors/DecagonCTD.h> const char* CTDSDI12address = "1"; // The SDI-12 Address of the CTD const uint8_t CTDNumberReadings = 6; // The number of readings to average const int8_t CTDPower = sensorPowerPin; // Power pin (-1 if unconnected) const int8_t CTDData = 11; // The SDI12 data pin // Create a Decagon CTD sensor object DecagonCTD ctd(*CTDSDI12address, CTDPower, CTDData, CTDNumberReadings); // Create conductivity, temperature, and depth variable pointers for the CTD //Variable* ctdCond = new DecagonCTD_Cond(&ctd, // "12345678-abcd-1234-ef00-1234567890ab"); //Variable* ctdTemp = new DecagonCTD_Temp(&ctd, // "12345678-abcd-1234-ef00-1234567890ab"); //Variable* ctdDepth = // new DecagonCTD_Depth(&ctd, "12345678-abcd-1234-ef00-1234567890ab"); /** End [hydros21] */ // ========================================================================== // Yosemitech Y511 Turbidity Sensor with Wiper // ========================================================================== /** Start [y511] */ #include <sensors/YosemitechY511.h> #include <AltSoftSerial.h> AltSoftSerial altSoftSerial; // Create a reference to the serial port for modbus // Extra hardware and software serial ports are created in the "Settings for // Additional Serial Ports" section #if defined ARDUINO_ARCH_SAMD || defined ATMEGA2560 HardwareSerial& y511modbusSerial = Serial2; // Use hardware serial if possible #else AltSoftSerial& y511modbusSerial = altSoftSerial; // For software serial // NeoSWSerial& y511modbusSerial = neoSSerial1; // For software serial #endif byte y511ModbusAddress = 0x01; // The modbus address of the Y511 const int8_t y511AdapterPower = sensorPowerPin; // RS485 adapter power pin (-1 if unconnected) const int8_t y511SensorPower = -1; // Sensor power pin const int8_t y511EnablePin = -1; // Adapter RE/DE pin (-1 if not applicable) const uint8_t y511NumberReadings = 5; // The manufacturer recommends averaging 10 readings, but we take 5 to minimize // power consumption // Create a Y511-A Turbidity sensor object YosemitechY511 y511(y511ModbusAddress, y511modbusSerial, y511AdapterPower, y511SensorPower, y511EnablePin, y511NumberReadings); // Create turbidity and temperature variable pointers for the Y511 //Variable* y511Turb = // new YosemitechY511_Turbidity(&y511, "12345678-abcd-1234-ef00-1234567890ab"); //Variable* y511Temp = // new YosemitechY511_Temp(&y511, "12345678-abcd-1234-ef00-1234567890ab"); /** End [y511] */ // ========================================================================== // Creating the Variable Array[s] and Filling with Variable Objects // ========================================================================== Variable *variableList[] = { //new ProcessorStats_SampleNumber(&mcuBoard), //new ProcessorStats_FreeRam(&mcuBoard), new ProcessorStats_Battery(&mcuBoard,"3cafc793-59d4-4a89-aaa4-f0f55aaa2a43"), new MaximDS3231_Temp(&ds3231,"85322878-f3c6-4013-bb70-f5d05a2bd3d4"), new DecagonCTD_Cond(&ctd, "30b1000a-90f3-40e9-8782-0ce03291a89a"), new DecagonCTD_Temp(&ctd, "4940af20-f35f-4d96-9eb4-09064d1ebf6a"), new DecagonCTD_Depth(&ctd, "a72b2617-9d34-43e0-8429-17e817a0d686"), new YosemitechY511_Turbidity(&y511, "6a179ddf-7d16-4b1b-98cd-ab3ed468e70d"), new YosemitechY511_Temp(&y511, "c01965dd-8952-4e0c-9201-f83fcfdc2bc8") // 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(variableCount, variableList); // ========================================================================== // The Logger Object[s] // ========================================================================== // Create a logger instance Logger dataLogger(LoggerID, loggingInterval, &varArray); // ========================================================================== // A Publisher to Monitor My Watershed / EnviroDIY Data Sharing Portal // ========================================================================== // Device registration and sampling feature information can be obtained after // registration at https://monitormywatershed.org or https://data.envirodiy.org const char *registrationToken = "3f8eb19c-11b1-4d81-a80d-e3443728ab03"; // Device registration token const char *samplingFeature = "89551d76-a825-4357-94f2-23aa82b52cfe"; // Sampling feature UUID // const char *UUIDs[] = // UUID array for device sensors // { // "0bc19c50-67d8-4012-9e17-fb32db82f1ca", // Temperature (Maxim_DS18B20_Temp) // "846f84dc-4455-47f3-bd38-51a21e20fa50" // Temperature (Maxim_DS3231_Temp) // }; // 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]; } //Median Funtion // calculate a median for set of values in buffer int getMedianNum(int bArray[], int iFilterLen) { int bTab[iFilterLen]; for (byte i = 0; i<iFilterLen; i++) bTab[i] = bArray[i]; // copy input array into BTab[] array int i, j, bTemp; for (j = 0; j < iFilterLen - 1; j++) // put array in ascending order { for (i = 0; i < iFilterLen - j - 1; i++) { if (bTab[i] > bTab[i + 1]) { bTemp = bTab[i]; bTab[i] = bTab[i + 1]; bTab[i + 1] = bTemp; } } } if ((iFilterLen & 1) > 0) // check to see if iFilterlen is odd or even using & (bitwise AND) i.e if length &AND 1 is TRUE (>0) bTemp = bTab[(iFilterLen - 1) / 2]; // then then it is odd, and should take the central value else bTemp = (bTab[iFilterLen / 2] + bTab[iFilterLen / 2 - 1]) / 2; // if even then take aveage of two central values return bTemp; } //end getmedianNum // ========================================================================== // Main setup function // ========================================================================== void setup() { // Wait for USB connection to be established by PC // NOTE: Only use this when debugging - if not connected to a PC, this // could prevent the script from starting #if defined SERIAL_PORT_USBVIRTUAL while (!SERIAL_PORT_USBVIRTUAL && (millis() < 10000)){} #endif // 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(); // Allow interrupts for software serial #if defined SoftwareSerial_ExtInts_h enableInterrupt(softSerialRx, SoftwareSerial_ExtInts::handle_interrupt, CHANGE); #endif #if defined NeoSWSerial_h enableInterrupt(neoSSerial1Rx, neoSSerial1ISR, CHANGE); #endif // Start the serial connection with the modem modemSerial.begin(modemBaud); // Start the stream for the modbus sensors; all currently supported modbus sensors use 9600 baud y511modbusSerial.begin(9600); // 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 } // Set up some of the power pins so the board boots up with them off // NOTE: This isn't necessary at all. The logger begin() function // should leave all power pins off when it finishes. if (modemVccPin >= 0) { pinMode(modemVccPin, OUTPUT); digitalWrite(modemVccPin, LOW); pinMode(modemSleepRqPin, OUTPUT); // <- Added digitalWrite(modemSleepRqPin, HIGH); // <- Added } // Call the processor sleep Serial.println(F("Putting processor to sleep\n")); dataLogger.systemSleep(); } // ========================================================================== // Main loop function // ========================================================================== /** Start [complex_loop] */ // Use this long loop when you want to do something special // Because of the way alarms work on the RTC, it will wake the processor and // start the loop every minute exactly on the minute. // The processor may also be woken up by another interrupt or level change on a // pin - from a button or some other input. // The "if" statements in the loop determine what will happen - whether the // sensors update, testing mode starts, or it goes back to sleep. void loop() { // Reset the watchdog dataLogger.watchDogTimer.resetWatchDog(); // Assuming we were woken up by the clock, check if the current time is an // even interval of the logging interval // We're only doing anything at all if the battery is above 3.4V if (dataLogger.checkInterval() && getBatteryVoltage() > 3.4) { // Flag to notify that we're in already awake and logging a point Logger::isLoggingNow = true; dataLogger.watchDogTimer.resetWatchDog(); // Print a line to show new reading Serial.println(F("------------------------------------------")); // Turn on the LED to show we're taking a reading dataLogger.alertOn(); // Power up the SD Card, but skip any waits after power up dataLogger.turnOnSDcard(false); dataLogger.watchDogTimer.resetWatchDog(); // Turn on the modem to let it start searching for the network // Only turn the modem on if the battery at the last interval was high // enough // NOTE: if the modemPowerUp function is not run before the // completeUpdate // function is run, the modem will not be powered and will not // return a signal strength reading. if (getBatteryVoltage() > 3.6) modem.modemPowerUp(); // Start the stream for the modbus sensors, if your RS485 adapter bleeds // current from data pins when powered off & you stop modbus serial // connection with digitalWrite(5, LOW), below. // https://github.com/EnviroDIY/ModularSensors/issues/140#issuecomment-389380833 altSoftSerial.begin(9600); // Do a complete update on the variable array. // This this includes powering all of the sensors, getting updated // values, and turing them back off. // NOTE: The wake function for each sensor should force sensor setup // to run if the sensor was not previously set up. varArray.completeUpdate(); dataLogger.watchDogTimer.resetWatchDog(); // Reset modbus serial pins to LOW, if your RS485 adapter bleeds power // on sleep, because Modbus Stop bit leaves these pins HIGH. // https://github.com/EnviroDIY/ModularSensors/issues/140#issuecomment-389380833 digitalWrite(5, LOW); // Reset AltSoftSerial Tx pin to LOW digitalWrite(6, LOW); // Reset AltSoftSerial Rx pin to LOW // Create a csv data record and save it to the log file dataLogger.logToSD(); dataLogger.watchDogTimer.resetWatchDog(); // Connect to the network // Again, we're only doing this if the battery is doing well if (getBatteryVoltage() > 3.55) { // Serial.println(F("Trying to connect to internet-------")); dataLogger.watchDogTimer.resetWatchDog(); if (modem.connectInternet()) { dataLogger.watchDogTimer.resetWatchDog(); // Publish data to remotes Serial.println(F("Modem connected to internet.")); dataLogger.publishDataToRemotes(); // Sync the clock at midnight dataLogger.watchDogTimer.resetWatchDog(); if (Logger::markedEpochTime != 0 && Logger::markedEpochTime % 86400 == 0) { Serial.println(F("Running a daily clock sync...")); dataLogger.setRTClock(modem.getNISTTime()); dataLogger.watchDogTimer.resetWatchDog(); modem.updateModemMetadata(); dataLogger.watchDogTimer.resetWatchDog(); } // Disconnect from the network modem.disconnectInternet(); dataLogger.watchDogTimer.resetWatchDog(); } // Turn the modem off modem.modemSleepPowerDown(); dataLogger.watchDogTimer.resetWatchDog(); } // Cut power from the SD card - without additional housekeeping wait dataLogger.turnOffSDcard(false); dataLogger.watchDogTimer.resetWatchDog(); // Turn off the LED dataLogger.alertOff(); // Print a line to show reading ended Serial.println(F("------------------------------------------\n")); // Unset flag Logger::isLoggingNow = false; } // Check if it was instead the testing interrupt that woke us up if (Logger::startTesting) { // Start the stream for the modbus sensors, if your RS485 adapter bleeds // current from data pins when powered off & you stop modbus serial // connection with digitalWrite(5, LOW), below. // https://github.com/EnviroDIY/ModularSensors/issues/140#issuecomment-389380833 altSoftSerial.begin(9600); dataLogger.testingMode(); } // Reset modbus serial pins to LOW, if your RS485 adapter bleeds power // on sleep, because Modbus Stop bit leaves these pins HIGH. // https://github.com/EnviroDIY/ModularSensors/issues/140#issuecomment-389380833 digitalWrite(5, LOW); // Reset AltSoftSerial Tx pin to LOW digitalWrite(6, LOW); // Reset AltSoftSerial Rx pin to LOW // Call the processor sleep dataLogger.systemSleep(); } |