Adapting sketch to upload to ATTiny85 board

I am attempting to upload a sketch that is currently running on a Nano to a ATTiny85 board. So far, no success. I have installed the necessary drivers for the ATTiny85 board in the Arduino IDE software, and uploaded a test sketch (blink), which does work. So the board is OK. But when uploading the desired sketch to the ATTiny, it won’t finish compiling. This sketch does work (it is for a digital clock with custom display). Is it too large to fit on the ATTiny85? Or does it need to be modified? Any assistance would be appreciated.

#include "Wire.h"
#include "DS3231.h"
#define DS3231_I2C_ADDRESS 0x68
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
Adafruit_8x16matrix matrix = Adafruit_8x16matrix();


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 setDS3231time(byte second, byte minute, byte hour);

void setup()
{
  Wire.begin();
  matrix.begin(0x70);  // pass in the address
  Serial.begin(9600);
  // set the initial time here:
  // DS3231 seconds, minutes, hours
   setDS3231time(45,59,23); 
}


 void loop()
{
  displayTime(); // display the real-time clock data on the Serial Monitor,
  delay(500); // every second
}

static const uint8_t PROGMEM
colon_bmp[] =
   {
    B0,       
    B1,
    B0,
    B1,
    B0,
 
    B0,
    B1,
    B0,
    B1,
    B0
   };

static const uint8_t PROGMEM
  digit_bmp[10][5] = {
  { B1110,
    B1010,
    B1010,
    B1110,
    B0100 }, // Zero
  { B1000,
    B0000,
    B0000,
    B1110,
    B0100 }, // One
  { B1100,
    B0000,
    B0000,
    B1110,
    B0100 }, // Two
  { B1110,
    B0000,
    B0000,
    B1110,
    B0100 }, // Three
  { B1110,
    B1000,
    B0000,
    B1110,
    B0100 }, // Four
  { B1110,
    B1100,
    B0000,
    B1110,
    B0100 }, // Five
  { B1110,
    B1110,
    B0000,
    B1110,
    B0100 }, // Six
  { B1110,
    B1110,
    B1000,
    B1110,
    B0100 }, // Seven
  { B1110,
    B1110,
    B1100,
    B1110,
    B0100 }, // Eight
  { B1110,
    B1110,
    B1110,
    B1110,
    B0100 } // Nine
  };


void setDS3231time(byte second, byte minute, byte hour)   // sets time data to DS3231
{ 
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set next input to start at the seconds register
  Wire.write(decToBcd(second)); // set seconds
  Wire.write(decToBcd(minute)); // set minutes
  Wire.write(decToBcd(hour)); // set hours
  Wire.endTransmission();
}
 

void readDS3231time
(byte *second,
 byte *minute,
 byte *hour)
{
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0);                             // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);   // request seven bytes of data from DS3231 starting from register 00h 
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f);
}
 
void displayTime()
{
  byte second, minute, hour;                 // retrieve data from DS3231 
  readDS3231time(&second, &minute, &hour);   // send it to the serial monitor 
   if( hour == 0 )
    hour = 12; // 12 midnight
  else if(hour  > 12)
    hour = hour - 12 ;
  Serial.print(hour, DEC);               // convert the byte variable to a decimal number when displayed 
  Serial.print(":");
  if (minute<10)
  {
    Serial.print("0");
  }
  Serial.print(minute, DEC);
  Serial.print(":");
  if (second<10)
  {
    Serial.print("0");
  }
  Serial.print(second, DEC);
  Serial.print(" ");

  matrix.clear();
  matrix.drawBitmap(0, 0, colon_bmp, 8, 10, LED_ON);
  matrix.drawBitmap(-3, 0, digit_bmp[hour / 10], 7, 5, LED_ON);
  matrix.drawBitmap(0, 0, digit_bmp[hour % 10], 7, 5, LED_ON);
  matrix.drawBitmap(-3, 5, digit_bmp[minute / 10], 7, 5, LED_ON);
  matrix.drawBitmap(0, 5, digit_bmp[minute % 10], 7, 5, LED_ON);
  matrix.drawBitmap(-3, 10, digit_bmp[second / 10], 7, 5, LED_ON);
  matrix.drawBitmap(0, 10, digit_bmp[second % 10], 7, 5, LED_ON);
  matrix.writeDisplay();
  delay(500);

}

ATTiny85 board.jpg

Does it show any warning or error messages before the compiler "doesn't finish"?

Try turning up the compiler warnings in Preferences.

Try turning on verbose compiler logging in Preferences.

NOW does it display any messages?

I would suspect that one or more of the libraries you are using might not support some non-Arduino hardware. You should get error messages if undefined registers are used or the code won't fit in memory.

Thanks for the reply. I was able to determine the problem. The library for the LED display is too big to fit on the ATTiny85, and there is no alternative code to replace it that will fit. So I will be sticking with the Nano.

jeredneus: Thanks for the reply. I was able to determine the problem. The library for the LED display is too big to fit on the ATTiny85, and there is no alternative code to replace it that will fit. So I will be sticking with the Nano.

Really? Ive been using Adafruit's gfx and led backpacks (with their libraries) with tiny 85s all along!

I think the problem lies elsewhere. First thing I see is that you include the Wire library. That library doesn't work with the Tiny85. The next thing I see is the tiny85 board you show. It must be running a custom bootloader, cause it has a usb connector, which may be using a lot of memory. Third, you are using Serial, which also is not supported by the Tiny85.

