ATTiny85 not connecting to DS3231 RTC Module

I’ve been trying to figure this out for over two weeks now, and I’m officially stuck. I have this DS3231 RTC module. Using the following code from this RTCLib library, it works perfectly with my ESP32:

#include "RTClib.h"

RTC_DS3231 rtc;

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


  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    Serial.flush();
    abort();
  }
  if (rtc.lostPower()) {
    Serial.println("RTC lost power, let's set the time!");
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }

}

void loop () {
    DateTime now = rtc.now();
    // prints more date stuff
}

So I used that same code on my ATTiny85, except using software serial (I have a USB to TTL connected). So the code for my ATTiny85 is the following:

#include <SoftwareSerial.h>
#include "RTClib.h"
RTC_DS3231 rtc;   


SoftwareSerial mySerial(3, 4);  // rx, tx


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

   mySerial.println("Starting up...");
  if (! rtc.begin()) {
    mySerial.println("Couldn't find RTC");
    Serial.flush();
    abort();
  }
  if (rtc.lostPower()) {
    mySerial.println("RTC lost power, let's set the time!");
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }

}

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

    //prints more date stuff
}

**The problem is that after it prints “Starting up…”, nothing else gets printed to the console. It seems to be failing at the rtc.begin line. **

Just in case it was this particular library, I tried the DS3232RTC.h library using the following code:

#include <SoftwareSerial.h>
#include <DS3232RTC.h>         


SoftwareSerial mySerial(3, 4);  // rx, tx


void setup()
{
    mySerial.begin(9600); // 9600 baud
    mySerial.println("Starting!!");
    mySerial.println("Getting reading to connect to RTC...");
    setSyncProvider(RTC.get);
    mySerial.println("RTC Sync");
    if (timeStatus() != timeSet) mySerial.println(" FAIL!");
 
      
}

void loop()
{
// prints date stuff
}

Again, it stops after “Getting reading to connect to RTC…”. So like before, the RTC.get seems to not be working.

As far as my circuit, I double-checked to make sure the SDA and SDL of the RTC module are connected to the SDA and SDL of the ATTIny85.

The RTC module is powered by 3v3 volts from my ESP32 (not shown). My ATTiny85 is powered by 4.5 volts battery. It’s running at 8 MHz and using the Tinycore board manager.

I also read something about needing pull-up resistors on the I2C bus. So I attempted to add two 4.7K resistors. I’m still new to electronics so this might be the wrong configuration but this is what I did:

But still, either way, it freezes after “Starting…” with the first code and “Getting reading to connect to RTC…” on the second. Any ideas why?

Where is the variable timeSet initiated?

In neither of the tiny85 codes are you printing anything in loop(). How do you know that the program is not working?

SDA and SCL already have 4.7K pullup resistors on the RTC module. You shouldn't add additional ones.

I can't tell from the pictures - is the ground of the RTC module connected to the ground of the ATTiny?

groundFungus:
In neither of the tiny85 codes are you printing anything in loop(). How do you know that the program is not working?

Sorry, I removed those for abbreviation. In that loop I am printing the date and time from the RTC module. It looks like this:

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(") ");
    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);
}

However, nothing in the loop prints. I don't even think it's getting to the loop.

ShermanP:
SDA and SCL already have 4.7K pullup resistors on the RTC module. You shouldn't add additional ones.

I can't tell from the pictures - is the ground of the RTC module connected to the ground of the ATTiny?

