rtc DS1302 Help

salve, sto costruendo una centralina per gli irrigatori e al momento di configurare l'rtc non riesco a farlo partire, il resto funziona tutto piu o meno bene (arduino UNO rev3, 4 relè, 4led, telecomando RF 4 tasti e igrometro). Ho provato a cercare delle librerie nel web .. ma con tutte quelle che ho provato non riesco ad usarlo .. il risultato è piu o meno questo:
"xxxxxxxxx 00.00.2000 -- 00:00:00
xxxxxxxxx 00.00.2000 -- 00:00:00
xxxxxxxxx 00.00.2000 -- 00:00:00"
qualsiasi data, ora, minuto metta è sempre 00:00:00.

è da oggi pomeriggio che io e un mio amico ci scervelliamo per trovare una soluzione .. Aiutatemi!!
P:S il mio amico ha studiato informatica, io no .. ma mi piace lavorare manualmente e sto imparando a leggere i codici a forza di scriverli.
Vi ringrazio in anticipo

Per favore schema elettrico o foto o descrizione cosa dove hai collegato. Serve anche lo sketch. pPi non sarebbe male sapere che modello di Arduino hai.
Ciao Uwe

ciao Uwe, allora inanzitutto uso Arduino uno r3 come gia scritto nel primo post.
I pin che io ho usato sono i seguenti:
digitalPin:
1 Rele1
2 Rele2
3 Rele3
4 Rele4
5 Igrometro
6 Rtc CLK
7 Rtc DAT
8 Rtc RST
9 Remoto1
10 Remoto2
11 Remoto3
12 Remoto4
13 /

Analogpin:
0 /
1 Led4
2 Led3
3 Led2
4 Led1
5 /

lo sketch che uso al momento è questo, funzioma ma ho bisogno di aggiungere l'RTC per far partire la "routin" in automatico.

int rele[]    = {1, 2, 3, 4};
int igrometro = 5;
int clk       = 6;
int dat       = 7;
int rst       = 8;
int remoto[]  = {11, 9, 12, 10};
int led[]     = {18, 17, 16, 15};
boolean isOn1;
boolean isOn2;
boolean acceso;


void setup() {
  acceso = true;  
  isOn1 = false;
  isOn2 = false;
  
  for(int i = 0; i < 4; i++) {
    pinMode(rele[i], OUTPUT);
    pinMode(remoto[i], INPUT);
    pinMode(led[i], OUTPUT); 
  }
 
  pinMode(igrometro, INPUT);
  pinMode(clk, INPUT);
  pinMode(dat, INPUT);
}

static void rem1()
{
  if(!isOn1)
  {
    digitalWrite(led[1], LOW);
    digitalWrite(rele[2], HIGH);
    digitalWrite(rele[1], LOW);
    digitalWrite(rele[0], HIGH);
    digitalWrite(led[0], HIGH);
    isOn1 = true;
  } else{
      digitalWrite(rele[2], LOW);
      digitalWrite(rele[0], LOW);
      digitalWrite(led[0], LOW);
      isOn1 = false;
    }
}

static void rem2()
{
  if(!isOn2)
  {
    digitalWrite(led[0], LOW);
    digitalWrite(rele[2], HIGH);
    digitalWrite(rele[0], LOW);
    digitalWrite(rele[1], HIGH);
    digitalWrite(led[1], HIGH);
    isOn2 = true;
  } else{
      digitalWrite(rele[2], LOW);
      digitalWrite(rele[1], LOW);
      digitalWrite(led[1], LOW);
      isOn2 = false;
    }
}

static void routine()
{
  digitalWrite(led[0], LOW);
  digitalWrite(led[2], HIGH);
  digitalWrite(rele[2], HIGH);
  digitalWrite(rele[0], LOW);
  digitalWrite(rele[0], LOW);
  for(int i = 0; i < 12; i++)
  {
	digitalWrite(led[1], LOW);
        digitalWrite(rele[0], HIGH);
	digitalWrite(led[0], HIGH);
    delay(3000);
	digitalWrite(led[0], LOW);
        digitalWrite(rele[0], LOW);
        digitalWrite(rele[1], HIGH);
	digitalWrite(led[1], HIGH);
    delay(3000);
    digitalWrite(rele[1], LOW);
    digitalWrite(led[1], LOW);
  }
  digitalWrite(led[2], LOW);
  digitalWrite(rele[2], LOW);
}

