Browse Source

add RTC

master
Ralf Behrens 4 years ago
parent
commit
7a829687e8
  1. 3
      include/MessenSensoren.h
  2. 10
      platformio.ini
  3. 72
      src/MessenSensoren.cpp
  4. 6
      src/main.cpp

3
include/MessenSensoren.h

@ -2,6 +2,9 @@ @@ -2,6 +2,9 @@
#define h_messenSensoren
void InitTimeDate(void);
void PrintTimeDate(void);
int16_t readVcc(void);
void init_Messen(void);
void MessenSensoren(void);

10
platformio.ini

@ -12,7 +12,9 @@ @@ -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
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

72
src/MessenSensoren.cpp

@ -8,12 +8,72 @@ @@ -8,12 +8,72 @@
#include "BH1750.h"
#include "hseSensorProtocol.h"
#include "ATSAMD21_ADC.h"
#include <RTCZero.h>
#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; @@ -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() { @@ -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() { @@ -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
}

6
src/main.cpp

@ -32,7 +32,7 @@ @@ -32,7 +32,7 @@
*
*******************************************************************************/
#define CFG_sx1276_radio 1
#include <lmic.h>
#include <hal/hal.h>
@ -276,7 +276,7 @@ void setup() { @@ -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() { @@ -287,6 +287,8 @@ void setup() {
init_Messen();
InitTimeDate(); // RTC Starten
#ifdef CFG_eu868
Serial.println(F("Using EU868"));

Loading…
Cancel
Save