No, the ground of the RTC module is connected to the ground of the ESP32 (where it' power is coming from).

  Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');

Aren’t you using a software serial port (mySerial)?

I wired up a tiny85 and RTC as close to your wiring as I could see. I added print statements to your code using the RTClib library. It works.

#include <SoftwareSerial.h>
#include "RTClib.h"
RTC_DS3231 rtc;

SoftwareSerial mySerial(3, 4);  // rx, tx

void setup ()
{
   mySerial.begin(9600);
   mySerial.println("Starting up...");
   if (! rtc.begin())
   {
      mySerial.println("Couldn't find RTC");
      mySerial.flush();
      abort();
   }
   if (rtc.lostPower())
   {
      mySerial.println("RTC lost power, let's set the time!");
      rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
   }
}

void loop ()
{
   static unsigned long timer = 0;
   unsigned long interval = 1000;
   if (millis() - timer >= interval)
   {
      timer = millis();
      DateTime now = rtc.now();
      mySerial.print(now.hour());
      mySerial.print(":");
      mySerial.print(now.minute());
      mySerial.print(":");
      mySerial.println(now.second());
   }
}

Output:

Starting up...
8:43:48
8:43:49
8:43:50
8:43:51
8:43:52
8:43:53
8:43:54

groundFungus:

  Serial.print('/');

Serial.print(now.month(), DEC);
   Serial.print(’/’);



Aren't you using a software serial port (mySerial)?


I wired up a tiny85 and RTC as close to your wiring as I could see. I added print statements to your code using the RTClib library. It works.



#include <SoftwareSerial.h>
#include “RTClib.h”
RTC_DS3231 rtc;

SoftwareSerial mySerial(3, 4);  // rx, tx

void setup ()
{
  mySerial.begin(9600);
  mySerial.println(“Starting up…”);
  if (! rtc.begin())
  {
     mySerial.println(“Couldn’t find RTC”);
     mySerial.flush();
     abort();
  }
  if (rtc.lostPower())
  {
     mySerial.println(“RTC lost power, let’s set the time!”);
     rtc.adjust(DateTime(F(DATE), F(TIME)));
  }
}

void loop ()
{
  static unsigned long timer = 0;
  unsigned long interval = 1000;
  if (millis() - timer >= interval)
  {
     timer = millis();
     DateTime now = rtc.now();
     mySerial.print(now.hour());
     mySerial.print(":");
     mySerial.print(now.minute());
     mySerial.print(":");
     mySerial.println(now.second());
  }
}




Output:


Starting up…
8:43:48
8:43:49
8:43:50
8:43:51
8:43:52
8:43:53
8:43:54

It works for you? I have no idea why mine isn’t. Sorry, that was partially my ESP32 code. Here’s the full code I just deployed on attiny85. I added a final print statement in the setup, but it never gets to that print statement:

#include <SoftwareSerial.h>
#include "RTClib.h"
RTC_DS3231 rtc;   


SoftwareSerial mySerial(3, 4);  // rx, tx


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

   mySerial.println("Starting up..."); //This prints
  if (! rtc.begin()) {  //I'm pretty sure it's failing here, nothing happens past this
    mySerial.println("Couldn't find RTC");
    Serial.flush();
    abort();
  }
  if (rtc.lostPower()) {
    mySerial.println("RTC lost power, let's set the time!");
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }

    mySerial.println("Connectedted to RTC"); //Never prints this statement, doesn't get to this point

}

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

    mySerial.print(now.year(), DEC);
    mySerial.print('/');
    mySerial.print(now.month(), DEC);
    mySerial.print('/');
    mySerial.print(now.day(), DEC);
    mySerial.print(" (");
    mySerial.print(") ");
    mySerial.print(now.hour(), DEC);
    mySerial.print(':');
    mySerial.print(now.minute(), DEC);
    mySerial.print(':');
    mySerial.print(now.second(), DEC);
    mySerial.println();

     

    mySerial.println();
    delay(3000);
}

Btw, thanks for taking the time to wire it and try it yourself. I do appreciate the help :slight_smile:

groundFungus:

  Serial.print('/');

Serial.print(now.month(), DEC);
   Serial.print(’/’);



Aren't you using a software serial port (mySerial)?


I wired up a tiny85 and RTC as close to your wiring as I could see. I added print statements to your code using the RTClib library. It works.



#include <SoftwareSerial.h>
#include “RTClib.h”
RTC_DS3231 rtc;

SoftwareSerial mySerial(3, 4);  // rx, tx

void setup ()
{
  mySerial.begin(9600);
  mySerial.println(“Starting up…”);
  if (! rtc.begin())
  {
     mySerial.println(“Couldn’t find RTC”);
     mySerial.flush();
     abort();
  }
  if (rtc.lostPower())
  {
     mySerial.println(“RTC lost power, let’s set the time!”);
     rtc.adjust(DateTime(F(DATE), F(TIME)));
  }
}

void loop ()
{
  static unsigned long timer = 0;
  unsigned long interval = 1000;
  if (millis() - timer >= interval)
  {
     timer = millis();
     DateTime now = rtc.now();
     mySerial.print(now.hour());
     mySerial.print(":");
     mySerial.print(now.minute());
     mySerial.print(":");
     mySerial.println(now.second());
  }
}




Output:


Starting up…
8:43:48
8:43:49
8:43:50
8:43:51
8:43:52
8:43:53
8:43:54

I just tried the code you posted, and the only output that I receive is “Starting up…”

With your latest code on my setup I get:

2020/12/9 () 9:19:6

2020/12/9 () 9:19:9

2020/12/9 () 9:19:12

2020/12/9 () 9:19:15

2020/12/9 () 9:19:18

I can't tell from the pictures - is the ground of the RTC module connected to the ground of the ATTiny?

No, the ground of the RTC module is connected to the ground of the ESP32 (where it' power is coming from).

The grounds should all be connected together.

groundFungus:
The grounds should all be connected together.

That was it!!! Thank you so much. I can't believe at two weeks that never occurred to me.

Is it fine to keep the power sources seperate? As in, I power the RTC through 3.3v and the ATTiny85 with 4.5v but have all the grounds running to the ATTiny85?

That was it!!! Thank you so much.

Thank ShermanP for that.

Is it fine to keep the power sources seperate? As in, I power the RTC through 3.3v and the ATTiny85 with 4.5v but have all the grounds running to the ATTiny85?

You got it, but not necessarily to the tiny85 ground. All grounds should tie to one point and that point is, ideally, close to the power source. See this grounding tutorial.

Thank you!!