TFT Clock I2C Problem

Hi guys,

Just wondering if anyone could offer any advice, I'm using an arduuino Uno and the TFT shield by adafruit using their library: Overview | 2.8" TFT Touch Shield | Adafruit Learning System here. I'm also using a ds1307 module using the Arduino wire library. I am trying to get the LCD t display the time from the ds1307, the only problem is that when I call the getDateDs1307 function (currently commented out in the code) it stops the LCD from working and it just shows a white screen, however it correctly shows the time if I reset the screen after calling the function to get the time from the ds1307. Only problem is I only want to reset the screen once upon start, I don't want to initialise it every time!

Any help much appreciated!

#define LCD_CS A3    
#define LCD_CD A2    
#define LCD_WR A1   
#define LCD_RD A0    
#define LCD_RESET A4
#define DS1307_I2C_ADDRESS 0x68
#define	BLACK           0x0000
#define	BLUE            0x001F
#define	RED             0xF800
#define	GREEN           0x07E0
#define CYAN            0x07FF
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0 
#define WHITE           0xFFFF
#define PURPLE          0xF81F

#include "TFTLCD.h"
#include "Wire.h"

TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
  return ( (val/10*16) + (val%10) );
}

// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return ( (val/16*10) + (val%16) );
}

// Gets the date and time from the ds1307
void getDateDs1307(byte *second,
          byte *minute,
          byte *hour,
          byte *dayOfWeek,
          byte *dayOfMonth,
          byte *month,
          byte *year)
{
  // Reset the register pointer
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.write(0);
  Wire.endTransmission();
  
  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

  // A few of these need masks because certain bits are control bits
  *second     = bcdToDec(Wire.read() & 0x7f);
  *minute     = bcdToDec(Wire.read());
  *hour       = bcdToDec(Wire.read() & 0x3f);  // Need to change this if 12 hour am/pm
  *dayOfWeek  = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month      = bcdToDec(Wire.read());
  *year       = bcdToDec(Wire.read());
}

void setup(void) {
  Wire.begin();
  tft.initDisplay();
  tft.setRotation(3); 
  tft.fillScreen(BLACK);
}

void loop(void) {
  //getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
  tft.setCursor(0, 0);
  tft.setTextColor(GREEN);
  tft.setTextSize(6);
  tft.print(hour);
  tft.print(":");
  tft.print(minute);
  tft.print(":");
  tft.print(second);
  delay(1000);
}

ben967:

#define LCD_RESET A4

If that says what I think it does, there is a very major and inexplicable fault in the design of the shield.

On the Uno, A4 (analog 4) is reserved as SDA - I2C data - so if it has been allocated for use as the shield reset, then using the I2C function will always reset (clear) the display.

According to the schematic for the genuine Adafruit display shield, the display reset is tied to the Arduino reset, so it clearly should not be connected to A4 and I can hardly imagine that LadyAda would make such a terrible blunder.

Without examining the TFTLCD.h library, I am not sure whether it actually uses the "LCD_RESET" allocation, but the behaviour you describe does suggest that the reset line is in fact connected to A4 and it would seem you need to correct this erroneous connection that has somehow been made (on the shield) and confusingly documented,

Is this a genuine board? It would not be (by any means) the first time that the wiring in a "counterfeit" had been incorrectly copied. :smiley:

Hi,
Thanks for the help, unfortunately it is a cheap eBay module from china but it happens to work using the adafruit library. Changing this pin does seem to help the problem but now the display resets randomly as it feels like it! Maybe I should just buy an adafruit module. :~

I came across this issue to day, As suggested by Paul__B if you bend Pin A4 from the cheap'o LCD screen our the way so that it does not connect to the Arduino, then connect that bent pint to the reset pin of the arduino {LCD-A4-->REST-Arduino} It works fine.
Now just looks a bit ugly i think i will solder a new pin to the top of the lcd and bend it to one side.

Same issue here with a cheap Banggood 2.8 TFT display (http://0.klet.st/28TFTuno). It clearly needs a reset in order to start. Solution is simple: desolder the pin going into A4 and solder a short jumper wire to the Arduino's reset, which is on the same end. Very simple and neat: