Skocz do zawartości

Problem z DS1307


Mrpatryk

Pomocna odpowiedź

Witam, przyszedł dzisiaj do mnie DS1307, wgrałem podstawowa biblioteke DS1307 https://github.com/jarzebski/Arduino-DS1307 odpalam przykład z http://www.jarzebski.pl/arduino/komponenty/zegar-czasu-rzeczywistego-rtc-ds1307.html i lipa .zero odzwu stoi na inicjalizacji ds1307 ... Wszystkie połączenia posprawdzane, testowany na arduino nano mini oraz na Uno niestety bez skutku ... Co może być nie tak ? WADLIWY ?? 

 

 

Napięcia względem masy: scl +4,98v, sda 5v, vcc+5v

Edytowano przez Mrpatryk
Link do komentarza
Share on other sites

Sprawdź podłączenie.

Uruchom sobie i2c_scanner (tutaj) i zobaczysz jakie urządzenia masz podpięte do i2c no i jakie mają adresy. Zapomnij o tej bibliotece, tez kiedyś próbowałem z niej korzystać i były jakieś kłopoty. Lepszym rozwiązaniem jest  RTC by Makuna dostępna z poziomu Menadżera Bibliotek. Używam od dłuższego czasu z DS3231 i z pewnością z DS1307 także będzie działać super.

Link do komentarza
Share on other sites

Zarejestruj się lub zaloguj, aby ukryć tę reklamę.
Zarejestruj się lub zaloguj, aby ukryć tę reklamę.

jlcpcb.jpg

jlcpcb.jpg

Produkcja i montaż PCB - wybierz sprawdzone PCBWay!
   • Darmowe płytki dla studentów i projektów non-profit
   • Tylko 5$ za 10 prototypów PCB w 24 godziny
   • Usługa projektowania PCB na zlecenie
   • Montaż PCB od 30$ + bezpłatna dostawa i szablony
   • Darmowe narzędzie do podglądu plików Gerber
Zobacz również » Film z fabryki PCBWay

przykład pusciłem to pokazuje jakieś krzaki ... ⸮⸮BC⸮⸮⸮fBE⸮
4]H⸮Pr⸮S⸮FBBE⸮⸮⸮⸮FFCBE⸮⸮⸮b⸮RC5⸮⸮


// CONNECTIONS:
// DS1307 SDA --> SDA
// DS1307 SCL --> SCL
// DS1307 VCC --> 5v
// DS1307 GND --> GND

/* for software wire use below
#include <SoftwareWire.h>  // must be included here so that Arduino library object file references work
#include <RtcDS1307.h>

SoftwareWire myWire(SDA, SCL);
RtcDS1307<SoftwareWire> Rtc(myWire);
 for software wire use above */

/* for normal hardware wire use below */
#include <Wire.h> // must be included here so that Arduino library object file references work
#include <RtcDS1307.h>
RtcDS1307<TwoWire> Rtc(Wire);
/* for normal hardware wire use above */

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

    Serial.print("compiled: ");
    Serial.print(__DATE__);
    Serial.println(__TIME__);

    //--------RTC SETUP ------------
    // if you are using ESP-01 then uncomment the line below to reset the pins to
    // the available pins for SDA, SCL
    // Wire.begin(0, 2); // due to limited pins, use pin 0 and 2 for SDA, SCL
    
    Rtc.Begin();

    RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
    printDateTime(compiled);
    Serial.println();

    if (!Rtc.IsDateTimeValid()) 
    {
        // Common Cuases:
        //    1) first time you ran and the device wasn't running yet
        //    2) the battery on the device is low or even missing

        Serial.println("RTC lost confidence in the DateTime!");

        // following line sets the RTC to the date & time this sketch was compiled
        // it will also reset the valid flag internally unless the Rtc device is
        // having an issue

        Rtc.SetDateTime(compiled);
    }

    if (!Rtc.GetIsRunning())
    {
        Serial.println("RTC was not actively running, starting now");
        Rtc.SetIsRunning(true);
    }

    RtcDateTime now = Rtc.GetDateTime();
    if (now < compiled) 
    {
        Serial.println("RTC is older than compile time!  (Updating DateTime)");
        Rtc.SetDateTime(compiled);
    }
    else if (now > compiled) 
    {
        Serial.println("RTC is newer than compile time. (this is expected)");
    }
    else if (now == compiled) 
    {
        Serial.println("RTC is the same as compile time! (not expected but all is fine)");
    }

    // never assume the Rtc was last configured by you, so
    // just clear them to your needed state
    Rtc.SetSquareWavePin(DS1307SquareWaveOut_Low); 
}

