Home › Forums › Mayfly Data Logger › Calculated variable pointers preventing logging to SD
- This topic has 8 replies, 2 voices, and was last updated 2019-02-26 at 8:14 PM by James B.
-
AuthorPosts
-
-
2019-02-24 at 12:37 AM #12818
Hello,
I am testing a nearly identical setup to the showcased build “Construction of Water Level Monitoring Sensor Station” with the addition of a Maxbotix MB7389 and a Xbee LTE CatM1 instead of the 2G bee. I used code from baro_rho_correction.ino and menu_a_la_carte.ino.
When switched on the MayFly powered up and set up all the sensors, but just after the LTE CatM1 connected to the network it seemed to hang and lose power. Then the MayFly skipped dataLogger.logData and put all the sensors to sleep and then the system attempted to sleep infinitely but never made it. This resulted in a CSV file on the SD with headers for each variable but no sensor data. I have abandoned the Xbee LTE M and have ordered the LTE CatM1 breakout from SparkFun which I hope will work as a UBLOX modem.
https://www.sparkfun.com/products/14997In the meantime, I am testing a new sketch without any cellular connection and have run into a code issue which has similar symptoms to what I saw above.
I’m running the simple_logging.ino sketch and have pasted in the “calculated variables” section from baro_rho_correction.ino. My own calculated variable for the Maxbotix sensor is included in this section but is commented out as I do not have it connected to the MayFly at this time.
Without any calculated variable pointers included in the variable array the data logger runs flawlessly. Everything is set up, the sensors turn on and take readings, the data is logged to a CSV file and the system sleeps until the next time to log.
As soon as a calculated variable pointer is added to the variable array, I get similar activity to the setup above with the Xbee. The system powers up, the sensors are setup and turned off, but then the system immediately sleeps until the next time to log. It skips over the datalogger.logData in the loop function. I get empty CSV files again with headers. It wakes up on time but repeats the setup with no logging.
How does adding a calculated variable pointer to the variable array cause the interrupt and prevent the logger from reaching the main loop function?
Thank you
Attachments:
-
2019-02-24 at 12:42 AM #12820123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321// ===============================================================================================================================// Include the base required libraries// ===============================================================================================================================#include <Arduino.h> // The base Arduino library#include <EnableInterrupt.h> // for external and pin change interrupts#include <SensorBase.h>#include <OneWire.h>// ===============================================================================================================================// Data Logger Settings// ===============================================================================================================================// The library version this example was written forconst char *libraryVersion = "0.19.6";// The name of this fileconst char *sketchName = "tbshtnocell.ino";// Logger ID, also becomes the prefix for the name of the data file on SD cardconst char *LoggerID = "nocell4";// How frequently (in minutes) to log dataconst uint8_t loggingInterval = 2;// 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 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 sdCardPin = 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 metadataconst char *mcuBoardVersion = "v0.5b";ProcessorStats mcuBoard(mcuBoardVersion);// ================================================================================================================================// Maxim DS3231 RTC (Real Time Clock)// ================================================================================================================================#include <sensors/MaximDS3231.h>// Create and return the DS3231 sensor objectMaximDS3231 ds3231(1);// ================================================================================================================================// Bosch BME280 Environmental Sensor (Temperature, Humidity, Pressure)// ================================================================================================================================#include <sensors/BoschBME280.h>const int8_t I2CPower = sensorPowerPin; // Pin to switch power on and off (-1 if unconnected)uint8_t BMEi2c_addr = 0x77;// The BME280 can be addressed either as 0x77 (Adafruit default) or 0x76 (Grove default)// Either can be physically mofidied for the other addressconst uint8_t bme280ReadingsToAvg = 33;// Create and return the Bosch BME280 sensor objectBoschBME280 bme280(I2CPower, BMEi2c_addr, bme280ReadingsToAvg);// Create the four variable objects for the BME280 and return variable-type pointers to them// Use these to create variable pointers with names to use in multiple arrays or any calculated variables.Variable *bme280Humid = new BoschBME280_Humidity(&bme280);Variable *bme280Temp = new BoschBME280_Temp(&bme280);Variable *bme280Press = new BoschBME280_Pressure(&bme280);// ================================================================================================================================// Maxim DS18 One Wire Temperature Sensor// ================================================================================================================================#include <sensors/MaximDS18.h>// OneWire Address [array of 8 hex characters]const int8_t OneWireBus = 4; // Pin attached to the OneWire Bus (-1 if unconnected)const int8_t OneWirePower = sensorPowerPin; // Pin to switch power on and off (-1 if unconnected)const int8_t MaxDS18ReadingsToAvg = 33;// Create and return the Maxim DS18 sensor object (use this form for a single sensor on bus with an unknown address)MaximDS18 ds18_u(OneWirePower, OneWireBus, MaxDS18ReadingsToAvg);// Create the temperature variable object for the DS18 and return a variable-type pointer to it// Use this to create a variable pointer with a name to use in multiple arrays or any calculated variables.Variable *ds18Temp = new MaximDS18_Temp(&ds18_u);// ================================================================================================================================// MeaSpecMS5803 (Pressure, Temperature)// ================================================================================================================================#include <sensors/MeaSpecMS5803.h>//const int8_t I2CPower = sensorPowerPin; // Pin to switch power on and off (-1 if unconnected)const uint8_t MS5803i2c_addr = 0x76; // The MS5803 can be addressed either as 0x76 (default) or 0x77const int16_t MS5803maxPressure = 14; // The maximum pressure measurable by the specific MS5803 modelconst uint8_t MS5803ReadingsToAvg = 33;// Create and return the MeaSpec MS5803 pressure and temperature sensor objectMeaSpecMS5803 ms5803(I2CPower, MS5803i2c_addr, MS5803maxPressure, MS5803ReadingsToAvg);// Create the conductivity and temperature variable objects for the ES2 and return variable-type pointers to them// Use these to create variable pointers with names to use in multiple arrays or any calculated variables.Variable *ms5803Press = new MeaSpecMS5803_Pressure(&ms5803);Variable *ms5803Temp = new MeaSpecMS5803_Temp(&ms5803);// ================================================================================================================================// Maxbotix HRXL Ultrasonic Range Finder// ================================================================================================================================//#include <sensors/MaxBotixSonar.h>// Create a reference to the serial port for the sonar// A Maxbotix sonar with the trigger pin disconnect CANNOT share the serial port// A Maxbotix sonar using the trigger may be able to share but YMMV// Extra hardware and software serial ports are created in the "Settings for Additional Serial Ports" section//AltSoftSerial &sonarSerial = altSoftSerial; // For software serial if needed//const int8_t SonarPower = sensorPowerPin; // Excite (power) pin (-1 if unconnected)//const int8_t Sonar1Trigger = 6; // Trigger pin (a unique negative number if unconnected)// Create and return the MaxBotix Sonar sensor object//MaxBotixSonar sonar1(sonarSerial, SonarPower, Sonar1Trigger);// Create the voltage variable object and return a variable-type pointer to it//Variable *sonar1Range = new MaxBotixSonar_Range(&sonar1);// ==========================================================================// Calculated Variables// ==========================================================================// Create any calculated variables you want here// Create the function to calculate the water pressure// Water pressure = pressure from MS5803 (water+baro) - pressure from BME280 (baro)// The MS5803 reports pressure in millibar, the BME280 in pascal// 1 pascal = 0.01 mbarfloat calculateWaterPressure(void){float totalPressureFromMS5803 = ms5803Press->getValue();float baroPressureFromBME280 = bme280Press->getValue();float waterPressure = totalPressureFromMS5803 - (baroPressureFromBME280)*0.01;if (totalPressureFromMS5803 == -9999 || baroPressureFromBME280 == -9999)waterPressure = -9999;// Serial.print(F("Water pressure is ")); // for debugging// Serial.println(waterPressure); // for debuggingreturn waterPressure;}// Properties of the calculated water pressure variableconst char *waterPressureVarName = "pressureGauge"; // This must be a value from http://vocabulary.odm2.org/variablename/const char *waterPressureVarUnit = "millibar"; // This must be a value from http://vocabulary.odm2.org/units/int waterPressureVarResolution = 3;const char *waterPressureUUID = "12345678-abcd-1234-efgh-1234567890ab";const char *waterPressureVarCode = "CorrectedPressure";// Create the calculated water pressure variable objects and return a variable pointer to itVariable *calcWaterPress = new Variable(calculateWaterPressure, waterPressureVarName,waterPressureVarUnit, waterPressureVarResolution,waterPressureUUID, waterPressureVarCode);// Create the function to calculate the "raw" water depth// For this, we're using the conversion between mbar and mm pure water at 4°C// This calculation gives a final result in mm of waterfloat calculateWaterDepthRaw(void){float waterDepth = calculateWaterPressure()*10.1972;if (calculateWaterPressure() == -9999) waterDepth = -9999;// Serial.print(F("'Raw' water depth is ")); // for debugging// Serial.println(waterDepth); // for debuggingreturn waterDepth;}// Properties of the calculated water depth variableconst char *waterDepthVarName = "waterDepth"; // This must be a value from http://vocabulary.odm2.org/variablename/const char *waterDepthVarUnit = "millimeter"; // This must be a value from http://vocabulary.odm2.org/units/int waterDepthVarResolution = 3;const char *waterDepthUUID = "12345678-abcd-1234-efgh-1234567890ab";const char *waterDepthVarCode = "CalcDepth";// Create the calculated raw water depth variable objects and return a variable pointer to itVariable *calcRawDepth = new Variable(calculateWaterDepthRaw, waterDepthVarName,waterDepthVarUnit, waterDepthVarResolution,waterDepthUUID, waterDepthVarCode);// Create the function to calculate the water depth after correcting water density for temperature// This calculation gives a final result in mm of waterfloat calculateWaterDepthTempCorrected(void){const float gravitationalConstant = 9.80665; // m/s2, meters per second squared// First get water pressure in Pa for the calculation: 1 mbar = 100 Pafloat waterPressurePa = 100 * calculateWaterPressure();float waterTempertureC = ms5803Temp->getValue();// Converting water depth for the changes of pressure with depth// Water density (kg/m3) from equation 6 from JonesHarris1992-NIST-DensityWater.pdffloat waterDensity = + 999.84847+ 6.337563e-2 * waterTempertureC- 8.523829e-3 * pow(waterTempertureC,2)+ 6.943248e-5 * pow(waterTempertureC,3)- 3.821216e-7 * pow(waterTempertureC,4);// This calculation gives a final result in mm of water// from P = rho * g * hfloat rhoDepth = 1000 * waterPressurePa/(waterDensity * gravitationalConstant);if (calculateWaterPressure() == -9999 || waterTempertureC == -9999)rhoDepth = -9999;// Serial.print(F("Temperature corrected water depth is ")); // for debugging// Serial.println(rhoDepth); // for debuggingreturn rhoDepth;}// Properties of the calculated temperature corrected water depth variableconst char *rhoDepthVarName = "waterDepth"; // This must be a value from http://vocabulary.odm2.org/variablename/const char *rhoDepthVarUnit = "millimeter"; // This must be a value from http://vocabulary.odm2.org/units/int rhoDepthVarResolution = 3;const char *rhoDepthUUID = "12345678-abcd-1234-efgh-1234567890ab";const char *rhoDepthVarCode = "DensityDepth";// Create the temperature corrected water depth variable objects and return a variable pointer to itVariable *calcCorrDepth = new Variable(calculateWaterDepthTempCorrected, rhoDepthVarName,rhoDepthVarUnit, rhoDepthVarResolution,rhoDepthUUID, rhoDepthVarCode);// ===============================================================================================================================// Creating the Variable Array and filling with Variable Objects// ===============================================================================================================================#include <VariableArray.h>// FORM1: Create pointers for all of the variables from the sensors,// at the same time putting them into an arrayVariable *variableList[] ={new ProcessorStats_SampleNumber(&mcuBoard),new ProcessorStats_FreeRam(&mcuBoard),new ProcessorStats_Batt(&mcuBoard),new MaximDS3231_Temp(&ds3231),bme280Humid,bme280Temp,bme280Press,ds18Temp,ms5803Press,ms5803Temp,calcWaterPress// calcRawDepth,// calcCorrDepth //final temp and baro corrected pressure depth};// 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]// ==========================================================================#include <LoggerBase.h>// Create a new logger instanceLogger dataLogger(LoggerID, loggingInterval, sdCardPin, wakePin, &varArray);// ==========================================================================// 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);}// ==========================================================================// Main setup function// ==========================================================================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);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'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 timezone and offsets// Logging in the given time zoneLogger::setTimeZone(timeZone);// Offset is the same as the time zone because the RTC is in UTCLogger::setTZOffset(timeZone);// Set information pinsdataLogger.setAlertPin(greenLED);dataLogger.setTestingModePin(buttonPin);// Begin the loggerdataLogger.begin();}// ==========================================================================// Main loop function// ==========================================================================void loop(){dataLogger.logData();}
-
2019-02-24 at 10:35 AM #12821
Oh dear. I’ll get on this ASAP and let you know how it’s going.
A warning on the ublox shield:the native baud rate is 112500, which is to fast for the Mayfly. Look at the gitgub issue on the sodaq uBee for how we worked around it. There’s code in the soon-to-be released as master atlas branch for it.
-
2019-02-24 at 12:41 PM #12822
I’m starting to look at the calculated variables.
Have you read the threads on the LTE-M XBee? I’ve gotten it to work; hopefully you can too! https://github.com/EnviroDIY/ModularSensors/issues/162#issuecomment-459879699
-
2019-02-24 at 7:46 PM #12823
Thanks Sara! Yes I have been over both the GPRS bee thread and the LTEM thread here on the forums and the Github thread a bunch. I added a crude “capacitor chain” with the recommended values between bee pin stubs power and ground, a jumper wire between reset and pin A5 and a capacitor on that reset jumper wire as well. It doesn’t fire up at all without the capacitors or the jumper. The last thing I wanted to try before I gave up with it was a smaller battery as I have a 3.7V 6600 mah lipo hooked up that is reading 4.88V fully charged. Somewhere in the Bee manual it said the highest voltage the thing likes is 4.2(I think) so I thought it might be cutting itself off when it saw that the voltage was too high. I was getting activity on the hologram dash though so it was connecting fine, and XCTU said it had full signal since I’m right next to a tower.
-
2019-02-25 at 12:25 PM #12826
Ugh. I’m sorry. I can definitely reproduce this, but I haven’t solved it yet. I’m fairly certain it’s because I’m linking object together in the constructors, but they’re not being created in the right order. This is causing important things (like the whole variable array) to be recreated.
I’m working to solve it.
Sorry!
-
2019-02-25 at 9:52 PM #12828
No problem! Thank you for taking the time to look into it.
-
2019-02-25 at 11:19 PM #12830
If you’re curious, I’m working on the objectInitialization branch for this.
-
2019-02-26 at 8:14 PM #12831
Awesome I’ll head over there. I made huge progress with the XBee LTEM. Have it working with just the reset jumper wire. I added a line to one of the .H files where the APN is set to hologram and also setupXbee() that sets the carrier profile to Verizon (not sure which one helped) and commented out some of the conditions from the example sketch that deal with battery voltage. That seemed to jumpstart everything and it stopped hanging after the network registration. The next issue I’m seeing is failed MQTT status -4 for thingspeak publishing. I’m not sure what that stands for so I have some more troubleshooting to do tonight. I hope I see a dot on a graph soon!
-
-
AuthorPosts
- You must be logged in to reply to this topic.