RTC ERROR : SYNC! need a little help here.

Hi peoples,

I am using a 2.4 inch TFT LCD SPFD5408 with Arduino Uno directly connected, so the TFT LCD shield is on top of it. I added a time clock module to display it on the bottom of the monitor of my project. My project is a weather station with a dht11 and a soil hygrometer, I made a whole new interface for this screen. But the only thing that isn't working is the clock. I know this code was originally for a mega, and that should be no problem, there is a problem with setting the pins i think.

Now i connected the pins for the clock the following way:

VCC on clock --> 3v on arduino uno
GND on clock --> GND next to pin 13 on arduino uno
CLK on clock --> PIN D8 on arduino
DAT on clock --> PIN D9 on arduino
RST on clock --> PIN D10 on arduino

I know this part of the script is not right there are not that many pins on the UNO.. but
when you look at fritzing and hold your mouse at the GND pin on Digital pwm, you will see a number 58, when holding your mouse over the 3v3 pin you will see a number 87. So that is why these pins are set, my GND and VCC are connected to those.

#define DS1302_GND_PIN 58
#define DS1302_VCC_PIN 87

Here are some detailed pictures i added to imgur.

Imgur

Imgur

Imgur

Imgur

here is a part of the code with setting for the pin etc.

//Author Danny van den brande.

#include "DHT.h"
#include <SPFD5408_Adafruit_GFX.h>    // Core graphics library
#include <SPFD5408_Adafruit_TFTLCD.h> // Hardware-specific library
#include <SPFD5408_TouchScreen.h>
//                                    BEGIN CLOCK
#include <DS1302RTC.h>//clock module DS1302
#include <Time.h>//Need for clock module
// Init the DS1302
// Set pins:  CE, IO,CLK
DS1302RTC RTC(8, 9, 10);
// Optional connection for RTC module
#define DS1302_GND_PIN 58
#define DS1302_VCC_PIN 87
//                                      END CLOCK++++++++

#define DHTPIN 13     // what pin we're connected to
#define DHTTYPE DHT11 // DHT 11

#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0

#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin

// Assign human-readable names to some common 16-bit color values:
#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

// OBJECTS LCD ET DHT

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

DHT dht(DHTPIN, DHTTYPE);

float hprev, tprev, hicprev;
int moisture = 0;
int sensorValue;
void setup() {
//                                  CLOCK MODULE BEGIN
digitalWrite(DS1302_GND_PIN, LOW);
  pinMode(DS1302_GND_PIN, OUTPUT);

  digitalWrite(DS1302_VCC_PIN, HIGH);
  pinMode(DS1302_VCC_PIN, OUTPUT);

  tft.print("RTC activated");

  delay(500);

  ////////////////////////////////////////////////////////////////
  ///////STel tijd voor clock hier in              /////
  ///////////////////////////////////////////////////////////////
  //ZET TIJD HIER BENEDEN+++++++++++++++++++++++++++++++++
  setTime(6,10,0,28,01,2016);
  time_t t = now();
  RTC.set(t);
  //ZET TIJD HIER BOVEN+++++++++++++++++++++++++++++++++++

  // Check clock oscillation  
  
  if (RTC.haltRTC())
    tft.print("Clock stopped!");
  else
    tft.print("Clock working.");

  // Check write-protection
  tft.setCursor(0,1);
  if (RTC.writeEN())
    tft.print("Write allowed.");
  else
    tft.print("Write protected.");

  delay ( 2000 );

  // Setup Time library  
  
  tft.print("RTC Sync");
  setSyncProvider(RTC.get); // the function to get the time from the RTC
  if(timeStatus() == timeSet)
    tft.print(" Ok!");
  else
    tft.print(" FAIL!");

  delay ( 2000 );

  {
}

#define DS1302_GND_PIN 58
#define DS1302_VCC_PIN 87

There aren't that many pins on the UNO.

Pete

Hi,

I know that, i know i got something wrong with setting the pins, i did not change that yet.
its still how it was by default in the Clock script, dunno who set that, but not me.
If you look at the pics you see how i connected it to the arduino.
I just need to know why i dont have a working clock.

what do i need to change in the code to make the clock work?
I set the pins right for the CLK DAT RST for the clock?
I set he GND and VCC on the right place for the clock?

The CLK and DAT pin numbers don't look right. According to https://www.arduino.cc/en/Hacking/PinMapping168 they should be: A4 = SDA pin and A5 = SCL.

You should remove this:

#define DS1302_GND_PIN 58
#define DS1302_VCC_PIN 87

and this:

digitalWrite(DS1302_GND_PIN, LOW);
  pinMode(DS1302_GND_PIN, OUTPUT);

  digitalWrite(DS1302_VCC_PIN, HIGH);
  pinMode(DS1302_VCC_PIN, OUTPUT);

I don't know what digitalWrite and pinMode do with numbers that are larger than are available on the chip, but safest to get rid of it and not take any chances. Incidentally, it appears that this bit of code is intended to power the RTC from pin 87 so that the RTC can be programmably powered on and off.

Pete

el_supremo:
The CLK and DAT pin numbers don't look right. According to https://www.arduino.cc/en/Hacking/PinMapping168 they should be: A4 = SDA pin and A5 = SCL.

You should remove this:

#define DS1302_GND_PIN 58

#define DS1302_VCC_PIN 87




and this:


digitalWrite(DS1302_GND_PIN, LOW);
  pinMode(DS1302_GND_PIN, OUTPUT);

digitalWrite(DS1302_VCC_PIN, HIGH);
  pinMode(DS1302_VCC_PIN, OUTPUT);




I don't know what digitalWrite and pinMode do with numbers that are larger than are available on the chip, but safest to get rid of it and not take any chances. Incidentally, it appears that this bit of code is intended to power the RTC from pin 87 so that the RTC can be programmably powered on and off.

Pete

I am using a uno

Yes, I know. That's why I gave you the link to the pinout for the UNO and, in particular that A4 = SDA pin and A5 = SCL.

Pete

I don't know the relationship between the attached .ino file and what you posted within the code tags. But if the attached file is actually the code you are trying to run, then nowhere in the loop() do you update the time. The only place you write the time is in iniText().

You need an updateDateTime() function in the loop just like you have for the other sensors.

cattledog:
I don't know the relationship between the attached .ino file and what you posted within the code tags. But if the attached file is actually the code you are trying to run, then nowhere in the loop() do you update the time. The only place you write the time is in iniText().

You need an updateDateTime() function in the loop just like you have for the other sensors.

I know the code is messed up,
but its ok i fixed it. i placed the time part in the initext first i was just moving around the text. I was actualy planning to remove the iniText part... but i removed all the code parts of the clock and rewritten the whole code for the clock with a code from the arduino website. It works ok perfect now.
when i unplug the arduino and put it on 5 minutes later the time is still synchronized it 30 seconds behind on my computer everytime i upload the sketch or reset.
now i only need to clean up the code a bit and add 5 more moisture sensors.

Gr33tz and thanks for the responds guys.