Home › Forums › Mayfly Data Logger › Calculated Variable Celsius to Fahrenheit DS18
- This topic has 14 replies, 2 voices, and was last updated 2021-02-15 at 11:27 AM by Sara Damiano.
-
AuthorPosts
-
-
2021-02-12 at 11:54 AM #15133
My problem is that during compilation I get the error below.
I’m trying to convert the Celsius reading from my DS18 to Fahrenheit by using the baro_rho_correction sketch as a guide. I feel like I’ve got the calculated variable code copied over right as far as I can tell but something’s still wrong in the 186 to 240 line range.
I have included the sketch that I’m working on.12345678910C:/Users/brian.jastram/Documents/GitHub/Dev/WXMMBME280OLEDFtoC/WXMMBME280OLEDFtoC.ino:237:9: error: expected type-specifier before 'CalcTempF'new CalcTempF(&ds18, "12345689-abcd-1234-ef00-1234567890ab"),^C:/Users/brian.jastram/Documents/GitHub/Dev/WXMMBME280OLEDFtoC/WXMMBME280OLEDFtoC.ino:237:9: error: expected '}' before 'CalcTempF'C:/Users/brian.jastram/Documents/GitHub/Dev/WXMMBME280OLEDFtoC/WXMMBME280OLEDFtoC.ino:237:9: error: expected ',' or ';' before 'CalcTempF'C:/Users/brian.jastram/Documents/GitHub/Dev/WXMMBME280OLEDFtoC/WXMMBME280OLEDFtoC.ino:240:1: error: expected declaration before '}' token};^*** [.pio\build\mayfly\src\WXMMBME280OLEDFtoC.ino.cpp.o] Error 1========================== [FAILED] Took 5.85 seconds ==========================123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525/*****************************************************************************Based on logging_to MMW.inoAdapted by Anthony and Brianfrom source by: Sara Damiano (sdamiano@stroudcenter.org)Development Environment: PlatformIOHardware Platform: EnviroDIY Mayfly Arduino DataloggerSoftware License: BSD-3.Copyright (c) 2017, Stroud Water Research Center (SWRC)and the EnviroDIY Development TeamThis example sketch is written for ModularSensors library version 0.23.4This shows most of the standard functions of the library at once.DISCLAIMER:THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN.*****************************************************************************/// ==========================================================================// Defines for the Arduino IDE// In PlatformIO, set these build flags in your platformio.ini// ==========================================================================#ifndef TINY_GSM_RX_BUFFER#define TINY_GSM_RX_BUFFER 512#endif#ifndef TINY_GSM_YIELD_MS#define TINY_GSM_YIELD_MS 2#endif#ifndef MQTT_MAX_PACKET_SIZE#define MQTT_MAX_PACKET_SIZE 240#endif// ==========================================================================// Include the base required libraries// ==========================================================================#include <Arduino.h> // The base Arduino library#include <EnableInterrupt.h> // for external and pin change interrupts#include <LoggerBase.h> // The modular sensors library// ==========================================================================// Include libraries for OLED// ==========================================================================#include <Wire.h>#include <SPI.h>#include <Adafruit_Sensor.h>#include <Adafruit_BME280.h>#include <SDL_Arduino_SSD1306.h> // Modification of Adafruit_SSD1306 for ESP8266 compatibility#include <AMAdafruit_GFX.h> // Needs a little change in original Adafruit library (See README.txt file)#include <SPI.h> // For SPI comm (needed for not getting compile error)// Create an instance of the OLED displaySDL_Arduino_SSD1306 display(4); // FOR I2C#define SEALEVELPRESSURE_HPA (1013.25)Adafruit_BME280 bme; // I2C// ==========================================================================// Data Logger Settings// ==========================================================================// The library version this example was written for|previously 0.23.11const char *libraryVersion = "0.25.1";// The name of this fileconst char *sketchName = "WXSTN_Mini_Mobile.ino";// Logger ID, also becomes the prefix for the name of the data file on SD cardconst char *LoggerID = "WX001";// How frequently (in minutes) to log dataconst uint8_t loggingInterval = 15;// Your logger's timezone.const int8_t timeZone = -6; // Central 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 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 metadataconst char *mcuBoardVersion = "v0.5b";ProcessorStats mcuBoard(mcuBoardVersion);// ==========================================================================// Wifi/Cellular Modem Settings// ==========================================================================// Create a reference to the serial port for the modem// Extra hardware and software serial ports are created in the "Settings for Additional Serial Ports" sectionHardwareSerial &modemSerial = Serial1; // Use hardware serial if possible// AltSoftSerial &modemSerial = altSoftSerial; // For software serial if needed// NeoSWSerial &modemSerial = neoSSerial1; // For software serial if needed// Modem Pins - Describe the physical pin connection of your modem to your boardconst int8_t modemVccPin = -2; // MCU pin controlling modem power (-1 if not applicable)const int8_t modemStatusPin = 19; // MCU pin used to read modem status (-1 if not applicable)const int8_t modemResetPin = 20; // MCU pin connected to modem reset pin (-1 if unconnected)const int8_t modemSleepRqPin = 23; // MCU pin used for modem sleep/wake request (-1 if not applicable)const 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 connection#if not defined MS_BUILD_TESTING || defined MS_BUILD_TEST_XBEE_CELLULAR// 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>const long modemBaud = 9600; // All XBee's use 9600 by defaultconst bool useCTSforStatus = false; // Flag to use the modem CTS pin for status// NOTE: If possible, use the STATUS/SLEEP_not (XBee pin 13) for status, but// the CTS pin can also be used if necessaryDigiXBeeCellularTransparent modemXBCT(&modemSerial,modemVccPin, modemStatusPin, useCTSforStatus,modemResetPin, modemSleepRqPin,apn);// Create an extra reference to the modem by a generic name (not necessary)DigiXBeeCellularTransparent modem = modemXBCT;#endif// ==========================================================================// Maxim DS3231 RTC (Real Time Clock)// ==========================================================================#include <sensors/MaximDS3231.h>// ==========================================================================// 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 address// Create a Bosch BME280 sensor objectBoschBME280 bme280(I2CPower, BMEi2c_addr);// Create four variable pointers for the BME280Variable *bme280Humid = new BoschBME280_Humidity(&bme280, "12345678-abcd-1234-ef00-1234567890ab");Variable *bme280Temp = new BoschBME280_Temp(&bme280, "12345678-abcd-1234-ef00-1234567890ab");Variable *bme280Press = new BoschBME280_Pressure(&bme280, "12345678-abcd-1234-ef00-1234567890ab");Variable *bme280Alt = new BoschBME280_Altitude(&bme280, "12345678-abcd-1234-ef00-1234567890ab");// Variable *bme280TempF = new CalcTempF(&bme280, "12345689-abcd-1234-ef00-1234567890ab");// Create a DS3231 sensor objectMaximDS3231 ds3231(1);// ==========================================================================// Maxim DS18 One Wire Temperature Sensor// ==========================================================================#include <sensors/MaximDS18.h>// OneWire Address [array of 8 hex characters]// If only using a single sensor on the OneWire bus, you may omit the address// DeviceAddress OneWireAddress1 = {0x28, 0xFF, 0xBD, 0xBA, 0x81, 0x16, 0x03, 0x0C};const int8_t OneWirePower = sensorPowerPin; // Pin to switch power on and off (-1 if unconnected)const int8_t OneWireBus = 7; // Pin attached to the OneWire Bus (-1 if unconnected) (D24 = A0)// Create a Maxim DS18 sensor objects (use this form for a known address)MaximDS18 ds18(OneWirePower, OneWireBus);// Create a Maxim DS18 sensor object (use this form for a single sensor on bus with an unknown address)// MaximDS18 ds18(OneWirePower, OneWireBus);// Create a temperature variable pointer for the DS18Variable *ds18Temp = new MaximDS18_Temp(&ds18, "12345678-abcd-1234-ef00-1234567890ab");// ==========================================================================// Calculated Variables// ==========================================================================// Create the function to convert the BME280 celcius to fahrenheit// Variable *bme280TempF = new BoshBME280_TempF(&bme280, "12345689-abcd-1234-ef00-1234567890ab");float calculateTempF(void){float TempCFromMaximDS18_Temp = ds18Temp->getValue();float TempF = TempCFromMaximDS18_Temp*(1.8)+32;if (TempCFromMaximDS18_Temp == -9999){TempF = -9999;}return TempF;}// Properties of the calculated temperature variableconst char *TempFVarName = "Temperature";const char *TempFVarUnit = "Degree";int TempFVarResolution = 2;const char *TempFUUID = "12345678-abcd-1234-ef00-1234567890ab";const char *TempFVarCode = "CalcTempF";// Create the calculated fahrenheit variable object and return a variable pointer to itVariable *CalcTempF = new Variable(calculateTempF, TempFVarResolution,TempFVarName, TempFVarUnit,TempFVarCode, TempFUUID);/* CtoF - example from the internetfloat CtoF(float cel){float fahrenheit = (cel * 1.8) + 32;return fahrenheit;}void printValues() {Serial.print("Temperature = ");float cel = bme.readTemperature();Serial.print (bme.readTemperature());Serial.println("C");Serial.print(CtoF(cel));Serial.println("F");}End CtoF - example from internet*/// ==========================================================================// Creating the Variable Array[s] and Filling with Variable Objects// ==========================================================================Variable *variableList[] = {// new ProcessorStats_SampleNumber(&mcuBoard, "12345678-abcd-1234-ef00-1234567890ab"),new ProcessorStats_Battery(&mcuBoard, "b17cb0f2-5538-4790-8641-39f416d185a3"),new Modem_RSSI(&modem, "e1788d85-f8ca-451f-af49-5d4068650a04"),new Modem_SignalPercent(&modem, "94c67feb-ade1-42eb-aef2-dcb021b85ef4"),// new MaximDS3231_Temp(&ds3231, "3a304193-2e51-49e8-96a5-41015b445484"),// new RainCounterI2C_Tips(&tbi2c, "12345678-abcd-1234-ef00-1234567890ab"),new MaximDS18_Temp(&ds18, "a212b5a8-8ab3-456a-8e0e-c8647fe81772"),new BoschBME280_Humidity(&bme280, "fb3cb409-fdc3-42e4-9881-2ee06ad4a4d7"),new BoschBME280_Temp(&bme280, "d7b3ba33-8742-4c91-ac2e-8042e76b8f61"),new CalcTempF(&ds18, "12345689-abcd-1234-ef00-1234567890ab"),new BoschBME280_Pressure(&bme280, "252df794-5f34-4d70-b275-9a908c905b18"),new BoschBME280_Altitude(&bme280, "09fe0223-e9ea-4937-93d7-3468bad920cd"),};// 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]// ==========================================================================// Create a new logger instanceLogger dataLogger(LoggerID, loggingInterval, &varArray);// ==========================================================================// A Publisher to Monitor My Watershed / EnviroDIY Data Sharing Portal// ==========================================================================// Device registration and sampling feature information can be obtained after// registration at https://monitormywatershed.org or https://data.envirodiy.orgconst char *registrationToken = "ffb78d86-af9e-426d-ad44-b807f9e0cd4a"; // Device registration tokenconst char *samplingFeature = "f5290c01-05a9-4047-b096-ca21f21bfbdd"; // Sampling feature UUID// Create a data publisher for the EnviroDIY/WikiWatershed POST endpoint#include <publishers/EnviroDIYPublisher.h>EnviroDIYPublisher EnviroDIYPOST(dataLogger, &modem.gsmClient, registrationToken, samplingFeature);// ==========================================================================// 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);}// 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];}unsigned long delayTime;// ==========================================================================// Main setup function// ==========================================================================void setup(){// Wait for USB connection to be established by PC// NOTE: Only use this when debugging - if not connected to a PC, this// could prevent the script from starting// #if defined SERIAL_PORT_USBVIRTUAL// while (!SERIAL_PORT_USBVIRTUAL && (millis() < 10000)){}// #endif// Start the primary serial connectionSerial.begin(serialBaud);//Added from Example_06_Mayfly_BME280_OLED START//Serial.println(F("BME280 test"));// pinMode(5, INPUT);pinMode(5, INPUT);display.begin(SSD1306_SWITCHCAPVCC, 0x3C, false); // initialize with the I2C addr 0x3C (for the 128x64)/**display.clearDisplay();display.setTextSize(2);display.setTextColor(WHITE);display.setCursor(0,0);display.println("Mayfly");display.println("BME280 DEMO...");display.display();/**display.begin(SSD1306_SWITCHCAPVCC, 0x3C, false); // initialize with the I2C addr 0x3C (for the 128x64)display.clearDisplay();display.setTextSize(1);display.setTextColor(WHITE, BLACK);display.setTextColor(WHITE);display.setCursor(0,0);display.println("Mobile Mini Weather");display.println("What's the Temp?");display.println("*");display.setTextSize(1);display.setTextColor(WHITE, BLACK);display.println("MMWX 808");display.println("Location Unknown");display.setTextSize(2);display.println("72 degrees and sunny");display.println("hi");display.display();**/// Turn on switched powerpinMode(I2CPower, OUTPUT);digitalWrite(I2CPower, HIGH);bool status;// default settings// (you can also pass in a Wire library object like &Wire2)status = bme.begin(BMEi2c_addr);if (!status) {Serial.println("Could not find a valid BME280 sensor, check wiring!");while (1);}/**Serial.println("-- Timing Test --");delayTime = 1100;Serial.println();// Print table headersSerial.println(" Time, Temp, Humid, Press, Alt");Serial.println(" ms, *C, %, Pa, m");//END added from Example_06_Mayfly_BME280_OLED**/// 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!!"));// Allow interrupts for software serial#if defined SoftwareSerial_ExtInts_henableInterrupt(softSerialRx, SoftwareSerial_ExtInts::handle_interrupt, CHANGE);#endif#if defined NeoSWSerial_henableInterrupt(neoSSerial1Rx, neoSSerial1ISR, CHANGE);#endif// 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 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 (modemVccPin >= 0){pinMode(modemVccPin, OUTPUT);digitalWrite(modemVccPin, LOW);}if (sensorPowerPin >= 0){pinMode(sensorPowerPin, OUTPUT);digitalWrite(sensorPowerPin, LOW);}**/// 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(-6);// 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// Check that the battery is OK before powering the modemif (getBatteryVoltage() > 3.7){modem.modemPowerUp();modem.wake();modem.setup();// At very good battery voltage, or with suspicious time stamp, sync the clock// Note: Please change these battery voltages to match your batteryif (getBatteryVoltage() > 3.8 ||dataLogger.getNowEpoch() < 1546300800 || /*Before 01/01/2019*/dataLogger.getNowEpoch() > 1735689600) /*After 1/1/2025*/{// Synchronize the RTC with NISTSerial.println(F("Attempting to connect to the internet and synchronize RTC with NIST"));if (modem.connectInternet(120000L)){dataLogger.setRTClock(modem.getNISTTime());}else{Serial.println(F("Could not connect to internet for clock sync."));}}}// Set up the sensors, except at lowest battery levelif (getBatteryVoltage() > 3.4){Serial.println(F("Setting up sensors..."));varArray.setupSensors();}// Power down the modemmodem.disconnectInternet();modem.modemSleepPowerDown();// 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 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"));dataLogger.systemSleep();}// ==========================================================================// Main loop function// ==========================================================================// Use this short loop for simple data logging and sendingvoid loop(){if (getBatteryVoltage() > 3.6)// for (int i=0; i <= 30; i++){display.clearDisplay();display.setTextSize(2);display.setTextColor(WHITE);display.setCursor(0,0);// display.print("T: "); display.print(sensors.getTempCByIndex(0)); display.println(" C");display.print("T: "); display.print(bme.readTemperature()); display.println(" C");display.print("H: "); display.print(bme.readHumidity()); display.println(" %");display.print("E:"); display.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); display.println(" M");display.setTextSize(1);display.print("P: "); display.print(bme.readPressure()); display.println(" Pa");display.display();}// 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.6){dataLogger.logData();}// If the battery is good, send the data to the worldelse{dataLogger.logDataAndPublish();}} -
2021-02-12 at 12:04 PM #15134
In line 237 you don’t need the “new” or anything else with the calcTempF.
Replace
new CalcTempF(&ds18, "12345689-abcd-1234-ef00-1234567890ab"),
with justCalcTempF,
You’ve already created and named the variable, so you don’t need to re-create it, just reference it. Actually, since you’ve created all your variables with names, you should reference all of them that way instead of creating a second identical one for each of them. So in your variable array, you can replace almost all of the
new ...
with the names you gave the variables in the sensor blocks. The result will look more like the VariableArray in the data saving example: https://github.com/EnviroDIY/ModularSensors/blob/149bb59cdb34f7d54d26cd4a81b7e7a90eabced8/examples/data_saving/data_saving.ino#L318 -
2021-02-12 at 12:07 PM #15135
Does that make sense?
So, for example, in line 178 you created a variable for the DS18 (
Variable *ds18Temp = new MaximDS18_Temp(&ds18, "12345678-abcd-1234-ef00-1234567890ab");
) Since you’ve already done that, down in line 234 instead you can replacenew MaximDS18_Temp(&ds18, "12345678-abcd-1234-ef00-1234567890ab"),
with justds18Temp,
. And you can do the same with all of the other variables. -
2021-02-12 at 12:59 PM #15138
Awesome, thank you. That solved the error. I was wondering about my variable array because I saw the format of the variable array in the baro_rho_correction sketch and it was more bare bones.
Now I’m puzzling on the -17966.20 Degree F output I’m seeing in the serial monitor. I tried adding true to the ds18->getValue(true) but that didn’t work. -
2021-02-12 at 1:11 PM #15139
Now I got it to be 33.8 F by replacing
float TempF = TempCFromMaxiumDS18_Temp*1.8+32 with
float TempF = true*1.8+32 -
2021-02-12 at 1:15 PM #15140
-17966.20 does seem a little bit cold for most offices. Did you change your variable array so it has the
ds18Temp
named variable in it instead of the other new variable? If not update step will update that other new variable and not the one that you’re calculating F from, though adding the “true” to the getValue should force it to update anyway. Is the Celsius temperature from the DS18 reasonable?Using true*1.8+32 will give you 33.8 no matter what happens. In the multiplication “true” is converted to “1” so your equation is just (1*1.8)+32 = 33.8.
-
2021-02-12 at 1:18 PM #15141
You can throw a
Serial.println(TempCFromMaxiumDS18_Temp);
into the middle of your calculation equation just for testing. I can try testing your code myself later this afternoon. -
2021-02-12 at 1:26 PM #15142
I tried just DS18Temp but that didn’t work.
The Celsius temperature from the DS18 is a reasonable 22.25 degrees. -
2021-02-12 at 1:53 PM #15143
Hm. Can you post your current code? I’ll try running it. I have a DS18 here so hopefully once I attach things and start trying to run them whatever issue I’m missing will jump out at me.
-
2021-02-12 at 2:17 PM #15144
Yes, thank you. Here it is.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526/*****************************************************************************Based on logging_to MMW.inoAdapted by Anthony and Brianfrom source by: Sara Damiano (sdamiano@stroudcenter.org)Development Environment: PlatformIOHardware Platform: EnviroDIY Mayfly Arduino DataloggerSoftware License: BSD-3.Copyright (c) 2017, Stroud Water Research Center (SWRC)and the EnviroDIY Development TeamThis example sketch is written for ModularSensors library version 0.23.4This shows most of the standard functions of the library at once.DISCLAIMER:THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN.*****************************************************************************/// ==========================================================================// Defines for the Arduino IDE// In PlatformIO, set these build flags in your platformio.ini// ==========================================================================#ifndef TINY_GSM_RX_BUFFER#define TINY_GSM_RX_BUFFER 512#endif#ifndef TINY_GSM_YIELD_MS#define TINY_GSM_YIELD_MS 2#endif#ifndef MQTT_MAX_PACKET_SIZE#define MQTT_MAX_PACKET_SIZE 240#endif// ==========================================================================// Include the base required libraries// ==========================================================================#include <Arduino.h> // The base Arduino library#include <EnableInterrupt.h> // for external and pin change interrupts#include <LoggerBase.h> // The modular sensors library// ==========================================================================// Include libraries for OLED// ==========================================================================#include <Wire.h>#include <SPI.h>#include <Adafruit_Sensor.h>#include <Adafruit_BME280.h>#include <SDL_Arduino_SSD1306.h> // Modification of Adafruit_SSD1306 for ESP8266 compatibility#include <AMAdafruit_GFX.h> // Needs a little change in original Adafruit library (See README.txt file)#include <SPI.h> // For SPI comm (needed for not getting compile error)// Create an instance of the OLED displaySDL_Arduino_SSD1306 display(4); // FOR I2C#define SEALEVELPRESSURE_HPA (1013.25)Adafruit_BME280 bme; // I2C// ==========================================================================// Data Logger Settings// ==========================================================================// The library version this example was written for|previously 0.23.11const char *libraryVersion = "0.25.1";// The name of this fileconst char *sketchName = "WXSTN_Mini_Mobile.ino";// Logger ID, also becomes the prefix for the name of the data file on SD cardconst char *LoggerID = "WX001";// How frequently (in minutes) to log dataconst uint8_t loggingInterval = 15;// Your logger's timezone.const int8_t timeZone = -6; // Central 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 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 metadataconst char *mcuBoardVersion = "v0.5b";ProcessorStats mcuBoard(mcuBoardVersion);// ==========================================================================// Wifi/Cellular Modem Settings// ==========================================================================// Create a reference to the serial port for the modem// Extra hardware and software serial ports are created in the "Settings for Additional Serial Ports" sectionHardwareSerial &modemSerial = Serial1; // Use hardware serial if possible// AltSoftSerial &modemSerial = altSoftSerial; // For software serial if needed// NeoSWSerial &modemSerial = neoSSerial1; // For software serial if needed// Modem Pins - Describe the physical pin connection of your modem to your boardconst int8_t modemVccPin = -2; // MCU pin controlling modem power (-1 if not applicable)const int8_t modemStatusPin = 19; // MCU pin used to read modem status (-1 if not applicable)const int8_t modemResetPin = 20; // MCU pin connected to modem reset pin (-1 if unconnected)const int8_t modemSleepRqPin = 23; // MCU pin used for modem sleep/wake request (-1 if not applicable)const 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 connection#if not defined MS_BUILD_TESTING || defined MS_BUILD_TEST_XBEE_CELLULAR// 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>const long modemBaud = 9600; // All XBee's use 9600 by defaultconst bool useCTSforStatus = false; // Flag to use the modem CTS pin for status// NOTE: If possible, use the STATUS/SLEEP_not (XBee pin 13) for status, but// the CTS pin can also be used if necessaryDigiXBeeCellularTransparent modemXBCT(&modemSerial,modemVccPin, modemStatusPin, useCTSforStatus,modemResetPin, modemSleepRqPin,apn);// Create an extra reference to the modem by a generic name (not necessary)DigiXBeeCellularTransparent modem = modemXBCT;#endif// ==========================================================================// Maxim DS3231 RTC (Real Time Clock)// ==========================================================================#include <sensors/MaximDS3231.h>// ==========================================================================// 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 address// Create a Bosch BME280 sensor objectBoschBME280 bme280(I2CPower, BMEi2c_addr);// Create four variable pointers for the BME280Variable *bme280Humid = new BoschBME280_Humidity(&bme280, "12345678-abcd-1234-ef00-1234567890ab");Variable *bme280Temp = new BoschBME280_Temp(&bme280, "12345678-abcd-1234-ef00-1234567890ab");Variable *bme280Press = new BoschBME280_Pressure(&bme280, "12345678-abcd-1234-ef00-1234567890ab");Variable *bme280Alt = new BoschBME280_Altitude(&bme280, "12345678-abcd-1234-ef00-1234567890ab");// Variable *bme280TempF = new CalcTempF(&bme280, "12345689-abcd-1234-ef00-1234567890ab");// Create a DS3231 sensor objectMaximDS3231 ds3231(1);// ==========================================================================// Maxim DS18 One Wire Temperature Sensor// ==========================================================================#include <sensors/MaximDS18.h>// OneWire Address [array of 8 hex characters]// If only using a single sensor on the OneWire bus, you may omit the address// DeviceAddress OneWireAddress1 = {0x28, 0xFF, 0xBD, 0xBA, 0x81, 0x16, 0x03, 0x0C};const int8_t OneWirePower = sensorPowerPin; // Pin to switch power on and off (-1 if unconnected)const int8_t OneWireBus = 7; // Pin attached to the OneWire Bus (-1 if unconnected) (D24 = A0)// Create a Maxim DS18 sensor objects (use this form for a known address)MaximDS18 ds18(OneWirePower, OneWireBus);// Create a Maxim DS18 sensor object (use this form for a single sensor on bus with an unknown address)// MaximDS18 ds18(OneWirePower, OneWireBus);// Create a temperature variable pointer for the DS18Variable *ds18Temp = new MaximDS18_Temp(&ds18, "12345678-abcd-1234-ef00-1234567890ab");// ==========================================================================// Calculated Variables// ==========================================================================// Create the function to convert the BME280 celcius to fahrenheit// Variable *bme280TempF = new BoshBME280_TempF(&bme280, "12345689-abcd-1234-ef00-1234567890ab");float calculateTempF(void){float TempCFromMaximDS18_Temp = ds18Temp->getValue(true);float TempF = (true)*1.8+32;//if (TempCFromMaximDS18_Temp == -9999)//{// TempF = -9999;//}Serial.println(TempCFromMaxiumDS18_Temp);return TempF;}// Properties of the calculated temperature variableconst char *TempFVarName = "DS18 CalcTempF";const char *TempFVarUnit = "Degrees F";int TempFVarResolution = 1;const char *TempFUUID = "12345678-abcd-1234-ef00-1234567890ab";const char *TempFVarCode = "CalcTempF";// Create the calculated fahrenheit variable object and return a variable pointer to itVariable *CalcTempF = new Variable(calculateTempF, TempFVarResolution,TempFVarName, TempFVarUnit,TempFVarCode, TempFUUID);/* CtoF - example from the internetfloat CtoF(float cel){float fahrenheit = (cel * 1.8) + 32;return fahrenheit;}void printValues() {Serial.print("Temperature = ");float cel = bme.readTemperature();Serial.print (bme.readTemperature());Serial.println("C");Serial.print(CtoF(cel));Serial.println("F");}End CtoF - example from internet*/// ==========================================================================// Creating the Variable Array[s] and Filling with Variable Objects// ==========================================================================Variable *variableList[] = {// new ProcessorStats_SampleNumber(&mcuBoard, "12345678-abcd-1234-ef00-1234567890ab"),new ProcessorStats_Battery(&mcuBoard, "b17cb0f2-5538-4790-8641-39f416d185a3"),new Modem_RSSI(&modem, "e1788d85-f8ca-451f-af49-5d4068650a04"),new Modem_SignalPercent(&modem, "94c67feb-ade1-42eb-aef2-dcb021b85ef4"),// new MaximDS3231_Temp(&ds3231, "3a304193-2e51-49e8-96a5-41015b445484"),// new RainCounterI2C_Tips(&tbi2c, "12345678-abcd-1234-ef00-1234567890ab"),new MaximDS18_Temp(&ds18, "a212b5a8-8ab3-456a-8e0e-c8647fe81772"),new BoschBME280_Humidity(&bme280, "fb3cb409-fdc3-42e4-9881-2ee06ad4a4d7"),new BoschBME280_Temp(&bme280, "d7b3ba33-8742-4c91-ac2e-8042e76b8f61"),CalcTempF,new BoschBME280_Pressure(&bme280, "252df794-5f34-4d70-b275-9a908c905b18"),new BoschBME280_Altitude(&bme280, "09fe0223-e9ea-4937-93d7-3468bad920cd"),};// 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]// ==========================================================================// Create a new logger instanceLogger dataLogger(LoggerID, loggingInterval, &varArray);// ==========================================================================// A Publisher to Monitor My Watershed / EnviroDIY Data Sharing Portal// ==========================================================================// Device registration and sampling feature information can be obtained after// registration at https://monitormywatershed.org or https://data.envirodiy.orgconst char *registrationToken = "ffb78d86-af9e-426d-ad44-b807f9e0cd4a"; // Device registration tokenconst char *samplingFeature = "f5290c01-05a9-4047-b096-ca21f21bfbdd"; // Sampling feature UUID// Create a data publisher for the EnviroDIY/WikiWatershed POST endpoint#include <publishers/EnviroDIYPublisher.h>EnviroDIYPublisher EnviroDIYPOST(dataLogger, &modem.gsmClient, registrationToken, samplingFeature);// ==========================================================================// 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);}// 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];}unsigned long delayTime;// ==========================================================================// Main setup function// ==========================================================================void setup(){// Wait for USB connection to be established by PC// NOTE: Only use this when debugging - if not connected to a PC, this// could prevent the script from starting// #if defined SERIAL_PORT_USBVIRTUAL// while (!SERIAL_PORT_USBVIRTUAL && (millis() < 10000)){}// #endif// Start the primary serial connectionSerial.begin(serialBaud);//Added from Example_06_Mayfly_BME280_OLED START//Serial.println(F("BME280 test"));// pinMode(5, INPUT);pinMode(5, INPUT);display.begin(SSD1306_SWITCHCAPVCC, 0x3C, false); // initialize with the I2C addr 0x3C (for the 128x64)/**display.clearDisplay();display.setTextSize(2);display.setTextColor(WHITE);display.setCursor(0,0);display.println("Mayfly");display.println("BME280 DEMO...");display.display();/**display.begin(SSD1306_SWITCHCAPVCC, 0x3C, false); // initialize with the I2C addr 0x3C (for the 128x64)display.clearDisplay();display.setTextSize(1);display.setTextColor(WHITE, BLACK);display.setTextColor(WHITE);display.setCursor(0,0);display.println("Mobile Mini Weather");display.println("What's the Temp?");display.println("*");display.setTextSize(1);display.setTextColor(WHITE, BLACK);display.println("MMWX 808");display.println("Location Unknown");display.setTextSize(2);display.println("72 degrees and sunny");display.println("hi");display.display();**/// Turn on switched powerpinMode(I2CPower, OUTPUT);digitalWrite(I2CPower, HIGH);bool status;// default settings// (you can also pass in a Wire library object like &Wire2)status = bme.begin(BMEi2c_addr);if (!status) {Serial.println("Could not find a valid BME280 sensor, check wiring!");while (1);}/**Serial.println("-- Timing Test --");delayTime = 1100;Serial.println();// Print table headersSerial.println(" Time, Temp, Humid, Press, Alt");Serial.println(" ms, *C, %, Pa, m");//END added from Example_06_Mayfly_BME280_OLED**/// 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!!"));// Allow interrupts for software serial#if defined SoftwareSerial_ExtInts_henableInterrupt(softSerialRx, SoftwareSerial_ExtInts::handle_interrupt, CHANGE);#endif#if defined NeoSWSerial_henableInterrupt(neoSSerial1Rx, neoSSerial1ISR, CHANGE);#endif// 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 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 (modemVccPin >= 0){pinMode(modemVccPin, OUTPUT);digitalWrite(modemVccPin, LOW);}if (sensorPowerPin >= 0){pinMode(sensorPowerPin, OUTPUT);digitalWrite(sensorPowerPin, LOW);}**/// 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(-6);// 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// Check that the battery is OK before powering the modemif (getBatteryVoltage() > 3.7){modem.modemPowerUp();modem.wake();modem.setup();// At very good battery voltage, or with suspicious time stamp, sync the clock// Note: Please change these battery voltages to match your batteryif (getBatteryVoltage() > 3.8 ||dataLogger.getNowEpoch() < 1546300800 || /*Before 01/01/2019*/dataLogger.getNowEpoch() > 1735689600) /*After 1/1/2025*/{// Synchronize the RTC with NISTSerial.println(F("Attempting to connect to the internet and synchronize RTC with NIST"));if (modem.connectInternet(120000L)){dataLogger.setRTClock(modem.getNISTTime());}else{Serial.println(F("Could not connect to internet for clock sync."));}}}// Set up the sensors, except at lowest battery levelif (getBatteryVoltage() > 3.4){Serial.println(F("Setting up sensors..."));varArray.setupSensors();}// Power down the modemmodem.disconnectInternet();modem.modemSleepPowerDown();// 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 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"));dataLogger.systemSleep();}// ==========================================================================// Main loop function// ==========================================================================// Use this short loop for simple data logging and sendingvoid loop(){if (getBatteryVoltage() > 3.6)// for (int i=0; i <= 30; i++){display.clearDisplay();display.setTextSize(2);display.setTextColor(WHITE);display.setCursor(0,0);// display.print("T: "); display.print(sensors.getTempCByIndex(0)); display.println(" C");display.print("T: "); display.print(bme.readTemperature()); display.println(" C");display.print("H: "); display.print(bme.readHumidity()); display.println(" %");display.print("E:"); display.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); display.println(" M");display.setTextSize(1);display.print("P: "); display.print(bme.readPressure()); display.println(" Pa");display.display();}// 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.6){dataLogger.logData();}// If the battery is good, send the data to the worldelse{dataLogger.logDataAndPublish();}} -
2021-02-12 at 2:27 PM #15145
There should be no u in Maxium in line 194.
-
2021-02-12 at 5:43 PM #15146
The C-to-F is working for me with this calculation function:
Arduino1234567891011121314float calculateTempF(void){float TempCFromMaximDS18_Temp = ds18Temp->getValue();float TempF = (TempCFromMaximDS18_Temp)*1.8 + 32;if (TempCFromMaximDS18_Temp == -9999){TempF = -9999;}// Serial.print("DS18 Temperature in Celsius:");// Serial.println(TempCFromMaximDS18_Temp);// Serial.print("DS18 Temperature in Fahrenheit:");// Serial.println(TempF);return TempF;}And this variableArray:
Arduino1234567891011121314Variable *variableList[] = {// new ProcessorStats_SampleNumber(&mcuBoard, "12345678-abcd-1234-ef00-1234567890ab"),new ProcessorStats_Battery(&mcuBoard, "b17cb0f2-5538-4790-8641-39f416d185a3"),new Modem_RSSI(&modem, "e1788d85-f8ca-451f-af49-5d4068650a04"),new Modem_SignalPercent(&modem, "94c67feb-ade1-42eb-aef2-dcb021b85ef4"),// new MaximDS3231_Temp(&ds3231, "3a304193-2e51-49e8-96a5-41015b445484"),// new RainCounterI2C_Tips(&tbi2c, "12345678-abcd-1234-ef00-1234567890ab"),ds18Temp,CalcTempF,bme280Humid,bme280Temp,bme280Press,bme280Alt,};But I don’t have a BME280 on my desk so I commented out all of that code to get it to work. I also don’t have a working XBee3 right now, so I couldn’t test with that. I don’t think those would interfere, but I’m just warning you that my testing isn’t exactly what you have.
Are you planning to keep the code for displaying on the little screen? You could simplify your code by removing all of the extra code for the BME280 and then displaying the result of the BME280 by using the variables you created for it for the logger. So, replace
display.print("T: "); display.print(sensors.getTempCByIndex(0)); display.println(" C");
withdisplay.print("T: "); display.print(bme280Temp->getValueString()); display.println(" C");
and so forth. If you want, on Monday I can write up a simpler version for you following that model. -
2021-02-15 at 11:08 AM #15147
Here’s the version without the extra un-needed BME code. I left in all the code for the display.
Arduino123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474/*****************************************************************************Based on logging_to MMW.inoAdapted by Anthony and Brianfrom source by: Sara Damiano (sdamiano@stroudcenter.org)Development Environment: PlatformIOHardware Platform: EnviroDIY Mayfly Arduino DataloggerSoftware License: BSD-3.Copyright (c) 2017, Stroud Water Research Center (SWRC)and the EnviroDIY Development TeamThis example sketch is written for ModularSensors library version 0.23.4This shows most of the standard functions of the library at once.DISCLAIMER:THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN.*****************************************************************************/// ==========================================================================// Defines for the Arduino IDE// In PlatformIO, set these build flags in your platformio.ini// ==========================================================================#ifndef TINY_GSM_RX_BUFFER#define TINY_GSM_RX_BUFFER 512#endif#ifndef TINY_GSM_YIELD_MS#define TINY_GSM_YIELD_MS 2#endif#ifndef MQTT_MAX_PACKET_SIZE#define MQTT_MAX_PACKET_SIZE 240#endif// ==========================================================================// Include the base required libraries// ==========================================================================#include <Arduino.h> // The base Arduino library#include <EnableInterrupt.h> // for external and pin change interrupts#include <LoggerBase.h> // The modular sensors library// ==========================================================================// Include libraries for OLED// ==========================================================================#include <SDL_Arduino_SSD1306.h> // Modification of Adafruit_SSD1306 for ESP8266 compatibility// Create an instance of the OLED displaySDL_Arduino_SSD1306 display(4); // FOR I2C// ==========================================================================// Data Logger Settings// ==========================================================================// The library version this example was written for|previously 0.23.11const char *libraryVersion = "0.25.1";// The name of this fileconst char *sketchName = "WXSTN_Mini_Mobile.ino";// Logger ID, also becomes the prefix for the name of the data file on SD cardconst char *LoggerID = "WX001";// How frequently (in minutes) to log dataconst uint8_t loggingInterval = 15;// Your logger's timezone.const int8_t timeZone = -6; // Central 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 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 metadataconst char *mcuBoardVersion = "v0.5b";ProcessorStats mcuBoard(mcuBoardVersion);// ==========================================================================// Wifi/Cellular Modem Settings// ==========================================================================// Create a reference to the serial port for the modem// Extra hardware and software serial ports are created in the "Settings for Additional Serial Ports" sectionHardwareSerial &modemSerial = Serial1; // Use hardware serial if possible// AltSoftSerial &modemSerial = altSoftSerial; // For software serial if needed// NeoSWSerial &modemSerial = neoSSerial1; // For software serial if needed// Modem Pins - Describe the physical pin connection of your modem to your boardconst int8_t modemVccPin = -2; // MCU pin controlling modem power (-1 if not applicable)const int8_t modemStatusPin = 19; // MCU pin used to read modem status (-1 if not applicable)const int8_t modemResetPin = 20; // MCU pin connected to modem reset pin (-1 if unconnected)const int8_t modemSleepRqPin = 23; // MCU pin used for modem sleep/wake request (-1 if not applicable)const 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 connection#if not defined MS_BUILD_TESTING || defined MS_BUILD_TEST_XBEE_CELLULAR// 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>const long modemBaud = 9600; // All XBee's use 9600 by defaultconst bool useCTSforStatus = false; // Flag to use the modem CTS pin for status// NOTE: If possible, use the STATUS/SLEEP_not (XBee pin 13) for status, but// the CTS pin can also be used if necessaryDigiXBeeCellularTransparent modemXBCT(&modemSerial,modemVccPin, modemStatusPin, useCTSforStatus,modemResetPin, modemSleepRqPin,apn);// Create an extra reference to the modem by a generic name (not necessary)DigiXBeeCellularTransparent modem = modemXBCT;#endif// ==========================================================================// Maxim DS3231 RTC (Real Time Clock)// ==========================================================================#include <sensors/MaximDS3231.h>// Create a DS3231 sensor objectMaximDS3231 ds3231(1);// ==========================================================================// Calculated Variables// ==========================================================================// CtoF - example from the internetfloat CtoF(float cel){float fahrenheit = (cel * 1.8) + 32;return fahrenheit;}// End CtoF - example from internet// Properties of the calculated temperature variableconst char *TempFVarName = "temperature";const char *TempFVarUnit = "degreeFahrenheit";int TempFVarResolution = 2;// ==========================================================================// 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 address// Create a Bosch BME280 sensor objectBoschBME280 bme280(I2CPower, BMEi2c_addr);// Create four variable pointers for the BME280Variable *bme280Humid = new BoschBME280_Humidity(&bme280, "12345678-abcd-1234-ef00-1234567890ab");Variable *bme280Temp = new BoschBME280_Temp(&bme280, "12345678-abcd-1234-ef00-1234567890ab");Variable *bme280Press = new BoschBME280_Pressure(&bme280, "12345678-abcd-1234-ef00-1234567890ab");Variable *bme280Alt = new BoschBME280_Altitude(&bme280, "12345678-abcd-1234-ef00-1234567890ab");// Create the function to convert the BME280 celcius to fahrenheitfloat calculatebme280TempF(void){float TempCFromBME280 = bme280Temp->getValue();float TempF = CtoF(TempCFromBME280);if (TempCFromBME280 == -9999){TempF = -9999;}return TempF;}const char *bme280TempFUUID = "12345678-abcd-1234-ef00-1234567890ab";const char *bme280TempFVarCode = "bme280TempF";// Create the calculated fahrenheit variable object and return a variable pointer to itVariable *bme280TempF = new Variable(calculatebme280TempF, TempFVarResolution,TempFVarName, TempFVarUnit,bme280TempFVarCode, bme280TempFUUID);// ==========================================================================// Maxim DS18 One Wire Temperature Sensor// ==========================================================================#include <sensors/MaximDS18.h>// OneWire Address [array of 8 hex characters]// If only using a single sensor on the OneWire bus, you may omit the address// DeviceAddress OneWireAddress1 = {0x28, 0xFF, 0xBD, 0xBA, 0x81, 0x16, 0x03, 0x0C};const int8_t OneWirePower = sensorPowerPin; // Pin to switch power on and off (-1 if unconnected)const int8_t OneWireBus = 7; // Pin attached to the OneWire Bus (-1 if unconnected) (D24 = A0)// Create a Maxim DS18 sensor object (use this form for a single sensor on bus with an unknown address)MaximDS18 ds18(OneWirePower, OneWireBus);// Create a temperature variable pointer for the DS18Variable *ds18Temp = new MaximDS18_Temp(&ds18, "12345678-abcd-1234-ef00-1234567890ab");// Create the function to convert the DS18 celcius to fahrenheitfloat calculateds18TempF(void){float TempCFromMaximDS18 = ds18Temp->getValue();float TempF = CtoF(TempCFromMaximDS18);if (TempCFromMaximDS18 == -9999){TempF = -9999;}return TempF;}// Properties of the calculated temperature variableconst char *ds18TempFUUID = "12345678-abcd-1234-ef00-1234567890ab";const char *ds18TempFVarCode = "ds18TempF";// Create the calculated fahrenheit variable object and return a variable pointer to itVariable *ds18TempF = new Variable(calculateds18TempF, TempFVarResolution,TempFVarName, TempFVarUnit,ds18TempFVarCode, ds18TempFUUID);// ==========================================================================// Creating the Variable Array[s] and Filling with Variable Objects// ==========================================================================Variable *variableList[] = {// new ProcessorStats_SampleNumber(&mcuBoard, "12345678-abcd-1234-ef00-1234567890ab"),new ProcessorStats_Battery(&mcuBoard, "b17cb0f2-5538-4790-8641-39f416d185a3"),new Modem_RSSI(&modem, "e1788d85-f8ca-451f-af49-5d4068650a04"),new Modem_SignalPercent(&modem, "94c67feb-ade1-42eb-aef2-dcb021b85ef4"),new MaximDS3231_Temp(&ds3231, "3a304193-2e51-49e8-96a5-41015b445484"),ds18Temp,ds18TempF,bme280Humid,bme280Temp,bme280TempF,bme280Press,bme280Alt,};// 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]// ==========================================================================// Create a new logger instanceLogger dataLogger(LoggerID, loggingInterval, &varArray);// ==========================================================================// A Publisher to Monitor My Watershed / EnviroDIY Data Sharing Portal// ==========================================================================// Device registration and sampling feature information can be obtained after// registration at https://monitormywatershed.org or https://data.envirodiy.orgconst char *registrationToken = "ffb78d86-af9e-426d-ad44-b807f9e0cd4a"; // Device registration tokenconst char *samplingFeature = "f5290c01-05a9-4047-b096-ca21f21bfbdd"; // Sampling feature UUID// Create a data publisher for the EnviroDIY/WikiWatershed POST endpoint#include <publishers/EnviroDIYPublisher.h>EnviroDIYPublisher EnviroDIYPOST(dataLogger, &modem.gsmClient, registrationToken, samplingFeature);// ==========================================================================// 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);}// 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];}unsigned long delayTime;// ==========================================================================// Main setup function// ==========================================================================void setup(){// Wait for USB connection to be established by PC// NOTE: Only use this when debugging - if not connected to a PC, this// could prevent the script from starting// #if defined SERIAL_PORT_USBVIRTUAL// while (!SERIAL_PORT_USBVIRTUAL && (millis() < 10000)){}// #endif// Start the primary serial connectionSerial.begin(serialBaud);// Turn on switched power (for the display)pinMode(I2CPower, OUTPUT);digitalWrite(I2CPower, HIGH);display.begin(SSD1306_SWITCHCAPVCC, 0x3C, false); // initialize with the I2C addr 0x3C (for the 128x64)display.clearDisplay();display.setTextSize(2);display.setTextColor(WHITE);display.setCursor(0, 0);display.println(F("Mayfly\nBME280\nDEMO..."));display.display();// 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);// 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(-6);// 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// Check that the battery is OK before powering the modemif (getBatteryVoltage() > 3.7){Serial.println(F("Beginning modem setup"));modem.modemPowerUp();modem.wake();modem.setup();// At very good battery voltage, or with suspicious time stamp, sync the clock// Note: Please change these battery voltages to match your batteryif (getBatteryVoltage() > 3.8 ||dataLogger.getNowEpoch() < 1546300800 || /*Before 01/01/2019*/dataLogger.getNowEpoch() > 1735689600) /*After 1/1/2025*/{// Synchronize the RTC with NISTSerial.println(F("Attempting to connect to the internet and synchronize RTC with NIST"));if (modem.connectInternet(120000L)){dataLogger.setRTClock(modem.getNISTTime());}else{Serial.println(F("Could not connect to internet for clock sync."));}}}// Set up the sensors, except at lowest battery levelif (getBatteryVoltage() > 3.4){Serial.println(F("Setting up sensors..."));varArray.setupSensors();}// Power down the modemmodem.disconnectInternet();modem.modemSleepPowerDown();// 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 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"));dataLogger.systemSleep();}// ==========================================================================// Main loop function// ==========================================================================// 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.6){dataLogger.logData();}// If the battery is good, send the data to the worldelse{dataLogger.logDataAndPublish();// Turn on switched power (for the display)pinMode(I2CPower, OUTPUT);digitalWrite(I2CPower, HIGH);display.clearDisplay();display.setTextSize(1.5);display.setTextColor(WHITE);display.setCursor(0, 0);display.print(F("DS18 T: "));display.print(ds18Temp->getValueString());display.println(F(" C"));display.print(F("DS18 T: "));display.print(ds18TempF->getValueString());display.println(F(" F"));display.println();display.print(F("BME T: "));display.print(bme280Temp->getValueString());display.println(F(" C"));display.print(F("BME T: "));display.print(bme280TempF->getValueString());display.println(F(" F"));display.print(F("BME H: "));display.print(bme280Humid->getValueString());display.println(F(" %"));display.print(F("BME E:"));display.print(bme280Alt->getValueString());display.println(F(" M"));display.print(F("BME P: "));display.print(bme280Press->getValueString());display.println(F(" Pa"));display.display();PRINTOUT(F("DS18 T:"), ds18Temp->getValueString(), F("°C"));PRINTOUT(F("DS18 T:"), ds18TempF->getValueString(), F("°F\n"));PRINTOUT(F("BME T:"), bme280Temp->getValueString(), F("°C"));PRINTOUT(F("BME T:"), bme280TempF->getValueString(), F("°F"));PRINTOUT(F("BME H:"), bme280Humid->getValueString(), F("%"));PRINTOUT(F("BME E:"), bme280Alt->getValueString(), F("m"));PRINTOUT(F("BME P:"), bme280Press->getValueString(), F("Pa"));}} -
2021-02-15 at 11:12 AM #15148
Sorry, the formatter and I were having an argument. I think it’s right now.
-
2021-02-15 at 11:27 AM #15149
The print-outs are always going to be updated about a minute behind because the board will go to sleep at the end of the
logdata()
function and won’t do the printing until the next time it wakes up (which will be the next minute).
-
-
AuthorPosts
- You must be logged in to reply to this topic.