Skip to content

Commit

Permalink
Merge pull request #234 from EnviroDIY/objectInitialization
Browse files Browse the repository at this point in the history
Object initialization
  • Loading branch information
SRGDamia1 authored Mar 6, 2019
2 parents 7bbd3e1 + 756b4e9 commit eea2a85
Show file tree
Hide file tree
Showing 83 changed files with 2,879 additions and 1,447 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ include/readme.txt

# Other
compile_tests/
logger_test/
logger_test*/
YosemitechDO/
LongTermLogger/
barometric_correction/
Expand Down
45 changes: 22 additions & 23 deletions examples/DRWI_CitSci/DRWI_CitSci.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ 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.20.2
This example sketch is written for ModularSensors library version 0.21.0
This sketch is an example of logging data to an SD card and sending the data to
both the EnviroDIY data portal as should be used by groups involved with
Expand All @@ -28,7 +28,7 @@ THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN.
// Data Logger Settings
// ==========================================================================
// The library version this example was written for
const char *libraryVersion = "0.20.2";
const char *libraryVersion = "0.21.0";
// The name of this file
const char *sketchName = "DWRI_CitSci.ino";
// Logger ID, also becomes the prefix for the name of the data file on SD card
Expand All @@ -52,10 +52,11 @@ const int8_t buttonPin = 21; // MCU pin for a button to use to enter debugg
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 sdCardPin = 12; // MCU SD card chip select/slave select pin (must be given!)
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 and return the main processor chip "sensor" - for general metadata
// Create the main processor chip "sensor" - for general metadata
const char *mcuBoardVersion = "v0.5b";
ProcessorStats mcuBoard(mcuBoardVersion);

Expand Down Expand Up @@ -92,7 +93,7 @@ HardwareSerial &modemSerial = Serial1; // Use hardware serial if possible
// Create a new TinyGSM modem to run on that serial port and return a pointer to it
TinyGsm *tinyModem = new TinyGsm(modemSerial);

// Create a new TCP client on that modem and return a pointer to it
// Create a TCP client on that modem
TinyGsmClient *tinyClient = new TinyGsmClient(*tinyModem);


Expand All @@ -107,20 +108,19 @@ const bool modemStatusLevel = HIGH; // The level of the status pin when the mod

// Create the wake and sleep methods for the modem
// These can be functions of any type and must return a boolean
bool modemSleepFxn(void)
{
digitalWrite(modemSleepRqPin, LOW);
digitalWrite(redLED, LOW);
return true;
}
bool modemWakeFxn(void)
{
digitalWrite(modemSleepRqPin, HIGH);
digitalWrite(redLED, HIGH); // A light just for show
return true;
}


