#include #include #include // The modular sensors library #include /* This sample code demonstrates just about every built-in operation of TinyGPS++ (TinyGPSPlus). It requires the use of SoftwareSerial, and assumes that you have a 4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx). */ static const uint32_t GPSBaud = 4800; int delayTime = 1000; //milliseconds, so 1000 = one second int delayTime2 = 100; //milliseconds, so 1000 = one second //Assign pin numbers for built-in LEDs. int greenLED = 8; //Mayfly has LEDs at pins 8 (green) and 9 (red) int redLED = 9; //Mayfly has LEDs at pins 8 (green) and 9 (red) // Logger ID, also becomes the prefix for the name of the data file on SD card const char *LoggerID = "Test"; // How frequently (in minutes) to log data const uint8_t loggingInterval = 1; // Your logger's timezone. const int8_t timeZone = 0; // Create the main processor chip "sensor" - for general metadata const char *mcuBoardVersion = "v0.5b"; ProcessorStats mcuBoard(mcuBoardVersion); // The TinyGPS++ object TinyGPSPlus gps; TinyGPSCustom bars(gps, "WIMDA", 3); // barometric pressure, in bars TinyGPSCustom atemp(gps, "WIMDA", 5); // air temperature, in deg C TinyGPSCustom rhum(gps, "WIMDA", 9); // relative humidity, in percent TinyGPSCustom wdir(gps, "WIMDA", 13); // wind direction, in degrees T TinyGPSCustom wspd(gps, "WIMDA", 19); // wind speed, in meters per second // // Create a Y514 chlorophyll sensor object // YosemitechY514 y514(y514ModbusAddress, modbusSerial, rs485AdapterPower, modbusSensorPower, max485EnablePin, y514NumberReadings); // // Create chlorophyll concentration and temperature variable pointers for the Y514 // Variable *y514Chloro = new YosemitechY514_Chlorophyll(&y514, "12345678-abcd-1234-ef00-1234567890ab"); // Variable *y514Temp = new YosemitechY514_Temp(&y514, "12345678-abcd-1234-ef00-1234567890ab"); //Variable date = new TinyGPSPlus_date(&gps,'date'); Variable *GPSTime = new time(&gps); Variable *bars; Variable *AirTemp = new atemp; Variable *WindSpeed = new wspd; Variable *WindDirection = new wdir; // We put ALL of the variable pointers into the first array Variable *variableList[] = { new ProcessorStats_SampleNumber(&mcuBoard, "sample"), new ProcessorStats_Battery(&mcuBoard, "boardbatt"), new TinyGPSPlus_date(&gps, "date"); new TinyGPSCustom(&gps, "bars"); }; // Count up the number of pointers in the array int variableCount = sizeof(variableList) / sizeof(variableList[0]); // Create the VariableArray object VariableArray Varray(variableCount, variableList); // For stats that happen every 5 seconds unsigned long last = 0UL; // 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); } // Create one new logger instance for the complete array Logger loggerAllVars(LoggerID, loggingInterval, &Varray); void setup() { Serial.begin(115200); Serial1.begin(GPSBaud); pinMode(greenLED, OUTPUT); // all you need to set up the LED blink pinMode(redLED, OUTPUT); // all you need to set up the LED blink // Set the timezones for the logger/data and the RTC // Logging in the given time zone Logger::setLoggerTimeZone(timeZone); // It is STRONGLY RECOMMENDED that you set the RTC to be in UTC (UTC+0) Logger::setRTCTimeZone(0); Serial.println(F("AirmarLogger.ino")); Serial.println(F("An example of using TinyGPS++ and data_saving to log Airmar met data")); Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion()); Serial.println(F("by Mikal Hart")); Serial.println(); // Set up the sensors, except at lowest battery level Serial.println(F("Setting up sensors...")); Varray.setupSensors(); loggerAllVars.turnOnSDcard(true); // true = wait for card to settle after power up loggerAllVars.createLogFile(true); // true = write a new header loggerAllVars.turnOffSDcard(true); // true = wait for internal housekeeping after write } void loop() { // Dispatch incoming characters while (Serial1.available() > 0) gps.encode(Serial1.read()); if (gps.location.isUpdated()&&loggerAllVars.checkInterval()) { // Flag to notify that we're in already awake and logging a point Logger::isLoggingNow = true; // Print a line to show new reading Serial.println(F("------------------------------------------")); // Turn on the LED to show we're taking a reading loggerAllVars.alertOn(); // Power up the SD Card, but skip any waits after power up loggerAllVars.turnOnSDcard(false); // Do a complete update on the "full" array. // This this includes powering all of the sensors, getting updated // values, and turing them back off. // NOTE: The wake function for each sensor should force sensor setup // to run if the sensor was not previously set up. Varray.completeUpdate(); // Create a csv data record and save it to the log file loggerAllVars.logToSD(); else if (millis() - last > 5000) greenredflash() } if (gps.charsProcessed() < 10) Serial.println(F("WARNING: No GPS data. Check wiring.")); last = millis(); Serial.println(); } } static void smartDelay(unsigned long ms) { unsigned long start = millis(); do { while (Serial1.available()) gps.encode(Serial1.read()); } while (millis() - start < ms); } static void printDateTime(TinyGPSDate &d, TinyGPSTime &t) { if (!d.isValid()) { Serial.print(F("********** ")); } else { char sz[32]; sprintf(sz, "%02d/%02d/%02d ", d.month(), d.day(), d.year()); Serial.print(sz); } if (!t.isValid()) { Serial.print(F("******** ")); } else { char sz[32]; sprintf(sz, "%02d:%02d:%02d ", t.hour(), t.minute(), t.second()); Serial.print(sz); } printInt(d.age(), d.isValid(), 5); smartDelay(0); }