Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
274 lines (219 sloc) 11.2 KB
/*****************************************************************************
DRWI_NoCellular.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 example sketch is written for ModularSensors library version 0.21.2
This sketch is an example of logging data to an SD card as should be used by
groups involved with The William Penn Foundation's Delaware River Watershed
Initiative at sites without cellular service.
DISCLAIMER:
THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN.
*****************************************************************************/
// ==========================================================================
// Include the base required libraries
// ==========================================================================
#include <Arduino.h> // The base Arduino library
#include <EnableInterrupt.h> // for external and pin change interrupts
// ==========================================================================
// Data Logger Settings
// ==========================================================================
// The library version this example was written for
const char *libraryVersion = "0.21.2";
// The name of this file
const char *sketchName = "DRWI_NoCellular.ino";
// Logger ID, also becomes the prefix for the name of the data file on SD card
const char *LoggerID = "XXXXX";
// How frequently (in minutes) to log data
const uint8_t loggingInterval = 5;
// Your logger's timezone.
const int8_t timeZone = -5; // Eastern Standard Time
// NOTE: Daylight savings time will not be applied! Please use standard time!
// ==========================================================================
// Primary Arduino-Based Board and Processor
// ==========================================================================
#include <sensors/ProcessorStats.h>
const long serialBaud = 115200; // Baud rate for the primary serial port for debugging
const int8_t greenLED = 8; // MCU pin for the green LED (-1 if not applicable)
const int8_t redLED = 9; // MCU pin for the red LED (-1 if not applicable)
const int8_t buttonPin = 21; // MCU pin for a button to use to enter debugging mode (-1 if not applicable)
const int8_t wakePin = 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);
// ==========================================================================
// Maxim DS3231 RTC (Real Time Clock)
// ==========================================================================
#include <sensors/MaximDS3231.h>
// Create a DS3231 sensor object
MaximDS3231 ds3231(1);
// ==========================================================================
// CAMPBELL OBS 3 / OBS 3+ Analog Turbidity Sensor
// ==========================================================================
#include <sensors/CampbellOBS3.h>
const int8_t OBS3Power = sensorPowerPin; // Pin to switch power on and off (-1 if unconnected)
const uint8_t OBS3numberReadings = 10;
const uint8_t ADSi2c_addr = 0x48; // The I2C address of the ADS1115 ADC
// Campbell OBS 3+ Low Range calibration in Volts
const int8_t OBSLowADSChannel = 0; // The ADS channel for the low range output
const float OBSLow_A = 0.000E+00; // The "A" value (X^2) from the low range calibration
const float OBSLow_B = 1.000E+00; // The "B" value (X) from the low range calibration
const float OBSLow_C = 0.000E+00; // The "C" value from the low range calibration
// Create a Campbell OBS3+ LOW RANGE sensor object
CampbellOBS3 osb3low(OBS3Power, OBSLowADSChannel, OBSLow_A, OBSLow_B, OBSLow_C, ADSi2c_addr, OBS3numberReadings);
// Campbell OBS 3+ High Range calibration in Volts
const int8_t OBSHighADSChannel = 1; // The ADS channel for the high range output
const float OBSHigh_A = 0.000E+00; // The "A" value (X^2) from the high range calibration
const float OBSHigh_B = 1.000E+00; // The "B" value (X) from the high range calibration
const float OBSHigh_C = 0.000E+00; // The "C" value from the high range calibration
// Create a Campbell OBS3+ HIGH RANGE sensor object
CampbellOBS3 osb3high(OBS3Power, OBSHighADSChannel, OBSHigh_A, OBSHigh_B, OBSHigh_C, ADSi2c_addr, OBS3numberReadings);
// ==========================================================================
// Decagon CTD Conductivity, Temperature, and Depth Sensor
// ==========================================================================
#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 SDI12Power = sensorPowerPin; // Pin to switch power on and off (-1 if unconnected)
const int8_t SDI12Data = 7; // The SDI12 data pin
// Create a Decagon CTD sensor object
DecagonCTD ctd(*CTDSDI12address, SDI12Power, SDI12Data, CTDnumberReadings);
// ==========================================================================
// Creating the Variable Array[s] and Filling with Variable Objects
// ==========================================================================
#include <VariableArray.h>
Variable *variableList[] = {
new DecagonCTD_Cond(&ctd, "12345678-abcd-1234-efgh-1234567890ab"),
new DecagonCTD_Temp(&ctd, "12345678-abcd-1234-efgh-1234567890ab"),
new DecagonCTD_Depth(&ctd, "12345678-abcd-1234-efgh-1234567890ab"),
new CampbellOBS3_Turbidity(&osb3low, "12345678-abcd-1234-efgh-1234567890ab", "TurbLow"),
new CampbellOBS3_Turbidity(&osb3high, "12345678-abcd-1234-efgh-1234567890ab", "TurbHigh"),
new ProcessorStats_Batt(&mcuBoard, "12345678-abcd-1234-efgh-1234567890ab"),
new MaximDS3231_Temp(&ds3231, "12345678-abcd-1234-efgh-1234567890ab")
};
// 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]
// ==========================================================================
#include <LoggerBase.h>
// Create a new logger instance
Logger dataLogger(LoggerID, loggingInterval, &varArray);
// Device registration and sampling feature information
// This should be obtained after registration at http://data.envirodiy.org
// This is needed so the logger file will be "drag-and-drop" ready for manual
// upload to the portal.
const char *registrationToken = "12345678-abcd-1234-efgh-1234567890ab"; // Device registration token
const char *samplingFeature = "12345678-abcd-1234-efgh-1234567890ab"; // Sampling feature UUID
// ==========================================================================
// Working Functions
// ==========================================================================
// Flashes the LED's on the primary board
void greenredflash(uint8_t numFlash = 4, uint8_t rate = 75)
{
for (uint8_t i = 0; i < numFlash; i++) {
digitalWrite(greenLED, HIGH);
digitalWrite(redLED, LOW);
delay(rate);
digitalWrite(greenLED, LOW);
digitalWrite(redLED, HIGH);
delay(rate);
}
digitalWrite(redLED, LOW);
}
// Read's the battery voltage
// NOTE: This will actually return the battery level from the previous update!
float getBatteryVoltage()
{
if (mcuBoard.sensorValues[0] == -9999) mcuBoard.update();
return mcuBoard.sensorValues[0];
}
// ==========================================================================
// Main setup function
// ==========================================================================
void setup()
{
// Start the primary serial connection
Serial.begin(serialBaud);
// Print a start-up note to the first serial port
Serial.print(F("Now running "));
Serial.print(sketchName);
Serial.print(F(" on Logger "));
Serial.println(LoggerID);
Serial.println();
Serial.print(F("Using ModularSensors Library version "));
Serial.println(MODULAR_SENSORS_VERSION);
if (String(MODULAR_SENSORS_VERSION) != String(libraryVersion))
Serial.println(F(
"WARNING: THIS EXAMPLE WAS WRITTEN FOR A DIFFERENT VERSION OF MODULAR SENSORS!!"));
// 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 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 (sensorPowerPin >= 0)
{
pinMode(sensorPowerPin, OUTPUT);
digitalWrite(sensorPowerPin, LOW);
}
// Set the timezone and offsets
// Logging in the given time zone
Logger::setTimeZone(timeZone);
// Offset is the same as the time zone because the RTC is in UTC
Logger::setTZOffset(timeZone);
// Attach information pins to the logger
dataLogger.setLoggerPins(wakePin, sdCardSSPin, sensorPowerPin, buttonPin, greenLED);
dataLogger.setSamplingFeatureUUID(samplingFeature);
// Begin the logger
dataLogger.begin();
// Set up the sensors, except at lowest battery level
if (getBatteryVoltage() > 3.4)
{
Serial.println(F("Setting up sensors..."));
varArray.setupSensors();
}
// Create the log file, adding the default header to it
// Do this last so we have the best chance of getting the time correct and
// all sensor names correct
// 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)
{
dataLogger.turnOnSDcard(true); // true = wait for card to settle after power up
dataLogger.createLogFile(true); // true = write a new header
dataLogger.turnOffSDcard(true); // true = wait for internal housekeeping after write
}
// Call the processor sleep
Serial.println(F("Putting processor to sleep"));
dataLogger.systemSleep();
}
// ==========================================================================
// Main loop function
// ==========================================================================
// Use this short loop for simple data logging and sending
void loop()
{
// Note: Please change these battery voltages to match your battery
// At very low battery, just go back to sleep
if (getBatteryVoltage() < 3.4)
{
dataLogger.systemSleep();
}
// If the battery is OK, log data
else dataLogger.logData();
}
You can’t perform that action at this time.