Använd pollande testkod hittills (får själv försöka löda in mig på 32kHz och/eller fyrkantsvågpinnen, om jag vill åt dem):
Kod: Markera allt
// Include the libraries
#include <RtcDS3231.h>
//Open the Library Manager and search for "Rtc by Makuna" and install
#include <Wire.h>
// Create new RTC module
RtcDS3231<TwoWire> Rtc(Wire);
// Create variables for time
byte hours;
byte minutes;
byte seconds;
byte old;
byte oldM;
uint16_t year;
byte month;
byte day;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Rtc.Begin();
// Update RTC module time to compilation time
RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
compiled += 7; //transfer time
//Already set, comment this out:
//Rtc.SetDateTime(compiled);
//set 2019-03-03 ~15 EET
old = 0;
oldM = 0;
}
void loop() {
// put your main code here, to run repeatedly:
delay(10);
updateTime();
if(minutes != oldM){
printDate();
}
else if(seconds != old){
printTime();
}
}
void updateTime() {
RtcDateTime now = Rtc.GetDateTime();
hours = now.Hour();
minutes = now.Minute();
seconds = now.Second();
year = now.Year();
month = now.Month();
day = now.Day();
}
#define countof(a) (sizeof(a) / sizeof(a[0]))
void printTime(){
char timestring[9];
snprintf_P(timestring,
countof(timestring),
PSTR("%02u:%02u:%02u"),
hours,
minutes,
seconds );
Serial.println(timestring);
old = seconds;
}
void printDate(){
oldM = minutes;
char datestring[12];
snprintf_P(datestring,
countof(datestring),
PSTR("%04u-%02u-%02u "),
year,
month,
day );
Serial.print(datestring);
printTemperature();
printTime();
}
void printTemperature(){
RtcTemperature temp = Rtc.GetTemperature();
Serial.print(temp.AsFloatDegC());
Serial.println("°C");
}
Kod: Markera allt
import serial
import time
import datetime
ser = serial.Serial(
port='COM18',\
baudrate=115200,\
parity=serial.PARITY_NONE,\
stopbits=serial.STOPBITS_ONE,\
bytesize=serial.EIGHTBITS,\
timeout=0)
print("connected to: " + ser.portstr)
size = 10
while (size > 0):
line = ser.readline()
if(line!=""):
timestamp = str(time.time())
print timestamp + ": " + line
size -= 1
ser.close()
Inledande "mätning":
Kod: Markera allt
connected to: COM18
1551640907.06: 2019-03-03 26.50┬║C
1551640907.06: 21:21:46
1551640907.06:
1551640907.18: 21:21:47
1551640908.19: 21:21:48
1551640909.18: 21:21:4
1551640909.19: 9
1551640910.18: 21:21:50
1551640911.19: 21:21:51
1551640912.19: 21:21:52
Kod: Markera allt
connected to: COM18
1551658807.0: 2019-03-04 26.25┬░C
1551658807.0: 02:20:06
1551658807.23: 02:20:07
1551658808.22: 02:20:08
1551658809.23: 02:20:09
1551658810.23: 0
1551658810.23: 2:20:10
1551658811.23: 02:20:11
1551658812.22: 02:20:12
1551658813.23: 02:20:13
Projekt? ...tja vi får se hur det utvecklar sig, om jag deltar i Kjells tävling. Ligger här i "öppen tråd" oavsett.