bool modemSleepFxn(void)
{
digitalWrite(modemSleepRqPin, LOW);
digitalWrite(redLED, LOW);
return true;
}
void extraModemSetup(void){}
// ==========================================================================
// Network Information and LoggerModem Object
// ==========================================================================
Expand All @@ -140,7 +140,7 @@ loggerModem modem(modemVccPin, modemStatusPin, modemStatusLevel, modemWakeFxn, m
// ==========================================================================
#include <sensors/MaximDS3231.h>

// Create and return the DS3231 sensor object
// Create a DS3231 sensor object
MaximDS3231 ds3231(1);


Expand All @@ -158,7 +158,7 @@ const float OBSLow_A = 0.000E+00; // The "A" value (X^2) from the low range cal
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 and return the Campbell OBS3+ LOW RANGE sensor object
// Create a Campbell OBS3+ LOW RANGE sensor object
CampbellOBS3 osb3low(OBS3Power, OBSLowADSChannel, OBSLow_A, OBSLow_B, OBSLow_C, ADSi2c_addr, OBS3numberReadings);


Expand All @@ -168,7 +168,7 @@ const float OBSHigh_A = 0.000E+00; // The "A" value (X^2) from the high range c
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 and return the Campbell OBS3+ HIGH RANGE sensor object
// Create a Campbell OBS3+ HIGH RANGE sensor object
CampbellOBS3 osb3high(OBS3Power, OBSHighADSChannel, OBSHigh_A, OBSHigh_B, OBSHigh_C, ADSi2c_addr, OBS3numberReadings);


Expand All @@ -182,7 +182,7 @@ 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 and return the Decagon CTD sensor object
// Create a Decagon CTD sensor object
DecagonCTD ctd(*CTDSDI12address, SDI12Power, SDI12Data, CTDnumberReadings);


Expand All @@ -191,8 +191,6 @@ DecagonCTD ctd(*CTDSDI12address, SDI12Power, SDI12Data, CTDnumberReadings);
// ==========================================================================
#include <VariableArray.h>

// FORM1: Create pointers for all of the variables from the sensors,
// at the same time putting them into an array
Variable *variableList[] = {
new DecagonCTD_Cond(&ctd, "12345678-abcd-1234-efgh-1234567890ab"),
new DecagonCTD_Temp(&ctd, "12345678-abcd-1234-efgh-1234567890ab"),
Expand All @@ -217,7 +215,7 @@ VariableArray varArray(variableCount, variableList);
#include <LoggerBase.h>

// Create a new logger instance
Logger dataLogger(LoggerID, loggingInterval, sdCardPin, wakePin, &varArray);
Logger dataLogger(LoggerID, loggingInterval, &varArray);


// ==========================================================================
Expand Down Expand Up @@ -321,8 +319,7 @@ void setup()

// Attach the modem and information pins to the logger
dataLogger.attachModem(modem);
dataLogger.setAlertPin(greenLED);
dataLogger.setTestingModePin(buttonPin);
dataLogger.setLoggerPins(wakePin, sdCardSSPin, sensorPowerPin, buttonPin, greenLED);

// Begin the logger
dataLogger.begin();
Expand Down Expand Up @@ -366,7 +363,9 @@ void setup()
// the sensor setup we'll skip this too.
if (getBatteryVoltage() > 3.4)
{
dataLogger.createLogFile(true);
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
Expand Down
52 changes: 29 additions & 23 deletions examples/DRWI_LTE/DRWI_LTE.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ 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.20.2
This example sketch is written for ModularSensors library version 0.21.0
This sketch is an example of logging data to an SD card and sending the data to
both the EnviroDIY data portal as should be used by groups involved with
Expand All @@ -28,7 +28,7 @@ THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN.
// Data Logger Settings
// ==========================================================================
// The library version this example was written for
const char *libraryVersion = "0.20.2";
const char *libraryVersion = "0.21.0";
// The name of this file
const char *sketchName = "DRWI_LTE.ino";
// Logger ID, also becomes the prefix for the name of the data file on SD card
Expand All @@ -52,10 +52,11 @@ const int8_t buttonPin = 21; // MCU pin for a button to use to enter debugg
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 sdCardPin = 12; // MCU SD card chip select/slave select pin (must be given!)
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 and return the main processor chip "sensor" - for general metadata
// Create the main processor chip "sensor" - for general metadata
const char *mcuBoardVersion = "v0.5b";
ProcessorStats mcuBoard(mcuBoardVersion);

Expand Down Expand Up @@ -91,7 +92,7 @@ const int8_t modemStatusPin = 19; // MCU pin used to read modem status (-1 if
// Create a reference to the serial port for the modem
HardwareSerial &modemSerial = Serial1; // Use hardware serial if possible

// Create a new TinyGSM modem to run on that serial port and return a pointer to it
// Create a TinyGSM modem to run on that serial port
TinyGsm *tinyModem = new TinyGsm(modemSerial);

// Create a new TCP client on that modem and return a pointer to it
Expand Down Expand Up @@ -119,7 +120,10 @@ bool modemSleepFxn(void)
digitalWrite(redLED, LOW);
return true;
}
else return true;
else
{
return true;
}
}
bool modemWakeFxn(void)
{
Expand All @@ -131,11 +135,14 @@ bool modemWakeFxn(void)
digitalWrite(redLED, HIGH); // Because the XBee doesn't have any lights
return true;
}
else return true;
else
{
return true;
}
}
// An extra function to set up pin sleep and other preferences on the XBee
// NOTE: This will only succeed if the modem is turned on and awake!
void setupXBee(void)
void extraModemSetup(void)
{
delay(1000); // Guard time for command mode
tinyModem->streamWrite(GF("+++")); // enter command mode
Expand Down Expand Up @@ -183,7 +190,7 @@ loggerModem modem(modemVccPin, modemStatusPin, modemStatusLevel, modemWakeFxn, m
// ==========================================================================
#include <sensors/MaximDS3231.h>

// Create and return the DS3231 sensor object
// Create a DS3231 sensor object
MaximDS3231 ds3231(1);


Expand All @@ -201,7 +208,7 @@ const float OBSLow_A = 0.000E+00; // The "A" value (X^2) from the low range cal
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 and return the Campbell OBS3+ LOW RANGE sensor object
// Create a Campbell OBS3+ LOW RANGE sensor object
CampbellOBS3 osb3low(OBS3Power, OBSLowADSChannel, OBSLow_A, OBSLow_B, OBSLow_C, ADSi2c_addr, OBS3numberReadings);


Expand All @@ -211,7 +218,7 @@ const float OBSHigh_A = 0.000E+00; // The "A" value (X^2) from the high range c
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 and return the Campbell OBS3+ HIGH RANGE sensor object
// Create a Campbell OBS3+ HIGH RANGE sensor object
CampbellOBS3 osb3high(OBS3Power, OBSHighADSChannel, OBSHigh_A, OBSHigh_B, OBSHigh_C, ADSi2c_addr, OBS3numberReadings);


Expand All @@ -225,7 +232,7 @@ 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 and return the Decagon CTD sensor object
// Create a Decagon CTD sensor object
DecagonCTD ctd(*CTDSDI12address, SDI12Power, SDI12Data, CTDnumberReadings);


Expand All @@ -234,8 +241,6 @@ DecagonCTD ctd(*CTDSDI12address, SDI12Power, SDI12Data, CTDnumberReadings);
// ==========================================================================
#include <VariableArray.h>

// FORM1: Create pointers for all of the variables from the sensors,
// at the same time putting them into an array
Variable *variableList[] = {
new DecagonCTD_Cond(&ctd, "12345678-abcd-1234-efgh-1234567890ab"),
new DecagonCTD_Temp(&ctd, "12345678-abcd-1234-efgh-1234567890ab"),
Expand All @@ -260,7 +265,7 @@ VariableArray varArray(variableCount, variableList);
#include <LoggerBase.h>

// Create a new logger instance
Logger dataLogger(LoggerID, loggingInterval, sdCardPin, wakePin, &varArray);
Logger dataLogger(LoggerID, loggingInterval, &varArray);


// ==========================================================================
Expand Down Expand Up @@ -364,8 +369,7 @@ void setup()

// Attach the modem and information pins to the logger
dataLogger.attachModem(modem);
dataLogger.setAlertPin(greenLED);
dataLogger.setTestingModePin(buttonPin);
dataLogger.setLoggerPins(wakePin, sdCardSSPin, sensorPowerPin, buttonPin, greenLED);

// Begin the logger
dataLogger.begin();
Expand All @@ -377,11 +381,10 @@ void setup()
modem.modemPowerUp();
modem.wake();

// Extra pre-set-up for the XBee
Serial.println(F("Setting up sleep mode on the XBee."));
modem.modemPowerUp();
modem.wake(); // Turn it on to talk
setupXBee();
// Run any extra pre-set-up for the modem
Serial.println(F("Running extra modem pre-setup"));
extraModemSetup();
modem.setup();

// At very good battery voltage, or with suspicious time stamp, sync the clock
// Note: Please change these battery voltages to match your battery
Expand Down Expand Up @@ -415,10 +418,13 @@ void setup()
// the sensor setup we'll skip this too.
if (getBatteryVoltage() > 3.4)
{
dataLogger.createLogFile(true);
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();
}

Expand Down
Loading

0 comments on commit eea2a85

Please sign in to comment.