Hey Danke euch schon mal sehr an der stelle.
Ich poste bisschen mein Kartoffelsalat
.
#include <Arduino.h>
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
#include <DS3231.h>
#define SDA_PIN 21
#define SCL_PIN 22
RTClib myRTC;
void setup(void) {
Serial.begin(57600);
u8g2.begin();
u8g2.clearBuffer();
Wire.begin(SDA_PIN, SCL_PIN);
pinMode(2, OUTPUT);
digitalWrite(2, HIGH);
pinMode(13, INPUT_PULLUP); //Set pin for time/date mode button to input
digitalWrite(13, HIGH); //Turn on pullup resistors
pinMode(12, INPUT_PULLUP); //Set pin for time/date set button to input
digitalWrite(12, HIGH); //Turn on pullup resistors
pinMode(14, INPUT_PULLUP); //Set pin for external alarm indicator output
digitalWrite(14, LOW); //Initialize external alarm to off state
}
void loop(void) {
DateTime now = myRTC.now();
digitalWrite(2, HIGH);
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_spleen16x32_mf);
u8g2.setCursor(178,20);
u8g2.print(now.hour(), DEC);
u8g2.print(':');
u8g2.print(now.minute(), DEC);
} while ( u8g2.nextPage() );
delay(1000);
}
So funktioniert es die Uhrzeit aus dem RTC zu ziehen und auf dem Display anzeigen zu lassen.
Die Libs habe ich mehr oder weniger viele von GitHub.
So hatte ich zusammen gebaut, da startet das Gerät nicht:
#include <WiFi.h> // For WiFi
#include <Arduino.h>
#include <U8g2lib.h>
#include "time.h" // For time things
#include "RTClib.h" // For DS3231 RTC Module
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
#define SDA_PIN 21
#define SCL_PIN 22
U8G2_GP1294AI_256X48_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/18, /* data=*/23, /* cs=*/25, /* dc=*/U8X8_PIN_NONE, /* reset=*/33);
const char* ssid = "............";
const char* password = "..............";
const int UTCOffset = +1;
struct tm timeinfo;
RTC_DS3231 rtc;
void setup(void) {
Serial.begin(115200);
u8g2.begin();
u8g2.clearBuffer();
Wire.begin(SDA_PIN, SCL_PIN);
//connect to WiFi
Serial.printf("Connecting to %s ", ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println(" CONNECTED");
configTime(0, 0, "pool.ntp.org");
getLocalTime(&timeinfo);
rtc.adjust(DateTime(mktime(&timeinfo)+UTCOffset*3600));
printRTCTime();
}
void loop(void) {
DateTime now = rtc.now();
printRTCTime();
delay(10000);
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_spleen16x32_mf);
u8g2.setCursor(178,20);
u8g2.print(now.hour(), DEC);
u8g2.print(':');
u8g2.print(now.minute(), DEC);
} while ( u8g2.nextPage() );
delay(1000);
}
void printRTCTime()
{
DateTime now = rtc.now();
Serial.print("RTC: ");
Serial.printf("%02d/%02d/%04d (%02d:%02d:%02d)\n", now.month(), now.day(), now.year(), now.hour(), now.minute(), now.second());
}
Setze ich diese Zeile hinein, da gehts net mehr...:
DateTime now = rtc.now();
Aus dem funktionierenden Lib zusammen mit dem Display, gibt es nen Beispiel, da wird aber über den Serielleeingabe gelöst:
/*
DS3231_set.pde
Eric Ayars
4/11
Test of set-time routines for a DS3231 RTC
*/
#include <DS3231.h>
#include <Wire.h>
DS3231 myRTC;
byte year;
byte month;
byte date;
byte dOW;
byte hour;
byte minute;
byte second;
void getDateStuff(byte& year, byte& month, byte& date, byte& dOW,
byte& hour, byte& minute, byte& second) {
// Call this if you notice something coming in on
// the serial port. The stuff coming in should be in
// the order YYMMDDwHHMMSS, with an 'x' at the end.
boolean gotString = false;
char inChar;
byte temp1, temp2;
char inString[20];
byte j=0;
while (!gotString) {
if (Serial.available()) {
inChar = Serial.read();
inString[j] = inChar;
j += 1;
if (inChar == 'x') {
gotString = true;
}
}
}
Serial.println(inString);
// Read year first
temp1 = (byte)inString[0] -48;
temp2 = (byte)inString[1] -48;
year = temp1*10 + temp2;
// now month
temp1 = (byte)inString[2] -48;
temp2 = (byte)inString[3] -48;
month = temp1*10 + temp2;
// now date
temp1 = (byte)inString[4] -48;
temp2 = (byte)inString[5] -48;
date = temp1*10 + temp2;
// now Day of Week
dOW = (byte)inString[6] - 48;
// now hour
temp1 = (byte)inString[7] -48;
temp2 = (byte)inString[8] -48;
hour = temp1*10 + temp2;
// now minute
temp1 = (byte)inString[9] -48;
temp2 = (byte)inString[10] -48;
minute = temp1*10 + temp2;
// now second
temp1 = (byte)inString[11] -48;
temp2 = (byte)inString[12] -48;
second = temp1*10 + temp2;
}
void setup() {
// Start the serial port
Serial.begin(57600);
// Start the I2C interface
Wire.begin();
}
void loop() {
// If something is coming in on the serial line, it's
// a time correction so set the clock accordingly.
if (Serial.available()) {
getDateStuff(year, month, date, dOW, hour, minute, second);
myRTC.setClockMode(false); // set to 24h
//setClockMode(true); // set to 12h
myRTC.setYear(year);
myRTC.setMonth(month);
myRTC.setDate(date);
myRTC.setDoW(dOW);
myRTC.setHour(hour);
myRTC.setMinute(minute);
myRTC.setSecond(second);
// Test of alarm functions
// set A1 to one minute past the time we just set the clock
// on current day of week.
myRTC.setA1Time(dOW, hour, minute+1, second, 0x0, true,
false, false);
// set A2 to two minutes past, on current day of month.
myRTC.setA2Time(date, hour, minute+2, 0x0, false, false,
false);
// Turn on both alarms, with external interrupt
myRTC.turnOnAlarm(1);
myRTC.turnOnAlarm(2);
}
delay(1000);
}
Mit Wlan gibts da leider nichts, ich weiß vielleicht ist es wirklich für euch sehr einfach und Ihr lachts über meine Dusseligkeit. Wäre ja auch irgendwo berechtigt, ich schnalle es einfach noch nicht.
Beachtet die anderen eingebunden Libs nicht so sehr, dieser Sketch ist zum testen da. Die Tasten sind quasi gerade auch noch blind.
Wollte erst Uhrzeitstellung über die Tasten realisieren, das ist aber noch heftiger im Umfang, eigentlich auch viel zu viel des guten. Mir reichen ja auch nur Stunden und Minuten, da muss man aber sich um alles unnötige kümmern, zumindest für meinen vorhaben.
Eigentlich war auch der Plan gar kein Wlan zu nutzen, wenn aber dieser nur über einen Menüpunkt die Zeit holt, bei bedarf wäre ja noch ok.
Sorry für die blöden Fragen