non riesco a settare ds1307

ciao,

ho preso un ds1307 su basetta con quarzo e batteria e vorrei settare l'orario;
ho collegato scl su A4 e sda su A5, poi 5v e gnd;
lo sketch è questo

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 RTC;

void setup () {
Serial.begin(57600);
Wire.begin();
RTC.begin();
DateTime dt6 (2012, 7, 4, 12, 22, 0);
RTC.adjust(dt6);
}

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

Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
Serial.println();
delay(3000);
}

e il risultato sul monitor è

2165/165/165 165:165:85

dove sbaglio? mi sembra tutto così banale....

Ti posso solo dare un esempio che ho usato, setta l'ora e data e se il ds1307 ha la batteria rimane settata. ovviamente va settato solo una volta con questo codice, vedi se ti e' utile

#include "Wire.h"
#define DS1307_ADDRESS 0x68

void setup(){
  Wire.begin();
  Serial.begin(9600);
  setDateTime(); //MUST CONFIGURE IN FUNCTION
}

void loop(){
  printDate();
  delay(1000);
}

void setDateTime(){

  byte second =      30; //0-59
  byte minute =      37; //0-59
  byte hour =        0; //0-23
  byte weekDay =     1; //1-7
  byte monthDay =    24; //1-31
  byte month =       10; //1-12
  byte year  =       11; //0-99

  Wire.beginTransmission(DS1307_ADDRESS);
  Wire.send(0); //stop Oscillator

  Wire.send(decToBcd(second));
  Wire.send(decToBcd(minute));
  Wire.send(decToBcd(hour));
  Wire.send(decToBcd(weekDay));
  Wire.send(decToBcd(monthDay));
  Wire.send(decToBcd(month));
  Wire.send(decToBcd(year));

  Wire.send(0); //start 

  Wire.endTransmission();

}

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

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

void printDate(){

  // Reset the register pointer
  Wire.beginTransmission(DS1307_ADDRESS);
  Wire.send(0);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_ADDRESS, 7);

  int second = bcdToDec(Wire.receive());
  int minute = bcdToDec(Wire.receive());
  int hour = bcdToDec(Wire.receive() & 0b111111); //24 hour time
  int weekDay = bcdToDec(Wire.receive()); //0-6 -> sunday - Saturday
  int monthDay = bcdToDec(Wire.receive());
  int month = bcdToDec(Wire.receive());
  int year = bcdToDec(Wire.receive());

  //print the date EG   3/1/11 23:59:59
  Serial.print(monthDay);
  Serial.print("/");  
  Serial.print(month);
  Serial.print("/");
  Serial.print(year);
  Serial.print(" ");
  Serial.print(hour);
  Serial.print(":");
  Serial.print(minute);
  Serial.print(":");
  Serial.println(second);

}

non funziona, sul monitor ricevo solo grupppi di 'à'

il codice che ho postato funziona, ora non posso far prove perche' non ho un ds1307 assemblato

ricordo che lo usai per settare ora e data, poi ho usato il 1307 programmato con un altro sketch su arduino per avere degli allarmi/sveglia con i tempi che leggeva dal 1307

aspetta che ti dice qualcun altro, ciao

SDA è il pin A4, e SCL il pin A5. Tu li hai invertiti:

willy12:
ciao,

ho preso un ds1307 su basetta con quarzo e batteria e vorrei settare l'orario;
ho collegato scl su A4 e sda su A5, poi 5v e gnd;

leo72:
SDA è il pin A4, e SCL il pin A5. Tu li hai invertiti:

ho scambiato ifili ma non cambia nulla, sarà rotto?

Sicuramente non per l'inversione dei fili. Hai una foto di questa schedina? Puoi fare una foto per vedere come l'hai collegata?

willy12:

leo72:
SDA è il pin A4, e SCL il pin A5. Tu li hai invertiti:

ho scambiato ifili ma non cambia nulla, sarà rotto?

non è che hai invertito anche l'alimentazione?

non è che hai invertito anche l'alimentazione?
[/quote]

no, su quella sono sicuro.

Hai provato a leggere che dati ti da?
se ti da FF:FF:FF significa che non ce comunicazione, se e collegato giusto ti da un orario e la data a caso.