From 7a829687e873a2411e9b9b8b650f9db99c83c564 Mon Sep 17 00:00:00 2001 From: Ralf Behrens Date: Wed, 12 Jan 2022 16:09:42 +0100 Subject: [PATCH] add RTC --- include/MessenSensoren.h | 3 ++ platformio.ini | 10 +++--- src/MessenSensoren.cpp | 72 ++++++++++++++++++++++++++++++++++++++-- src/main.cpp | 6 ++-- 4 files changed, 82 insertions(+), 9 deletions(-) diff --git a/include/MessenSensoren.h b/include/MessenSensoren.h index 35b126c..e1c10a5 100644 --- a/include/MessenSensoren.h +++ b/include/MessenSensoren.h @@ -2,6 +2,9 @@ #define h_messenSensoren +void InitTimeDate(void); +void PrintTimeDate(void); + int16_t readVcc(void); void init_Messen(void); void MessenSensoren(void); diff --git a/platformio.ini b/platformio.ini index b3d5ac5..338f0d2 100644 --- a/platformio.ini +++ b/platformio.ini @@ -12,7 +12,9 @@ platform = atmelsam board = adafruit_feather_m0 framework = arduino -lib_deps = mcci-catena/MCCI LoRaWAN LMIC library@^4.1.1 -build_flags = - -D ARDUINO_LMIC_PROJECT_CONFIG_H_SUPPRESS - -D CFG_eu868=1 \ No newline at end of file +lib_deps = + mcci-catena/MCCI LoRaWAN LMIC library@^4.1.1 + arduino-libraries/RTCZero@^1.6.0 +build_flags = + -D ARDUINO_LMIC_PROJECT_CONFIG_H_SUPPRESS + -D CFG_eu868=1 diff --git a/src/MessenSensoren.cpp b/src/MessenSensoren.cpp index ffcbc40..a058d19 100644 --- a/src/MessenSensoren.cpp +++ b/src/MessenSensoren.cpp @@ -8,12 +8,72 @@ #include "BH1750.h" #include "hseSensorProtocol.h" #include "ATSAMD21_ADC.h" +#include #define I2C_POWER 5 // bei Feather M0 // hse-Protokoll Datensatz HseSP hse(2, 60); +RTCZero zerortc; +char szUhrzeit2[25]; +uint16_t uiOldHour; +uint16_t uiOnStd; + +// Uhr anhand des Compiler Zeitpunkt setzen +// es geht nur die Uhrzeit (Monat und Jahr von Hand) +void InitTimeDate(void) +{ +int h,m,t; + + zerortc.begin(); // Set up clocks + + // nutze das Compiler Datum zum Stellen der Uhr + h = (__TIME__[0]-0x30)*10; + h += (__TIME__[1]-0x30); + + m = (__TIME__[3]-0x30)*10; + m += (__TIME__[4]-0x30); + + //Jun 10 2020. + //01234567890 + t =(__DATE__[4]-0x30)*10; + t +=(__DATE__[5]-0x30); + + // Uhrzeit stellen + zerortc.begin(); // Set up clocks + zerortc.setTime(h, m, 1); + zerortc.setDate(t, 1, 22); + + uiOnStd = 0; + Serial.println(" InitTimeDate "); + + PrintTimeDate(); +} + +//-------------------------------------------------- +void PrintTimeDate(void) +{ +int i; + +// Datum auch + sprintf(szUhrzeit2, "%02d.%02d.%02d ", zerortc.getDay(), zerortc.getMonth(), zerortc.getYear() ); + Serial.print(szUhrzeit2); + +// Zum Test Uhrzeit ausgeben + sprintf(szUhrzeit2, "%02d:%02d:%02d", zerortc.getHours(), zerortc.getMinutes(), zerortc.getSeconds() ); + Serial.println(szUhrzeit2); + +// gesammt Stunden berechnen +i = zerortc.getHours(); +if ( uiOldHour != i) + { + uiOldHour = i; + uiOnStd++; + Serial.println(uiOnStd); + } +} + //-------------------------------------------------------------------------------------------------- @@ -32,7 +92,10 @@ return result; - +//-------------------------------------- +// Messung vorbereiten +// zeig welche Sensoren angeschlossen sind +//-------------------------------------- void init_Messen() { int i; @@ -77,12 +140,15 @@ void init_Messen() { Serial.println("ende"); } -//-------------------------- +//------------------------------------------ +// Messwerte beschaffen +//------------------------------------------ void MessenSensoren() { int i; float t, p, h, fUb; unsigned int lVisLux; + PrintTimeDate(); Set_I2C_Adresse(BME280_ADR); i = I2C_read8(BME280_REGISTER_CHIPID); @@ -146,5 +212,5 @@ void MessenSensoren() { hse.addClimateSensor(&cs); hse.addVoltage(fUb/1000.0); // in Volt - // hse.addCounter(uiOnStd); // Zeit On + hse.addCounter(uiOnStd); // Zeit On } diff --git a/src/main.cpp b/src/main.cpp index 5f1415c..d788307 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,7 +32,7 @@ * *******************************************************************************/ - +#define CFG_sx1276_radio 1 #include #include @@ -276,7 +276,7 @@ void setup() { delay(5000); //while (!Serial); Serial.begin(19200); - Serial.println(F("Starting 1.02")); + Serial.println(F("Starting 1.03")); #ifdef __SAMD21G18A__ Serial.println(F("SAMD21G18A ARM Cortex-M0+ detected")); @@ -287,6 +287,8 @@ void setup() { init_Messen(); + InitTimeDate(); // RTC Starten + #ifdef CFG_eu868 Serial.println(F("Using EU868"));