Hi , I have connected two devices to Nano.
- DS1307
- 0.9 OLED DISPLAY 128X32
eVERYTHING IS FINE when display is only working, bu when I introduce rtc codes into it only rtc responds, displays stops. Please explain procedure to call one by one. I want to display current time. The coding is not very good, it is borrowed from here and there. Currently it only displays the current year in serial monitor but nothing on oled display
#include "RTClib.h"
RTC_DS1307 rtc;
#include <Arduino.h>
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // Adafruit Feather ESP8266/32u4 Boards + FeatherWing OLED
void setup(void) {
Serial.begin(57600);
u8g2.begin();
u8g2.enableUTF8Print(); // enable UTF8 support for the Arduino print() function
#ifndef ESP8266
while (!Serial); // wait for serial port to connect. Needed for native USB
#endif
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
while (1) delay(10);
}
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running, let's set the time!");
// When time needs to be set on a new device, or after a power loss, the
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
}
void loop(void) {
u8g2.setFont(u8g2_font_simple1_tf);
u8g2.setFontDirection(0);
u8g2.clearBuffer();
u8g2.setCursor(0, 15);
u8g2.print("Hello World!");
u8g2.setCursor(0, 30);
u8g2.print("Naushad");
u8g2.sendBuffer();
DateTime now = rtc.now();
Serial.print(now.year(), DEC);
delay(1000);
}