Home › Forums › Environmental Sensors › Hydros 21 CTD – Losing connection? [SOLVED]
- This topic has 4 replies, 2 voices, and was last updated 2021-06-03 at 3:47 AM by James_NZ.
-
AuthorPosts
-
-
2021-06-01 at 5:01 PM #15581
Hi all,
I am testing a Mayfly setup with a HYDROS 21 CTD and a Yosemitech 511-A turbidity sensor. The Turbidity sensor is working well, but the CTD seems to intermittently dropping in and out (see attached MMW plots).
Any thoughts on what might cause this? I have set the CTD address to channel 1 as per instructions. I did notice that the ‘sdi12_address_change.ino’ script went haywire until I removed the Modbus WingShield, so I wonder if the Y511-A is interfering with the CTD signal? The Y511-A is set to address 0x01 as per factory settings.
Thanks in advance for your help.
James
Attachments:
-
2021-06-01 at 10:53 PM #15584
Does your Modbus wingshield do any level shifting of the CTD’s SDI-12 data line? Is there anything on the wingshield tied to whatever Mayfly pin you’re using for the data line (I’m assuming D7)?
-
2021-06-01 at 10:59 PM #15585
Hi Shannon,
Yes I am on D7 for the CTD. I am using the default pins for the mayfly modbus wing (https://github.com/EnviroDIY/Mayfly-Modbus-Wing/tree/master/Modbus-Mayfly_WingShield):
1234Communication is hardwired to Mayfly digital pins 5 & 6, which enable use of the AltSoftSerial library.Read more at our Notes on Arduino Streams and Software Serial.Power to the RS485 to TTL Adapter comes from the Mayfly's switched 3.3V power.Power to the sensor(s) comes from the Mayfly's switched 5V power supply, which can then be optionally boosted to 9V or 12V depending on the requirements of the sensor. -
2021-06-02 at 4:49 AM #15586
I have switched my pin for the HYDROS 21 CTD from D7 to D11, but I seem to be having the same issue. It’s worth noting that I don’t get -9999 values when plugged into my computer. Could it have something to do with power?
My code is below.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435/*****************************************************************************simple_logging.inoWritten By: Sara Damiano (sdamiano@stroudcenter.org)Development Environment: PlatformIOHardware Platform: EnviroDIY Mayfly Arduino DataloggerSoftware License: BSD-3.Copyright (c) 2017, Stroud Water Research Center (SWRC)and the EnviroDIY Development TeamThis sketch is an example of logging data to an SD cardDISCLAIMER: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 fileconst char *sketchName = "WEN_Site_01.ino";// Logger ID, also becomes the prefix for the name of the data file on SD cardconst char *LoggerID = "WEN_01_2021";// How frequently (in minutes) to log dataconst 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 debuggingconst 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 1const 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 metadataconst char *mcuBoardVersion = "v0.5b";ProcessorStats mcuBoard(mcuBoardVersion);// ==========================================================================// Wifi/Cellular Modem Settings// ==========================================================================// Create a reference to the serial port for the modemHardwareSerial &modemSerial = Serial1; // Use hardware serial if possible// Modem Pins - Describe the physical pin connection of your modem to your boardconst 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 statusconst 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 informationconst 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 defaultconst 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 necessaryDigiXBeeLTEBypass 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 CTDconst uint8_t CTDNumberReadings = 6; // The number of readings to averageconst int8_t CTDPower = sensorPowerPin; // Power pin (-1 if unconnected)const int8_t CTDData = 11; // The SDI12 data pin// Create a Decagon CTD sensor objectDecagonCTD 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 ATMEGA2560HardwareSerial& y511modbusSerial = Serial2; // Use hardware serial if possible#elseAltSoftSerial& y511modbusSerial = altSoftSerial; // For software serial// NeoSWSerial& y511modbusSerial = neoSSerial1; // For software serial#endifbyte y511ModbusAddress = 0x01; // The modbus address of the Y511const int8_t y511AdapterPower =sensorPowerPin; // RS485 adapter power pin (-1 if unconnected)const int8_t y511SensorPower = -1; // Sensor power pinconst 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 objectYosemitechY511 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,"ad1e7a6a-414b-4cb5-86c6-69a7c54080bd"),new MaximDS3231_Temp(&ds3231,"846f84dc-4455-47f3-bd38-51a21e20fa50"),new DecagonCTD_Cond(&ctd, "1ce4a66a-3ba3-4a00-a1dd-11b1c96c5e32"),new DecagonCTD_Temp(&ctd, "e888701f-8de7-449b-8e91-6902e289e026"),new DecagonCTD_Depth(&ctd, "faecb826-a197-4047-8b6a-21e22ab4913c"),new YosemitechY511_Turbidity(&y511, "8b4ac069-8edb-4780-bf1c-ba6006f29851"),new YosemitechY511_Temp(&y511, "7b9f9978-e3d1-46ed-8695-397972db3893")// 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 arrayint variableCount = sizeof(variableList) / sizeof(variableList[0]);// Create the VariableArray objectVariableArray varArray(variableCount, variableList);// ==========================================================================// The Logger Object[s]// ==========================================================================// Create a logger instanceLogger 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.orgconst char *registrationToken = "bb4be033-adea-475c-a4ad-17ce67fc0c58"; // Device registration tokenconst char *samplingFeature = "03b56716-e87d-47cf-9952-10aec25d886f"; // 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 boardvoid 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 bufferint getMedianNum(int bArray[], int iFilterLen){ int bTab[iFilterLen];for (byte i = 0; i<iFilterLen; i++)bTab[i] = bArray[i]; // copy input array into BTab[] arrayint 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 valueelsebTemp = (bTab[iFilterLen / 2] + bTab[iFilterLen / 2 - 1]) / 2; // if even then take aveage of two central valuesreturn 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_USBVIRTUALwhile (!SERIAL_PORT_USBVIRTUAL && (millis() < 10000)){}#endif// Start the primary serial connectionSerial.begin(serialBaud);// Print a start-up note to the first serial portSerial.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_henableInterrupt(softSerialRx, SoftwareSerial_ExtInts::handle_interrupt, CHANGE);#endif#if defined NeoSWSerial_henableInterrupt(neoSSerial1Rx, neoSSerial1ISR, CHANGE);#endif// Start the serial connection with the modemmodemSerial.begin(modemBaud);// Start the stream for the modbus sensors; all currently supported modbus sensors use 9600 baudy511modbusSerial.begin(9600);// Set up pins for the LED'spinMode(greenLED, OUTPUT);digitalWrite(greenLED, LOW);pinMode(redLED, OUTPUT);digitalWrite(redLED, LOW);// Blink the LEDs to show the board is on and starting upgreenredflash();// Set the timezones for the logger/data and the RTC// Logging in the given time zoneLogger::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 loggerdataLogger.attachModem(modem);modem.setModemLED(modemLEDPin);dataLogger.setLoggerPins(wakePin, sdCardSSPin, sdCardPwrPin, buttonPin, greenLED);// Begin the loggerdataLogger.begin();// Note: Please change these battery voltages to match your battery// Set up the sensors, except at lowest battery levelif (getBatteryVoltage() > 3.4){Serial.println(F("Setting up sensors..."));varArray.setupSensors();}// Sync the clock if it isn't valid or we have battery to spareif (getBatteryVoltage() > 3.55 || !dataLogger.isRTCSane()){// Synchronize the RTC with NIST// This will also set up the modemdataLogger.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 updataLogger.createLogFile(true); // true = write a new headerdataLogger.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); // <- AddeddigitalWrite(modemSleepRqPin, HIGH); // <- Added}// Call the processor sleepSerial.println(F("Putting processor to sleep\n"));dataLogger.systemSleep();}// ==========================================================================// Main loop function// ==========================================================================// Use this short loop for simple data logging and sendingvoid loop(){// Note: Please change these battery voltages to match your battery// At very low battery, just go back to sleepif (getBatteryVoltage() < 3.4){dataLogger.systemSleep();}// At moderate voltage, log data but don't send it over the modemelse if (getBatteryVoltage() < 3.55){dataLogger.logData();}// If the battery is good, send the data to the worldelse{dataLogger.logDataAndPublish();}} -
2021-06-03 at 3:47 AM #15587
I had a lightbulb moment today that seems to have fixed my problem. I switched the 3.3v jumper to 5v. Success!! I guess it was brown-out.
James
-
-
AuthorPosts
- You must be logged in to reply to this topic.