Home › Forums › Environmental Sensors › Atlas Scientific Code Help
Tagged: Atlas Scientific, code, modular sensors, sensors, variables
- This topic has 0 replies, 1 voice, and was last updated 2021-10-05 at 1:46 PM by Fiona.
-
AuthorPosts
-
-
2021-10-05 at 1:46 PM #16040
Hi All,
I have everything I need to build out a system using the Mayfly and Atlas Scientific sensors, but I am stuck on how to integrate the Atlas Scientific code from menu a la carte into DRWI LTE. An electrical engineering volunteer created a shield that allows us to connect four sensors on their own electrically isolated carrier boards to the system while communicating on I2C. We are using Atlas Sci EZO circuits to include pH, electrical conductivity, dissolved oxygen, and RTD temperature.
Will I simply remove the code for the Campbell OBS 3 and Meter Hydros sensors and paste the code for each EZO circuit from menu a la carte in its place, and then change the “Creating Variable Array and Filling with Variable Objects” section and add my UUIDs? I am unsure what the lines for the Atlas sensors would look like in the variable list. Can anyone advise? I know @adamgold and @w3asa have worked with these sensors – any clues? Any help is much appreciated. Thank you! Fiona
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550/** =========================================================================* @file DRWI_LTE.ino* @brief Example for DRWI CitSci LTE sites.** @author Sara Geleskie Damiano <sdamiano@stroudcenter.org>* @copyright (c) 2017-2020 Stroud Water Research Center (SWRC)* and the EnviroDIY Development Team* This example is published under the BSD-3 license.** Build Environment: Visual Studios Code with PlatformIO* Hardware Platform: EnviroDIY Mayfly Arduino Datalogger** DISCLAIMER:* THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN.* ======================================================================= */// ==========================================================================// 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>// To get all of the base classes for ModularSensors, include LoggerBase.// NOTE: Individual sensor definitions must be included separately.#include <LoggerBase.h>/** End [includes] */// ==========================================================================// Data Logging Options// ==========================================================================/** Start [logging_options] */// The name of this program fileconst char* sketchName = "DRWI_LTE.ino";// Logger ID, also becomes the prefix for the name of the data file on SD cardconst char* LoggerID = "XXXXX";// How frequently (in minutes) to log dataconst 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!// Set the input and output pins for the logger// NOTE: Use -1 for pins that do not applyconst int32_t serialBaud = 115200; // 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 = 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 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] */// ==========================================================================// Wifi/Cellular Modem Options// ==========================================================================/** Start [xbee_cell_transparent] */// For any Digi Cellular XBee's// NOTE: The u-blox based Digi XBee's (3G global and LTE-M global)// are more stable used in bypass mode (below)// The Telit based Digi XBees (LTE Cat1) can only use this mode.#include <modems/DigiXBeeCellularTransparent.h>// Create a reference to the serial port for the modemHardwareSerial& modemSerial = Serial1; // Use hardware serial if possibleconst int32_t modemBaud = 9600; // All XBee's use 9600 by default// 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 = -2; // MCU pin controlling modem powerconst int8_t modemStatusPin = 19; // MCU pin used to read modem statusconst bool useCTSforStatus = false; // Flag to use the modem CTS pin for statusconst int8_t modemResetPin = 20; // MCU pin connected to modem reset pinconst int8_t modemSleepRqPin = 23; // MCU pin for modem sleep/wake requestconst int8_t modemLEDPin = redLED; // MCU pin connected an LED to show modem// status (-1 if unconnected)// Network connection informationconst char* apn = "hologram"; // The APN for the gprs connectionDigiXBeeCellularTransparent modemXBCT(&modemSerial, modemVccPin, modemStatusPin,useCTSforStatus, modemResetPin,modemSleepRqPin, apn);// Create an extra reference to the modem by a generic nameDigiXBeeCellularTransparent modem = modemXBCT;/** End [xbee_cell_transparent] */// ==========================================================================// Using the Processor as a Sensor// ==========================================================================/** Start [processor_sensor] */#include <sensors/ProcessorStats.h>// Create the main processor chip "sensor" - for general metadataconst char* mcuBoardVersion = "v0.5b";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] */#if defined MS_BUILD_TEST_ATLASDO || defined MS_BUILD_TEST_ALL_SENSORS// ==========================================================================// Atlas Scientific EZO-DO Dissolved Oxygen Sensor// ==========================================================================/** Start [atlas_do] */#include <sensors/AtlasScientificDO.h>const int8_t AtlasDOPower = sensorPowerPin; // Power pin (-1 if unconnected)uint8_t AtlasDOi2c_addr = 0x61; // Default for DO is 0x61 (97)// All Atlas sensors have different default I2C addresses, but any of them can// be re-addressed to any 8 bit number. If using the default address for any// Atlas Scientific sensor, you may omit this argument.// Create an Atlas Scientific DO sensor object#ifdef MS_ATLAS_SOFTWAREWIRE// AtlasScientificDO atlasDO(AtlasDOPower, softwareSDA, softwareSCL,// AtlasDOi2c_addr);AtlasScientificDO atlasDO(&softI2C, AtlasDOPower, AtlasDOi2c_addr);#else// AtlasScientificDO atlasDO(AtlasDOPower, AtlasDOi2c_addr);AtlasScientificDO atlasDO(AtlasDOPower);#endif// Create concentration and percent saturation variable pointers for the EZO-DOVariable* atlasDOconc = new AtlasScientificDO_DOmgL(&atlasDO, "12345678-abcd-1234-ef00-1234567890ab");Variable* atlasDOpct = new AtlasScientificDO_DOpct(&atlasDO, "12345678-abcd-1234-ef00-1234567890ab");/** End [atlas_do] */#endif#if defined MS_BUILD_TEST_ATLASPH || defined MS_BUILD_TEST_ALL_SENSORS// ==========================================================================// Atlas Scientific EZO-pH Sensor// ==========================================================================/** Start [atlas_ph] */#include <sensors/AtlasScientificpH.h>const int8_t AtlaspHPower = sensorPowerPin; // Power pin (-1 if unconnected)uint8_t AtlaspHi2c_addr = 0x63; // Default for pH is 0x63 (99)// All Atlas sensors have different default I2C addresses, but any of them can// be re-addressed to any 8 bit number. If using the default address for any// Atlas Scientific sensor, you may omit this argument.// Create an Atlas Scientific pH sensor object#ifdef MS_ATLAS_SOFTWAREWIREAtlasScientificpH atlaspH(&softI2C, AtlaspHPower, AtlaspHi2c_addr);// AtlasScientificpH atlaspH(AtlaspHPower, softwareSDA, softwareSCL,// AtlaspHi2c_addr);#else// AtlasScientificpH atlaspH(AtlaspHPower, AtlaspHi2c_addr);AtlasScientificpH atlaspH(AtlaspHPower);#endif// Create a pH variable pointer for the pH sensorVariable* atlaspHpH =new AtlasScientificpH_pH(&atlaspH, "12345678-abcd-1234-ef00-1234567890ab");/** End [atlas_ph] */#endif#if defined MS_BUILD_TEST_ATLASRTD || defined MS_BUILD_TEST_ATLASEC || \defined MS_BUILD_TEST_ALL_SENSORS// ==========================================================================// Atlas Scientific EZO-RTD Temperature Sensor// ==========================================================================/** Start [atlas_rtd] */#include <sensors/AtlasScientificRTD.h>const int8_t AtlasRTDPower = sensorPowerPin; // Power pin (-1 if unconnected)uint8_t AtlasRTDi2c_addr = 0x66; // Default for RTD is 0x66 (102)// All Atlas sensors have different default I2C addresses, but any of them can// be re-addressed to any 8 bit number. If using the default address for any// Atlas Scientific sensor, you may omit this argument.// Create an Atlas Scientific RTD sensor object#ifdef MS_ATLAS_SOFTWAREWIREAtlasScientificRTD atlasRTD(&softI2C, AtlasRTDPower, AtlasRTDi2c_addr);// AtlasScientificRTD atlasRTD(AtlasRTDPower, softwareSDA, softwareSCL,// AtlasRTDi2c_addr);#else// AtlasScientificRTD atlasRTD(AtlasRTDPower, AtlasRTDi2c_addr);AtlasScientificRTD atlasRTD(AtlasRTDPower);#endif// Create a temperature variable pointer for the RTDVariable* atlasTemp = new AtlasScientificRTD_Temp(&atlasRTD, "12345678-abcd-1234-ef00-1234567890ab");/** End [atlas_rtd] */#endif#if defined MS_BUILD_TEST_ATLASEC || defined MS_BUILD_TEST_ALL_SENSORS// ==========================================================================// Atlas Scientific EZO-EC Conductivity Sensor// ==========================================================================/** Start [atlas_ec] */#include <sensors/AtlasScientificEC.h>const int8_t AtlasECPower = sensorPowerPin; // Power pin (-1 if unconnected)uint8_t AtlasECi2c_addr = 0x64; // Default for EC is 0x64 (100)// All Atlas sensors have different default I2C addresses, but any of them can// be re-addressed to any 8 bit number. If using the default address for any// Atlas Scientific sensor, you may omit this argument.// Create an Atlas Scientific Conductivity sensor object#ifdef MS_ATLAS_SOFTWAREWIRE// AtlasScientificEC atlasEC(AtlasECPower, softwareSDA, softwareSCL,// AtlasECi2c_addr);AtlasScientificEC atlasEC(&softI2C, AtlasECPower, AtlasECi2c_addr);#else// AtlasScientificEC atlasEC(AtlasECPower, AtlasECi2c_addr);AtlasScientificEC atlasEC(AtlasECPower);#endif// Create four variable pointers for the EZO-ESVariable* atlasCond = new AtlasScientificEC_Cond(&atlasEC, "12345678-abcd-1234-ef00-1234567890ab");Variable* atlasTDS =new AtlasScientificEC_TDS(&atlasEC, "12345678-abcd-1234-ef00-1234567890ab");Variable* atlasSal = new AtlasScientificEC_Salinity(&atlasEC, "12345678-abcd-1234-ef00-1234567890ab");Variable* atlasGrav = new AtlasScientificEC_SpecificGravity(&atlasEC, "12345678-abcd-1234-ef00-1234567890ab");// Create a calculated variable for the temperature compensated conductivity// (that is, the specific conductance). For this example, we will use the// temperature measured by the Atlas RTD above this. You could use the// temperature returned by any other water temperature sensor if desired.// **DO NOT** use your logger board temperature (ie, from the DS3231) to// calculate specific conductance!float calculateAtlasSpCond(void) {float spCond = -9999; // Always safest to start with a bad valuefloat waterTemp = atlasTemp->getValue();float rawCond = atlasCond->getValue();// ^^ Linearized temperature correction coefficient per degrees Celsius.// The value of 0.019 comes from measurements reported here:// Hayashi M. Temperature-electrical conductivity relation of water for// environmental monitoring and geophysical data inversion. Environ Monit// Assess. 2004 Aug-Sep;96(1-3):119-28.// doi: 10.1023/b:emas.0000031719.83065.68. PMID: 15327152.if (waterTemp != -9999 && rawCond != -9999) {// make sure both inputs are goodfloat temperatureCoef = 0.019;spCond = rawCond / (1 + temperatureCoef * (waterTemp - 25.0));}return spCond;}// Properties of the calculated variable// The number of digits after the decimal placeconst uint8_t atlasSpCondResolution = 0;// This must be a value from http://vocabulary.odm2.org/variablename/const char* atlasSpCondName = "specificConductance";// This must be a value from http://vocabulary.odm2.org/units/const char* atlasSpCondUnit = "microsiemenPerCentimeter";// A short code for the variableconst char* atlasSpCondCode = "atlasSpCond";// The (optional) universallly unique identifierconst char* atlasSpCondUUID = "12345678-abcd-1234-ef00-1234567890ab";// Finally, create the specific conductance variable and return a pointer to itVariable* atlasSpCond =new Variable(calculateAtlasSpCond, atlasSpCondResolution, atlasSpCondName,atlasSpCondUnit, atlasSpCondCode, atlasSpCondUUID);/** End [atlas_ec] */#endif// ==========================================================================// Creating the Variable Array[s] and Filling with Variable Objects// ==========================================================================/** Start [variable_arrays] */Variable* variableList[] = {// new DecagonCTD_Cond(&ctd),// new DecagonCTD_Temp(&ctd),// new DecagonCTD_Depth(&ctd),// new CampbellOBS3_Turbidity(&osb3low, "", "TurbLow"),// new CampbellOBS3_Turbidity(&osb3high, "", "TurbHigh"),new ProcessorStats_Battery(&mcuBoard),new MaximDS3231_Temp(&ds3231),// new Modem_RSSI(&modem),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[] = {"12345678-abcd-1234-ef00-1234567890ab", // Electrical conductivity// (Decagon_CTD-10_Cond)"12345678-abcd-1234-ef00-1234567890ab", // Temperature// (Decagon_CTD-10_Temp)"12345678-abcd-1234-ef00-1234567890ab", // Water depth// (Decagon_CTD-10_Depth)"12345678-abcd-1234-ef00-1234567890ab", // Turbidity (Campbell_OBS3_Turb)"12345678-abcd-1234-ef00-1234567890ab", // Turbidity (Campbell_OBS3_Turb)"12345678-abcd-1234-ef00-1234567890ab", // Battery voltage// (EnviroDIY_Mayfly_Batt)"12345678-abcd-1234-ef00-1234567890ab", // Temperature// (EnviroDIY_Mayfly_Temp)"12345678-abcd-1234-ef00-1234567890ab", // Received signal strength// indication (Digi_Cellular_RSSI)"12345678-abcd-1234-ef00-1234567890ab" // Percent full scale// (Digi_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();// 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();}// Extra modem set-up - selecting AT&T as the carrier and LTE-M only// NOTE: The code for this could be shortened using the "commandMode" and// other XBee specific commands in TinyGSM. I've written it this way in// this example to show how the settings could be changed in either bypass// OR transparent mode.Serial.println(F("Waking modem and setting Cellular Carrier Options..."));modem.modemWake(); // NOTE: This will also set up the modem// Go back to command mode to set carrier optionsfor (uint8_t i = 0; i < 5; i++) {// Wait the required guard time before entering command modedelay(1010);modem.gsmModem.streamWrite(GF("+++")); // enter command modeif (modem.gsmModem.waitResponse(2000, GF("OK\r")) == 1) break;}// Carrier Profile - 0 = Automatic selection// - 1 = No profile/SIM ICCID selected// - 2 = AT&T// - 3 = Verizon// NOTE: To select T-Mobile, you must enter bypass mode!modem.gsmModem.sendAT(GF("CP"), 2);modem.gsmModem.waitResponse(GF("OK\r"));// Cellular network technology - 0 = LTE-M with NB-IoT fallback// - 1 = NB-IoT with LTE-M fallback// - 2 = LTE-M only// - 3 = NB-IoT onlymodem.gsmModem.sendAT(GF("N#"), 2);modem.gsmModem.waitResponse();// Write changes to flash and apply themSerial.println(F("Wait while applying changes..."));// Write changes to flashmodem.gsmModem.sendAT(GF("WR"));modem.gsmModem.waitResponse(GF("OK\r"));// Apply changesmodem.gsmModem.sendAT(GF("AC"));modem.gsmModem.waitResponse(GF("OK\r"));// Reset the cellular component to ensure network settings are changedmodem.gsmModem.sendAT(GF("!R"));modem.gsmModem.waitResponse(30000L, GF("OK\r"));// Force reset of the Digi component as well// This effectively exits command modemodem.gsmModem.sendAT(GF("FR"));modem.gsmModem.waitResponse(5000L, GF("OK\r"));// 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] */
-
-
AuthorPosts
- You must be logged in to reply to this topic.