swarkn
Letzte Artikel von swarkn (Alle anzeigen)
- Creality Ender-5 Smoother - 3. März 2019
- NodeMCU gecheckt ✔ (Teil 1) - 9. Juli 2018
- Akkutausch meines Samsung YH-J70 - 30. März 2017
Dieses Beispiel gehört zur Baugruppe: Tiny RTC I2C Module und dient der Veranschaulichung der allgemeinen Kommunikation mit dem DS1307 (lesen der RAW-Daten) und dem Schreiben der gelesenen Werte in den NVRAM.
Ihr könnt das Beispiel noch erweitern, in dem Ihr den NVRAM mit Sensordaten füllt und danach einen „roll-over“ macht. Interessant wäre auch die Möglichkeit herauszufinden, ob die RTC einen Spannungsverlust erlitten hat. Es gibt noch so viel mehr Möglichkeiten. Aber – so viel Sand und keine Förmchen.
Screenshot des seriellen Monitors |
![]() |
// // This is a demo, how to use the DS1307 to read the time direct from RAM and write it into the 56 Bytes of NVRAM // Stefan (swarkn) from http://www.do-it-neat.com // // This demo need the following libraries: // https://github.com/jcw/rtclib // // Please note: i put things a bit appart to better understand and read the code. // // includes #include <Wire.h> #include <RTClib.h> RTC_DS1307 RTC; // Set the namespace RTC to DS1307 // global variables byte i; // counter byte data[8]; // hold read data void setup(void) { Serial.begin(9600); // start serial port //// //// Start DS1307 setup //// Wire.begin(); // start I²C Bus RTC.begin(); // start communicating to I2C device 0x68 (DS1307) RTC.adjust(DateTime(__DATE__, __TIME__)); // set RTC date and time to compilation time } void loop(void) { //// //// Do the DS1307 operations //// Serial.print("Read from low RAM (0x00-0x08): "); for ( i = 0; i < 8; i++) { // read 9 bytes of time register into NVRAM data[i] = RTC.readByteInRam(i); Serial.print(data[i], HEX); Serial.print(" "); } Serial.println(); Serial.print("Write to NVRAM (0x08-0x10): "); for ( i = 0; i < 8; i++) { // write the 9 bytes into NVRAM RTC.writeByteInRam(i + 0x08,data[i]); Serial.print(data[i], HEX); Serial.print(" "); } Serial.println(); Serial.print("Read from NVRAM (0x08-0x10): "); for ( i = 0; i < 8; i++) { // read the 9 bytes from NVRAM Serial.print(RTC.readByteInRam(i + 0x08), HEX); Serial.print(" "); } Serial.println(); Serial.println(); //// //// wait some time //// delay(1000); }
Viel Spaß damit :),
swarkn