void loop() {
  // se remoto1 = high allora rele1 = high and rele2 = low and rele3 = high and led1 = high.
  // se remoto2 = high allora rele2 = high and rele1 = low and rele3 = high and led2 = high.
  // se remoto3 = high allora remoto1 = high per 5 minuti then remoto2 = high per 5 minuti ripetuto  per 12. 
  // se remoto4 = high allora rele1-3 = Low.
  if (acceso)
  {
    if (digitalRead(remoto[0]) == HIGH)
      rem1();
	else
		if (digitalRead(remoto[1]) == HIGH)
			rem2();
		else	
			if (digitalRead(remoto[2]) == HIGH)
				routine();
  }else
  if (digitalRead(remoto[3]) == HIGH)
  {
    digitalWrite(rele[2], LOW);
    acceso = !acceso;
  }    
}

invece il codice che ho provato per settare l'RTC l'ho preso da Arduino Playground - DS1302, da alcuni esempi da delle librerie come GitHub - msparks/arduino-ds1302: Arduino library for the DS1302 Real Time Clock chip, Electronics - Henning Karlsen ma in tutti i casi quelle che mi riporta sulla seriale è simile a
xxxxxxxxx 00.00.2000 -- 00:00:00
xxxxxxxxx 00.00.2000 -- 00:00:00
xxxxxxxxx 00.00.2000 -- 00:00:00

PS ovviamente nello sketch per l'RTC ho cambiato i pin per farli combaciare con il mio hardware .. ho anche provato a fare l'inverso cioè a spostare i miei collegamenti per non cambiare lo sketch .. non cambia niente.

Scusami non avevo notato che lo avevi scritto.
Non usare il pin D1 perché viene usato dal interfaccia USB. puó farti comutare il relé alcune volte nei primi secondi dopo l' accensione /reset.
Per favore dacci lo sketch che non Ti funziona.
Ciao Uwe

si ho notato che il rele sul D1 si eccita quando uso la USB .. ma non è un problema fino a quando non eccito anche il rele3 ..
questo è il codice che non funziona

// DS1302_Serial_Easy (C)2010 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// A quick demo of how to use my DS1302-library to 
// quickly send time and date information over a serial link
//
// I assume you know how to connect the DS1302.
// DS1302:  CE pin    -> Arduino Digital 8
//          I/O pin   -> Arduino Digital 7
//          SCLK pin  -> Arduino Digital 6

#include <DS1302.h>

// Init the DS1302
DS1302 rtc(8, 7, 6);

void setup()
{
  // Set the clock to run-mode, and disable the write protection
  rtc.halt(false);
  rtc.writeProtect(false);
  
  // Setup Serial connection
  Serial.begin(9600);

  // The following lines can be commented out to use the values already stored in the DS1302
  rtc.setDOW(FRIDAY);        // Set Day-of-Week to FRIDAY
  rtc.setTime(12, 0, 0);     // Set the time to 12:00:00 (24hr format)
  rtc.setDate(6, 8, 2010);   // Set the date to August 6th, 2010
}

void loop()
{
  // Send Day-of-Week
  Serial.print(rtc.getDOWStr());
  Serial.print(" ");
  
  // Send date
  Serial.print(rtc.getDateStr());
  Serial.print(" -- ");

  // Send time
  Serial.println(rtc.getTimeStr());
  
  // Wait one second before repeating :)
  delay (1000);
}

e questo è quello che mi riporta sulla seriale