void loop () 
{
    if (!Rtc.IsDateTimeValid()) 
    {
        // Common Cuases:
        //    1) the battery on the device is low or even missing and the power line was disconnected
        Serial.println("RTC lost confidence in the DateTime!");
    }

    RtcDateTime now = Rtc.GetDateTime();

    printDateTime(now);
    Serial.println();

    delay(10000); // ten seconds
}

#define countof(a) (sizeof(a) / sizeof(a[0]))

void printDateTime(const RtcDateTime& dt)
{
    char datestring[20];

    snprintf_P(datestring, 
            countof(datestring),
            PSTR("%02u/%02u/%04u %02u:%02u:%02u"),
            dt.Month(),
            dt.Day(),
            dt.Year(),
            dt.Hour(),
            dt.Minute(),
            dt.Second() );
    Serial.print(datestring);
}

 

 poprawiłem już prędkość , jednak dostaje taka odpowiedz compiled: Jan 24 201923:10:11
23:10:17.985 -> 01/24/2019 23:10:11
23:10:18.019 -> RTC lost confidence in the DateTime!
23:10:18.053 -> RTC was not actively running, starting now
23:10:18.121 -> RTC lost confidence in the DateTime!
23:10:18.155 -> 165/165/2165 37:165
address didn't match
RTC lost confidence in the DateTime!
23:10:28.149 -> 165/165/2165 37:165
address didn't match
RTC lost confidence in the DateTime!
23:10:38.171 -> 165/165/2165 37:165
address didn't match
RTC lost confidence in the DateTime!
23:10:48.162 -> 165/165/2165 37:165

 

na początku dobra date i godzine podał a potem juz nie .

jakiś pomysł  ?

Link do komentarza
Share on other sites

Już ręce mi opadaja.

#include <RtcDateTime.h>

#include <RtcDS1307.h>

#include <RtcUtility.h>
#include <ThreeWire.h>
#include <Wire.h>
RtcDS1307<TwoWire> Rtc(Wire);
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>





void setup () {
  Serial.begin(9600);
  Rtc.Begin();
RtcDateTime(__DATE__, __TIME__);
  delay(100);
}

void loop () {
   RtcDateTime now = Rtc.GetDateTime();
    Serial.print(now.Day(), DEC);
    Serial.print('/');
    Serial.print(now.Month(), DEC);
    Serial.print('/');
    Serial.print(now.Year(), DEC);
    Serial.print(" (");
   
    Serial.print(") ");
    Serial.print(now.Hour(), DEC);
    Serial.print(':');
    Serial.print(now.Minute(), DEC);
    Serial.print(':');
    Serial.print(now.Second(), DEC);
    Serial.println();
    
    delay(3000); //Print date and time every 3 sec
}

Po tym kodzie otrzymuje... 


-165/165/2165 () 37:165:85
-165/165/2165 () 37:165:85
-165/165/2165 () 37:165:85
-165/165/2165 () 37:165:85
-165/165/2165 () 37:165:85 i tak w koło ... dziwny ten zegar.. żadna z blibliotek nie chce działać ...

Jest to śmieszne, bo po i2c scanner go znajduje, a on i tak te wartości widzę ze bierze z du... bo nawet jak SDA i SCL wypnę to dalej to samo  pokazuje

Link do komentarza
Share on other sites

Wyświetla cały czas to

14:22:58.975 -> 01/25/2019 14:22:18
14:22:58.975 -> RTC lost confidence in the DateTime!
14:22:58.975 -> RTC was not actively running, starting now
14:22:59.009 -> RTC is older than compile time!  (Updating DateTime)
14:22:59.009 -> RTC lost confidence in the DateTime!
14:22:59.009 -> 165/165/2165 37:165
14:23:09.001 -> RTC lost confidence in the DateTime!
14:23:09.035 -> 165/165/2165 37:165
14:23:19.024 -> RTC lost confidence in the DateTime!
14:23:19.024 -> 165/165/2165 37:165
14:23:29.019 -> RTC lost confidence in the DateTime!
14:23:29.019 -> 165/165/2165 37:165
14:23:39.043 -> RTC lost confidence in the DateTime!
14:23:39.043 -> 165/165/2165 37:165
14:23:49.022 -> RTC lost confidence in the DateTime!
14:23:49.022 -> 165/165/2165 37:165
14:23:59.016 -> RTC lost confidence in the DateTime!
14:23:59.052 -> 165/165/2165 37:165

