Forum Replies Created
-
AuthorPosts
-
Which hardware version of the Mayfly board are you using this sketch on?
As long as the cards are formatted for FAT32 and you can read/write to them with other Mayfly boards or Windows devices, then it’s possible the on-board memory card socket on that Mayfly is broken. Is this a brand new board that you’re using a card in for the first time? If you’ve got an EnviroDIY vertical microSD adapter you could try putting that on the Mayfly to see if a card will work in there, but sometimes we’ve found that the defect in the on-board socket causes the vertical adapter to also not work properly (because they both essentially share the same pins). You can email me at mayfly@envirodiy.org and we can arrange the warranty support.
I use pin 22 on line 145 because I’m using a prototype Mayfly board that is able to generate 12v to directly power the external sensors. If you’re using an external 12v source for your sensors, then it’s fine to put -1 on line 145. And I’m using a Max13412 RS-485 chip on my modbus adapter, which has auto direction control and internal 5v generation, which makes it easy to connect since it only needs a single 12v supply, but the auto direction control means I can set line 146 to -1 also. In my experimenting, I found that communicating with this chip using pins 5 and 6 using AltSoftSerial was the most reliable way to do it, so that’s why my code looks like it does. There’s probably other ways to do it, but this method has been very stable so far.
I looked at your sketch, it’s based on some really old examples we published many years ago at the beginning of the Mayfly project, but it should still work if you’ve got all the original old libraries. Many of them have been replaced or updated since then, and major changes were made to the Mayfly board design in recent years, making some of your code slightly incompatible with the Mayfly 1.0 and 1.1 boards.
But as for the differential ADS1115 analog readings for a self-powered sensor like the SQ-110, your code looks correct. Have you tried removing the sensor and connecting something with a known voltage (below 3.3v) to see what readings you get? For example, with the sensor removed from the logger, connect a standard AA battery to the two aux analog pins of the Mayfly so that the Mayfly will read the battery voltage (around 1.6v for a new AA battery). Your code line 554 would then measure about 8526 bits. Line 555 would convert that to voltage (in millivolts), which would be 1598.63 mV. Then line 556 would convert that to quantum flux units by multiplying it by 5, resulting in approximately 7993. (this is a number way higher than you’d see in the real world because the unamplified quantum sensor has a max output of 800 mV, but simulating an analog sensor by using a single battery is an easy way to test wiring or code to make sure everything is correct before using a real sensor.)
You could also try connecting a standard voltmeter (like a handheld digital multimeter) to your sensor wires (when not connected to a Mayfly or anything else) on a sunny day and see if it reads close to full scale (500-800 mv).
Thanks for posting your code, I edited your post to put it into the “code formatting” window that you can use when pasting code into our forum. It’s the little unlabled icon that looks like this: “<>” in the toolbar above the text entry box.
Your issue is caused by an error on line 186. It should look like this:
Arduino1new CampbellClariVUE10_Turbidity(&clarivue),You can also include another variable to report the Clarivue temperature (because the sensor also reports water temperature) by adding this line to your variable list:
Arduino1new CampbellClariVUE10_Temp(&clarivue),I haven’t published the official example code for using a ClariVUE10 sensor yet because they haven’t added the sensor to the list of supported sensors on the MonitorMyWatershed website. Once it gets added to MMW, I will publish the example, but it’s essentially exactly what you have above, minus the ES2 sensor, and with the correct variable declaration that I just posted here.
When you power up the ClariVUE10 sensor, we’ve found that it take a few seconds to warm up before the Mayfly can “see” it. So when that sketch cycles through all of the available numbers and letters, it usually doesn’t see the ClariVUE until the second loop through.
So when you first connect the sensor from the factory and run the sketch, it’ll run through one full loop before finding it on address “0”. Then you can either leave it there or enter another address, in your case “2”. Then it should go through the loop check again and say that it found the sensor on address “2”. If you run that sketch at any time or the “c_check_all_addresses” sketch, it should always find the sensor at address 2. If that’s all correct, then the issue is just with your logging sketch. You can post it here if you want, just be sure to edit out any personal information like UUIDs or wifi APN info.
For the past year we’ve had 8 stations using SDI12 CTD sensors and Yosemitech wipered turbidity sensors together on one prototype Mayfly using the EnviroDIY RS-485 half-shield. It also works with other generic modbus adapters too. We’ve had no issues with not being able to read the sensors or with dropped readings. I’m attaching the code below so you can see how I arranged my sketch. I don’t know what modbus sensors you’re using but I assume they are ones already included in our library?
Arduino123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393/** =========================================================================* @file mayfly1_y511turbidity_example.ino* @brief Example for Mayfly v1.0 revA turbidity logger.** This example shows proper settings for the following configuration:** Mayfly v1.0 revA board only* EnviroDIY RS-485 half-shield* EnviroDIY Sim7080 LTE Bee module* Yosemitech Y511A turbidity sensor* Hydros21 CTD sensor* ======================================================================= */// ==========================================================================// Defines for the Arduino IDE// NOTE: These are ONLY needed to compile with the Arduino IDE.// If you use PlatformIO, you should set these build flags in your// platformio.ini// ==========================================================================/** Start [defines] */#ifndef TINY_GSM_RX_BUFFER#define TINY_GSM_RX_BUFFER 64#endif#ifndef TINY_GSM_YIELD_MS#define TINY_GSM_YIELD_MS 2#endif/** End [defines] */// ==========================================================================// Include the libraries required for any data logger// ==========================================================================/** Start [includes] */// The Arduino library is needed for every Arduino program.#include <Arduino.h>// EnableInterrupt is used by ModularSensors for external and pin change// interrupts and must be explicitly included in the main program.#include <EnableInterrupt.h>// Include the main header for ModularSensors#include <ModularSensors.h>/** End [includes] */#include <AltSoftSerial.h>AltSoftSerial altSoftSerial(6,5); // the EnviroDIY RS-485 half-shield uses pins 5 and 6#define modbusSerial altSoftSerial // For AltSoftSerial// ==========================================================================// Data Logging Options// ==========================================================================/** Start [logging_options] */// The name of this program fileconst char* sketchName = "mayfly1_ctd_y511modbus_LTE_example.ino";// Logger ID, also becomes the prefix for the name of the data file on SD cardconst char* LoggerID = "ExampleLogger";// How frequently (in minutes) to log dataconst uint8_t loggingInterval = 10;// Your logger's timezone.const int8_t timeZone = -5; // Eastern Standard Time// NOTE: Daylight savings time will not be applied! Please use standard time!// Set the input and output pins for the logger// NOTE: Use -1 for pins that do not applyconst int32_t serialBaud = 57600; // Baud rate for debuggingconst int8_t greenLED = 8; // Pin for the green LEDconst int8_t redLED = 9; // Pin for the red LEDconst int8_t buttonPin = 21; // Pin for debugging mode (ie, button pin)const int8_t wakePin = 31; // MCU interrupt/alarm pin to wake from sleep// Mayfly 0.x D31 = A7// 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 pinconst int8_t sdCardSSPin = 12; // SD card chip select/slave select pinconst int8_t sensorPowerPin = 22; // MCU pin controlling main sensor power/** End [logging_options] */#define modemSerial Serial1// ==========================================================================/** Start [sim_com_sim7080] */// For almost anything based on the SIMCom SIM7080G#include <modems/SIMComSIM7080.h>// Create a reference to the serial port for the modemHardwareSerial& modemSerial = Serial1; // Use hardware serial if possibleconst int32_t modemBaud = 9600; // SIM7080 does auto-bauding by default, but// for simplicity we set to 9600// Modem Pins - Describe the physical pin connection of your modem to your board// NOTE: Use -1 for pins that do not applyconst int8_t modemVccPin = 18;// MCU pin controlling modem power --- Pin 18 is the power enable pin for the// bee socket on Mayfly v1.0, use -1 if using Mayfly 0.5b or if the bee socket// is constantly powered (ie you changed SJ18 on Mayfly 1.x to 3.3v)const int8_t modemStatusPin = 19; // MCU pin used to read modem statusconst int8_t modemSleepRqPin = 23; // MCU pin for modem sleep/wake requestconst int8_t modemLEDPin = redLED; // MCU pin connected an LED to show modem// status// Network connection informationconst char* apn ="hologram"; // APN connection name, typically Hologram unless you have a// different provider's SIM card. Change as needed// Create the modem objectSIMComSIM7080 modem7080(&modemSerial, modemVccPin, modemStatusPin,modemSleepRqPin, apn);// Create an extra reference to the modem by a generic nameSIMComSIM7080 modem = modem7080;/** End [sim_com_sim7080] */// ==========================================================================// Using the Processor as a Sensor// ==========================================================================/** Start [processor_sensor] */#include <sensors/ProcessorStats.h>// Create the main processor chip "sensor" - for general metadataconst char* mcuBoardVersion = "v1.0";ProcessorStats mcuBoard(mcuBoardVersion);/** End [processor_sensor] */// ==========================================================================// Maxim DS3231 RTC (Real Time Clock)// ==========================================================================/** Start [ds3231] */#include <sensors/MaximDS3231.h>// Create a DS3231 sensor objectMaximDS3231 ds3231(1);/** End [ds3231] *///----------------------------------------------------------------------------#include <sensors/YosemitechY511.h>// NOTE: Extra hardware and software serial ports are created in the "Settings// for Additional Serial Ports" sectionbyte y511ModbusAddress = 0x01; // The modbus address of the Y511const int8_t y511AdapterPower = sensorPowerPin; // RS485 adapter power pin (-1 if unconnected)const int8_t y511SensorPower = 22; // 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, modbusSerial, y511AdapterPower,y511SensorPower, y511EnablePin, y511NumberReadings);// ==========================================================================// Meter Hydros 21 Conductivity, Temperature, and Depth Sensor// ==========================================================================/** Start [hydros21] */#include <sensors/MeterHydros21.h>const char* hydrosSDI12address = "1"; // The SDI-12 Address of the Hydros 21const uint8_t hydrosNumberReadings = 6; // The number of readings to averageconst int8_t SDI12Power = sensorPowerPin; // Power pin (-1 if unconnected)const int8_t SDI12Data = 7; // The SDI12 data pin// Create a Meter Hydros 21 sensor objectMeterHydros21 hydros(*hydrosSDI12address, SDI12Power, SDI12Data,hydrosNumberReadings);/** End [hydros21] */// ==========================================================================// Creating the Variable Array[s] and Filling with Variable Objects// ==========================================================================/** Start [variable_arrays] */Variable* variableList[] = {new MeterHydros21_Cond(&hydros),new MeterHydros21_Depth(&hydros),new MeterHydros21_Temp(&hydros),new YosemitechY511_Temp(&y511),new YosemitechY511_Turbidity(&y511),new ProcessorStats_Battery(&mcuBoard),new MaximDS3231_Temp(&ds3231),new Modem_SignalPercent(&modem),};// All UUID's, device registration, and sampling feature information can be// pasted directly from Monitor My Watershed. To get the list, click the "View// token UUID list" button on the upper right of the site page.// *** 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{"12345678-abcd-1234-ef00-1234567890ab", // Specific conductance (Meter_Hydros21_Cond)"12345678-abcd-1234-ef00-1234567890ab", // Water depth (Meter_Hydros21_Depth)"12345678-abcd-1234-ef00-1234567890ab", // Temperature (Meter_Hydros21_Temp)"12345678-abcd-1234-ef00-1234567890ab", // Temperature (YosemiTech_Y511-A_Temp)"12345678-abcd-1234-ef00-1234567890ab", // Turbidity (YosemiTech_Y511-A_Turbidity)"12345678-abcd-1234-ef00-1234567890ab", // Battery voltage (EnviroDIY_Mayfly_Batt)"12345678-abcd-1234-ef00-1234567890ab", // Temperature (Maxim_DS3231_Temp)"12345678-abcd-1234-ef00-1234567890ab" // Percent full scale (Cellular_SignalPercent)};const char *registrationToken = "12345678-abcd-1234-ef00-1234567890ab"; // Device registration tokenconst char *samplingFeature = "12345678-abcd-1234-ef00-1234567890ab"; // Sampling feature UUID// Count up the number of pointers in the arrayint variableCount = sizeof(variableList) / sizeof(variableList[0]);// Create the VariableArray objectVariableArray varArray(variableCount, variableList, UUIDs);/** End [variable_arrays] */// ==========================================================================// The Logger Object[s]// ==========================================================================/** Start [loggers] */// Create a new logger instanceLogger dataLogger(LoggerID, loggingInterval, &varArray);/** End [loggers] */// ==========================================================================// Creating Data Publisher[s]// ==========================================================================/** Start [publishers] */// Create a data publisher for the Monitor My Watershed/EnviroDIY POST endpoint#include <publishers/EnviroDIYPublisher.h>EnviroDIYPublisher EnviroDIYPOST(dataLogger, &modem.gsmClient,registrationToken, samplingFeature);/** End [publishers] */// ==========================================================================// Working Functions// ==========================================================================/** Start [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);}// Reads 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];}// ==========================================================================// Arduino Setup Function// ==========================================================================/** Start [setup] */void setup() {// 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();// Start the serial connection with the modemmodemSerial.begin(modemBaud);// 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();pinMode(20, OUTPUT); // for proper operation of the onboard flash memory// chip's ChipSelect (Mayfly v1.0 and later)altSoftSerial.begin(9600); //needed for proper operation of the EnviroDIY RS-485 half-shieldmodbusSerial.begin(9600);// 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();}/** Start [setup_sim7080] */modem.setModemWakeLevel(HIGH); // ModuleFun Bee inverts the signalmodem.setModemResetLevel(HIGH); // ModuleFun Bee inverts the signalSerial.println(F("Waking modem and setting Cellular Carrier Options..."));modem.modemWake(); // NOTE: This will also set up the modemmodem.gsmModem.setBaud(modemBaud); // Make sure we're *NOT* auto-bauding!modem.gsmModem.setNetworkMode(38); // set to LTE only// 2 Automatic// 13 GSM only// 38 LTE only// 51 GSM and LTE onlymodem.gsmModem.setPreferredMode(1); // set to CAT-M// 1 CAT-M// 2 NB-IoT// 3 CAT-M and NB-IoT/** End [setup_sim7080] */// 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}// Call the processor sleepSerial.println(F("Putting processor to sleep\n"));dataLogger.systemSleep();}/** End [setup] */// ==========================================================================// Arduino Loop Function// ==========================================================================/** Start [loop] */// 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();}}/** End [loop] */When you changed the SDI12 address of the turbidity sensor to “2”, did you use the same Mayfly board and the “SDI12/b_address_change” example sketch that comes with our libraries, or did you change the address with a different board or instrument?
The only difference between the Gen 1 and 2 Hydros21 sensors is that the Gen 2 sensors need a little more time to respond to the SDI12 measurement command, which is hardcoded into one line in the MeterHydros21.h file within the ModularSensors library. If you’re using the most recent version of ModularSensors, then your code will support both generations of sensors. But the SDI12 library is a separate library from ModularSensors and is very complex and handles things like interrupts and timing that can break if not used correctly, or it could also conflict with other libraries or functions if they’re not compatible. I didn’t check the rest of your code, but I’ve successfully used over a dozen Hydros21 sensors simultaneously with one Mayfly board before with all the sensors connected to D7, but the most important thing is to verify that each sensor has had its SDI12 address changed individually to a unique number prior to connecting them all to a logger with a sketch that is communicating with all of them at once.
From the sketch, it looks like you’re trying to operate both sensors on the same logger by using a separate data pins for each sensors? That’s not the correct way to do it because of how the underlying EnviroDIY SDI12 library functions. You should instead put both sensors on the same data line (usually D7). Each sensor will need its own unique address, and it looks like you’re using 1 and 7 for your addresses, so once the sensors have different addresses, they can share the same data pin with up to 62 total devices, as long as each device has a unique address. There are 2 identical grove jacks on the latest Mayfly boards for SDI-12 ( D4-7) for people who want to easily connect 2 SDI12 sensors at the same time. Otherwise you’ll need a grove branch cablelike this one: https://www.seeedstudio.com/Grove-Branch-Cable-5PCs-pack.html
Once you’ve got the 2 sensors connected, then just simply the code by combining the constants named “hydros21Data_x” on lines 149 and 150 of your sketch to just one constant on pin 7 and then make sure the objects on lines 155 and 157 point to that one constant.
-
AuthorPosts