xxxxxxxxx 00.00.2000 -- 00:00:00
xxxxxxxxx 00.00.2000 -- 00:00:00
xxxxxxxxx 00.00.2000 -- 00:00:00
xxxxxxxxx 00.00.2000 -- 00:00:00
xxxxxxxxx 00.00.2000 -- 00:00:00
xxxxxxxxx 00.00.2000 -- 00:00:00
xxxxxxxxx 00.00.2000 -- 00:00:00
xxxxxxxxx 00.00.2000 -- 00:00:00
xxxxxxxxx 00.00.2000 -- 00:00:00
xxxxxxxxx 00.00.2000 -- 00:00:00
xxxxxxxxx 00.00.2000 -- 00:00:00

edit:
ho provato anche questo codice.. ma niente

// Example sketch for interfacing with the DS1302 timekeeping chip.
//
// Copyright (c) 2009, Matt Sparks
// All rights reserved.
//
// http://quadpoint.org/projects/arduino-ds1302
#include <stdio.h>
#include <DS1302.h>

namespace {

// Set the appropriate digital I/O pin connections. These are the pin
// assignments for the Arduino as well for as the DS1302 chip. See the DS1302
// datasheet:
//
//   http://datasheets.maximintegrated.com/en/ds/DS1302.pdf
const int kCePin   = 8;  // Chip Enable
const int kIoPin   = 7;  // Input/Output
const int kSclkPin = 6;  // Serial Clock

// Create a DS1302 object.
DS1302 rtc(kCePin, kIoPin, kSclkPin);

String dayAsString(const Time::Day day) {
  switch (day) {
    case Time::kSunday: return "Sunday";
    case Time::kMonday: return "Monday";
    case Time::kTuesday: return "Tuesday";
    case Time::kWednesday: return "Wednesday";
    case Time::kThursday: return "Thursday";
    case Time::kFriday: return "Friday";
    case Time::kSaturday: return "Saturday";
  }
  return "(unknown day)";
}

void printTime() {
  // Get the current time and date from the chip.
  Time t = rtc.time();

  // Name the day of the week.
  const String day = dayAsString(t.day);

  // Format the time and date and insert into the temporary buffer.
  char buf[50];
  snprintf(buf, sizeof(buf), "%s %04d-%02d-%02d %02d:%02d:%02d",
           day.c_str(),
           t.yr, t.mon, t.date,
           t.hr, t.min, t.sec);

  // Print the formatted string to serial so we can see the time.
  Serial.println(buf);
}

}  // namespace

void setup() {
  Serial.begin(9600);

  // Initialize a new chip by turning off write protection and clearing the
  // clock halt flag. These methods needn't always be called. See the DS1302
  // datasheet for details.
  rtc.writeProtect(false);
  rtc.halt(false);

  // Make a new time object to set the date and time.
  // Sunday, September 22, 2013 at 01:38:50.
  Time t(2013, 9, 22, 1, 38, 50, Time::kSunday);

  // Set the time and date on the chip.
  rtc.time(t);
}

// Loop and print the time every second.
void loop() {
  printTime();
  delay(1000);
}

in questo caso mi da una valanga di errori alla compilazione

Ho riscontrato alcuni problemi se non si inserisce la pila nel modulo RTC oppure se il contatto è incerto. Controlla!

cyberhs:
Ho riscontrato alcuni problemi se non si inserisce la pila nel modulo RTC oppure se il contatto è incerto. Controlla!

ho controllato la batteria .. 1V .. l'ho cambiata .. ma il problema non è cambiato ..
per contatto incerto quale intendi?

oggi pomeriggio ho provato il modulo sull'arduino uno di un mio amico .. senza modificare gli sketch ma spostando i pin sulla board .. non va ..
abbiamo provato anche la libreria presa da qua http://blog.trendsmix.com/?p=93 .. lo sketch è questo qua sotto:

/*
Example sketch for interfacing with the DS1302 timekeeping chip.

Copyright (c) 2009, Matt Sparks
All rights reserved.

http://quadpoint.org/projects/arduino-ds1302
*/
#include <stdio.h>
#include <string.h>
#include <DS1302.h>

/* Set the appropriate digital I/O pin connections */
uint8_t CE_PIN   = 8;
uint8_t IO_PIN   = 7;
uint8_t SCLK_PIN = 6;