// CONNECTIONS:
// DS1307 SDA --> SDA
// DS1307 SCL --> SCL
// DS1307 VCC --> 5v
// DS1307 GND --> GND

/* for software wire use below
#include <SoftwareWire.h>  // must be included here so that Arduino library object file references work
#include <RtcDS1307.h>

SoftwareWire myWire(SDA, SCL);
RtcDS1307<SoftwareWire> Rtc(myWire);
 for software wire use above */

/* for normal hardware wire use below */
#include <Wire.h> // must be included here so that Arduino library object file references work
#include <RtcDS1307.h>
RtcDS1307<TwoWire> Rtc(Wire);
/* for normal hardware wire use above */

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

    Serial.print("compiled: ");
    Serial.print(__DATE__);
    Serial.println(__TIME__);

    //--------RTC SETUP ------------
    // if you are using ESP-01 then uncomment the line below to reset the pins to
    // the available pins for SDA, SCL
    // Wire.begin(0, 2); // due to limited pins, use pin 0 and 2 for SDA, SCL
    
    Rtc.Begin();

    RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
    printDateTime(compiled);
    Serial.println();

    if (!Rtc.IsDateTimeValid()) 
    {
        // Common Cuases:
        //    1) first time you ran and the device wasn't running yet
        //    2) the battery on the device is low or even missing

        Serial.println("RTC lost confidence in the DateTime!");

        // following line sets the RTC to the date & time this sketch was compiled
        // it will also reset the valid flag internally unless the Rtc device is
        // having an issue

        Rtc.SetDateTime(compiled);
    }

    if (!Rtc.GetIsRunning())
    {
        Serial.println("RTC was not actively running, starting now");
        Rtc.SetIsRunning(true);
    }

    RtcDateTime now = Rtc.GetDateTime();
    if (now < compiled) 
    {
        Serial.println("RTC is older than compile time!  (Updating DateTime)");
        Rtc.SetDateTime(compiled);
    }
    else if (now > compiled) 
    {
        Serial.println("RTC is newer than compile time. (this is expected)");
    }
    else if (now == compiled) 
    {
        Serial.println("RTC is the same as compile time! (not expected but all is fine)");
    }

    // never assume the Rtc was last configured by you, so
    // just clear them to your needed state
    Rtc.SetSquareWavePin(DS1307SquareWaveOut_Low); 
}

void loop () 
{
    if (!Rtc.IsDateTimeValid()) 
    {
        // Common Cuases:
        //    1) the battery on the device is low or even missing and the power line was disconnected
        Serial.println("RTC lost confidence in the DateTime!");
    }

    RtcDateTime now = Rtc.GetDateTime();

    printDateTime(now);
    Serial.println();

    delay(10000); // ten seconds
}

#define countof(a) (sizeof(a) / sizeof(a[0]))

void printDateTime(const RtcDateTime& dt)
{
    char datestring[20];

    snprintf_P(datestring, 
            countof(datestring),
            PSTR("%02u/%02u/%04u %02u:%02u:%02u"),
            dt.Month(),
            dt.Day(),
            dt.Year(),
            dt.Hour(),
            dt.Minute(),
            dt.Second() );
    Serial.print(datestring);
}

 

mam moduł Tiny RTC I2C Modules ten z bateryjka i opcją podłączenia Dallasa do temperatury .

SCL-> A5,

 SDA->A4,

Gnd->GND,

Vcc->+5V

Arduino nano mini .

Link do komentarza
Share on other sites

Dołącz do dyskusji, napisz odpowiedź!

Jeśli masz już konto to zaloguj się teraz, aby opublikować wiadomość jako Ty. Możesz też napisać teraz i zarejestrować się później.
Uwaga: wgrywanie zdjęć i załączników dostępne jest po zalogowaniu!

Anonim
Dołącz do dyskusji! Kliknij i zacznij pisać...

×   Wklejony jako tekst z formatowaniem.   Przywróć formatowanie

  Dozwolonych jest tylko 75 emoji.

×   Twój link będzie automatycznie osadzony.   Wyświetlać jako link

×   Twoja poprzednia zawartość została przywrócona.   Wyczyść edytor

×   Nie możesz wkleić zdjęć bezpośrednio. Prześlij lub wstaw obrazy z adresu URL.

×
×
  • Utwórz nowe...

Ważne informacje

Ta strona używa ciasteczek (cookies), dzięki którym może działać lepiej. Więcej na ten temat znajdziesz w Polityce Prywatności.