If a nano works, great! But if you are really after the small size of a tiny, get a chip, and program it with a programmer, rather than the board (which looks almost as big as a nano.)

I'm not at my workshop right now, but Monday when I return, I can post some tiny85 code that uses an Adafruit LED display, a 3231rtc, and all the libraries to make it all work, if you are still interested.

ChrisTenone: I'm not at my workshop right now, but Monday when I return, I can post some tiny85 code that uses an Adafruit LED display, a 3231rtc, and all the libraries to make it all work, if you are still interested.

I would be interested; the LED matrix is custom-built for the clock display (six digits, each 3 x 5, with the colons separate) since I couldn't find what I needed already built. The ATTiny85 board pictured is half the size of the Nano.

Ah cool.

My LED matrix is an I2C device that has 4 alpha numeric characters with 14 (+1 for the colon) onboard, and the RTC is a generic DS3231 breakout board. I'm running the Tiny85 at 1 MHz, with two 1.5 volt aaa alkaline cells. I've built a number of these in Altoids tins, some on breadboards, and some soldered. They are either a magic 8 ball or a clock, depending on the position of the switch (I also make an I Ching version.) The answer phrase or the time string scrolls across the 4 character display in a continuous loop, until the switch is changed, or the box closed. When the box is closed the Tiny85 sleeps. A light sensitive resistor determines if the box is open or closed.

Here is the code.

Here's a picture of the device

That looks great. How long does the batteries last?

I am still learning how to use the Nano, and am still unable to write code for it from scratch (the sketch I posted was 95% supplied by members of this forum; the other 5% involved adjusting some of the code to work with my LED matrix). So tackling the changes needed to make it work on the ATTiny85 is way out of my reach.

What I would like to do, if you are willing to help, is to modify the sketch I posted to run as a countdown clock instead of a timekeeping clock. I wanted to combine both functions in the same script, but that would mean additional hardware would be needed, and it would be easier to have separate clocks, as I have already built three of them.

Here are a couple pictures of one of them;

DSCN0418.jpg

DSCN0419.jpg

Here is a clearer shot of the back of the clock.

DSCN0419.jpg

Your device looks VERY cool! (I want one.)

Use search for "countdown code" and my username. I've posted it here a couple times, but I don't have a link handy. The demo here is written for a Uno, but you can change the pins so it works on a tiny.

Oh, I forgot to answer the battery question. I don’t know how long the batteries last.

I made 3 similar devices (but without the rtc) last Spring, and gave two of them (soldered, not breadboarded) to my brother and sister-in-law. I still have the third, with a couple of Duracell batteries (which I am told are the worst kind.) The giveaways had Energizer lithium aaa cells. All three of these have been running, opened at least once daily, for three months now, with no sign of dimming. I started the device above about 3 weeks ago.

If it’s always closed, the typical mah of a aaa cell suggests they should last a few years.

What surprises me is how bright this display is at 3.0 volts!

ChrisTenone: Your device looks VERY cool! (I want one.)

Use search for "countdown code" and my username. I've posted it here a couple times, but I don't have a link handy. The demo here is written for a Uno, but you can change the pins so it works on a tiny.

If you are serious about wanting one of the clocks I built, I would be willing to do a trade. In exchange for modifying my existing code as posted in the first message so it could run as a countdown clock that could be set for any starting time between 48 hours and one minute using IR remote input, as well as start, pause resume and reset to zero. This is for novelty only, not for timing an event. I can add the key codes to the sketch for the remote I have. Hopefully the IR remote code could also be added to the copy of the sketch that is running on my three clocks, so I won't have to plug it into my computer to adjust the time when needed. That way, I will have one clock for normal time display, and one that can be used as a countdown clock. Let me know if you are interested.

Hey thanks! I don't do programs for others though. I'm not good at that 'meeting specifications' thing.

I do appreciate the offer, and you confidence in my skills!

Thanks for the reply. Although I have done a number of projects in the past that involved electronics of some kind, this is the first, and probably only, project I have attempted that involved a microprocessor. My skill set does not extend to programming; I never had a knack for it. Kind of like learning a second language. It is easiest when you are young; but when I was young, computers consisted of terminals that accessed a room-sized computer; you had to write a program to communicate with it. Which meant that only the students that were proficient in math and language skills were able to use it. Later, I did learn how to use a computer when they became available to the general public. That was in the '80s; I grew up in the second half of the '50s and '60s, so no computer access.

If you know of someone who might be able to help me complete this clock project, it would really be appreciated. I tried to do it myself, but failed since I don't really understand how to write the code from scratch, just how to make some small modifications to existing code. Which is the other problem I've had; finding existing code that can be easily adapted to add to the sketch I have, and how to integrate it so it will work properly.

jeredneus: ... If you know of someone who might be able to help me complete this clock project, it would really be appreciated. I tried to do it myself, but failed since I don't really understand how to write the code from scratch, just how to make some small modifications to existing code. Which is the other problem I've had; finding existing code that can be easily adapted to add to the sketch I have, and how to integrate it so it will work properly.

I believe there are many competent (and more skilled than I) folk here who could do this for you. Post your best description of what you want in the Gigs and Collaborations sub-forum. There, those wanting to do programming projects for you will be most likely to see it.

Thanks for the tip, Chris. I'll look into it