/* Create buffers */
char buf[50];
char day[10];

/* Create a DS1302 object */
DS1302 rtc(CE_PIN, IO_PIN, SCLK_PIN);


void print_time()
{
  /* Get the current time and date from the chip */
  Time t = rtc.time();

  /* Name the day of the week */
  memset(day, 0, sizeof(day));  /* clear day buffer */
  switch (t.day) {
    case 1:
      strcpy(day, "Sunday");
      break;
    case 2:
      strcpy(day, "Monday");
      break;
    case 3:
      strcpy(day, "Tuesday");
      break;
    case 4:
      strcpy(day, "Wednesday");
      break;
    case 5:
      strcpy(day, "Thursday");
      break;
    case 6:
      strcpy(day, "Friday");
      break;
    case 7:
      strcpy(day, "Saturday");
      break;
  }

  /* Format the time and date and insert into the temporary buffer */
  snprintf(buf, sizeof(buf), "%s %04d-%02d-%02d %02d:%02d:%02d",
           day,
           t.yr, t.mon, t.date,
           t.hr, t.min, t.sec);

  /* Print the formatted string to serial so we can see the time */
  Serial.println(buf);
}


void setup()
{
  Serial.begin(9600);

  /* Initialize a new chip by turning off write protection and clearing the
     clock halt flag. These methods needn't always be called. See the DS1302
     datasheet for details. */
  rtc.write_protect(false);
  rtc.halt(false);

  /* Make a new time object to set the date and time */
  /*   Tuesday, May 19, 2009 at 21:16:37.            */
  Time t(2009, 5, 19, 21, 16, 37, 3);

  /* Set the time and date on the chip */
  rtc.time(t);
}


/* Loop and print the time every second */
void loop()
{
  print_time();
  delay(1000);
}

il risultato sulla seriale è questo:

 2000-00-00 00:00:00
 2000-00-00 00:00:00
 2000-00-00 00:00:00
 2000-00-00 00:00:00
 2000-00-00 00:00:00
 2000-00-00 00:00:00
 2000-00-00 00:00:00

Scusa,
ma se tu carichi così come è l'esempio del playground (allegato a questo mio post) SENZA modificarlo (occhio quindi a quali pin usare) ... che risultato ti da ? :roll_eyes:

Guglielmo

EDIT : Hai letto anche che : "The three pins for the interface should avoid to use the internal pull-up resistors of the Arduino. The DS1302 has internal pull-down resistors, and the CE and SCLK lines should be low when inactive.
Some schematics on the internet have pull-up resistors on the three interface lines. That is wrong. Other schematics use two 22pF with the crystal. That is also wrong. See the datasheet for full specifications and a circuit."

ds1302.zip (4.62 KB)

gpb01:
Scusa,
ma se tu carichi così come è l'esempio del playground (allegato a questo mio post) SENZA modificarlo (occhio quindi a quali pin usare) ... che risultato ti da ? :roll_eyes:

Guglielmo

EDIT : Hai letto anche che : "The three pins for the interface should avoid to use the internal pull-up resistors of the Arduino. The DS1302 has internal pull-down resistors, and the CE and SCLK lines should be low when inactive.
Some schematics on the internet have pull-up resistors on the three interface lines. That is wrong. Other schematics use two 22pF with the crystal. That is also wrong. See the datasheet for full specifications and a circuit."

ho caricato lo sketch che mi hai messo in allegato senza modifiche dato che i pin erano già corretti, questo è quello che mi mostra la seriale:

