I2C device using MCUFRIEND library


I am developing a board that must display the current time, as read from an RTC. I am using a DS3231 RTC and Arduino Nano Evey board. Library used is RTClib from Adafruit and MCUFRIEND_kbv for the TFT screen.

As the RTC is running on the I2C bus, I have already moved the A4 pin from the LCD and put it on 5V with a 10K resistor. I am sure both the screen and RTC work, as if they are tested individually they do in fact work as planned. However, I am trying to use both toghether and I can not succed in it.

This is the code I am using (stripped down):

// time
#include "RTClib.h"
RTC_DS3231 rtc;

// screen
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#include <TouchScreen.h>
#define MINPRESSURE 200
#define MAXPRESSURE 3000
const int XP = 8, XM = A2, YP = A3, YM = 9; //ID=0x9341
const int TS_LEFT = 141, TS_RT = 905, TS_TOP = 948, TS_BOT = 91;
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 281);
Adafruit_GFX_Button btn_config, btn_home, btn_light, btn_lightA, btn_lightY, btn_lightN, btn_fanA, btn_fanY, btn_onP, btn_onM, btn_offP, btn_offM;
int pixel_x, pixel_y;     //Touch_getXY() updates global vars

void setup() {
  uint16_t ID = tft.readID();
  tft.setRotation(0);            //PORTRAIT
  tft.fillRect(0, 370, 320, 110, TFT_BLUE);


void loop() {
  DateTime now = rtc.now();

  Serial.print(now.year(), DEC);
  Serial.print(now.month(), DEC);
  Serial.print(now.day(), DEC);
  Serial.print(' ');
  Serial.print(now.hour(), DEC);
  Serial.print(now.minute(), DEC);
  Serial.print(now.second(), DEC);


The serial prints are obviously here for debug. When stating the program, everything up to FOUR is printed. THis leads me to believe the issue coours when reading the time with DateTime now = rtc.now();
I have no idea how to resolve this issue.

I was previously running the code on UNO board with a different library (DS3232RTC) successfully, but it is not supported on megaAVR boards so I moved to Adafruit’s.

Any help is appreciated.

The RTC is now working as espected. I modified the mcufriend_shield.h definitons and changed line 138 from:

#define RESET_PIN  2


#define RESET_PIN  4

From my limited knolwdge this should start using the A6 pin for reset (it’s disconnected anyway) and it frees up the A4 pin, making my RTC work. Not sure if there are other implications by doing so.
If a moderator can move this topic to the display section, it might be more appropriate and be helpful for further discussion.