DS1302 Real Time Clock
Version 2, March 2013
Time = 00:00:00, Date(day of month) = 0, Month = 0, Day(day of week) = 0, Year = 2000
Time = 00:00:00, Date(day of month) = 0, Month = 0, Day(day of week) = 0, Year = 2000
Time = 00:00:00, Date(day of month) = 0, Month = 0, Day(day of week) = 0, Year = 2000
Time = 00:00:00, Date(day of month) = 0, Month = 0, Day(day of week) = 0, Year = 2000
Time = 00:00:00, Date(day of month) = 0, Month = 0, Day(day of week) = 0, Year = 2000
Time = 00:00:00, Date(day of month) = 0, Month = 0, Day(day of week) = 0, Year = 2000
Time = 00:00:00, Date(day of month) = 0, Month = 0, Day(day of week) = 0, Year = 2000
Time = 00:00:00, Date(day of month) = 0, Month = 0, Day(day of week) = 0, Year = 2000
Time = 00:00:00, Date(day of month) = 0, Month = 0, Day(day of week) = 0, Year = 2000
Time = 00:00:00, Date(day of month) = 0, Month = 0, Day(day of week) = 0, Year = 2000
Time = 00:00:00, Date(day of month) = 0, Month = 0, Day(day of week) = 0, Year = 2000
Time = 00:00:00, Date(day of month) = 0, Month = 0, Day(day of week) = 0, Year = 2000
Time = 00:00:00, Date(day of month) = 0, Month = 0, Day(day of week) = 0, Year = 2000
Time = 00:00:00, Date(day of month) = 0, Month = 0, Day(day of week) = 0, Year = 2000
Time = 00:00:00, Date(day of month) = 0, Month = 0, Day(day of week) = 0, Year = 2000
Time = 00:00:00, Date(day of month) = 0, Month = 0, Day(day of week) = 0, Year = 2000
Time = 00:00:00, Date(day of month) = 0, Month = 0, Day(day of week) = 0, Year = 2000
Time = 00:00:00, Date(day of month) = 0, Month = 0, Day(day of week) = 0, Year = 2000

Quindi ... ho lo hai collegato male o il modulo è guasto ... :roll_eyes:

Propendo più per la prima ipotesi, ma tutto è possibile ... XD

Ti è stato chiesto fin dall'inizio di mettere LO SCHEMA (il disegno) esatto dei collegamenti (non solo l'elenco dei pin che usi), ma ancora non lo hai fatto ... :roll_eyes:

Guglielmo

ecco lo schema .. semplice ma vedete come è collegato il tutto .. ovviamente i led hanno una resistenza da 200ohm che nello schema ho sottinteso

Ma il DS 1302 è montato su una scheda che hai comprato (è in tal caso cortesemente metti il link al prodotto) o hai preso l'integrato e lo hai messo tu su una breadboard ???

Guglielmo

si scusa, è un modulo gia completo .. comprato da qua:

Ok, quindi si suppone che abbia il giusto quarzo e sia collegato bene ...
... se stacchi TUTTO e colleghi SOLO il modulo e fai girare il programma del playground, non va ugualmente ?

Guglielmo

P.S. : Nel tuo schema immagino tu ... abbia sott'inteso anche l'alimentazione del modulo vero ? XD

gpb01:
P.S. : Nel tuo schema immagino tu ... abbia sott'inteso anche l'alimentazione del modulo vero ? XD[/i]

giusta osservazione :slight_smile: .. si tutto è alimentato dalla +5v dell'arduino ..
oggi pomeriggio ho provato con solo l'rtc e l'arduino di un mio amico e con una libreria di quelle sopra citate e dava sempre lo stesso problema .. domani mattina provo a collegarlo senza gli altri componenti ma con lo sketch che mi hai mandato prima ..
speriamo bene.

ho fatto altre prove adesso .. ho controllato con il tester se tutti i collegamenti erano corretti e lo sono, ho provato anche le piste sulla scheda rtc e sono corrette .. a questo punto l'ipotesi è che sia rotto .. mi consiglieresti un valido sostituto? Ho visto che molti usano il modulo con il ds1307 ..
ho trovato questo Shield DS 1307 modulo RTC real time clock I2C per Arduino/PIC - ART. CL12 | eBay ma vedo che ha molti piu pin dell'altro ..

Ha più pin perchè ha anche un chip eeprom

nid69ita:
Ha più pin perchè ha anche un chip eeprom

e come va utilizzato?

Tieni anche conto che gli RTC non sono tutti uguali ed hanno precisioni diverse:
Qui ne hanno parlato: Problema con controllore serra - #8 by leo72 - Software - Arduino Forum