Go Down

Topic: ATTiny85 and RTC? Please Help. Code Errors? :) (Read 6950 times) previous topic - next topic


Feb 18, 2012, 01:57 am Last Edit: Feb 18, 2012, 02:18 am by Startgroup Reason: 1
Hello, I am still a newbie at this and I have dreamed of a project, ordered the parts, waited for ever, learned to code it and I am 80% done.

I am trying to make an art project that is a watch. It has one led, and reads the time off to you by blinking the time.

ex: 2 blinks, pause, 4 blinks, pause 4 blinks (2:45)

I bought a RTC real time clock module from sparkfun. I got it working with an arduino, but it is too big to strap to my wrist. I ordered a couple of ATTiny85 chips and I would like to shrink the project onto one of those. I finally got the blink sketch on the attiny, but I cannot get the RTC code onto it. I get a ton of errors like:

/Applications/Arduino.app/Contents/Resources/Java/libraries/Wire/utility/twi.c: In function 'twi_init':
/Applications/Arduino.app/Contents/Resources/Java/libraries/Wire/utility/twi.c:75: error: 'PORTD' undeclared (first use in this function)
/Applications/Arduino.app/Contents/Resources/Java/libraries/Wire/utility/twi.c:75: error: (Each undeclared identifier is reported only once
/Applications/Arduino.app/Contents/Resources/Java/libraries/Wire/utility/twi.c:75: error: for each function it appears in.)
/Applications/Arduino.app/Contents/Resources/Java/libraries/Wire/utility/twi.c:80: error: 'TWSR' undeclared (first use in this function)
/Applications/Arduino.app/Contents/Resources/Java/libraries/Wire/utility/twi.c:80: error: 'TWPS0' undeclared (first use in this function)


I need to read the hours, and minutes off of the attiny.

I am only using a few pins.  1 pin is led, 2 pins are clock, 1 pin is button.

Thank you so much. I  have been working on this since yesterday for so many hours and I am getting nowhere.


ATtiny has only PORTB
Using Port Manipulation?
You have to use the ATtiny's pin numbers, you can't just re-use (copy&paste) those from your Duemilanove (et al.)
The IC's pin_5 = D0, pin_6 = D1, pin_7 = D2, pin_2 = D3, and pin_4 =D4
"Who is like unto the beast? who is able to make war with him?"
When all else fails, check your wiring!


Hi, thanks for your reply, my problem isn't identifying the pins. It is the real time click liberty.

I just need a way to get the time from the RTC: DS1307.

There is a lib called TinyWireM that has an example sketch that talks to a RTC via its port address? But I dont get it. I tried using it and I dont know if it is working, all I know is when I try to assign one of my variables the value of hours and another variable the value of minutes I dont seem to be getting a response.



Does it compile with TinyWireM?

Have you configured it for the right speed as per the instructions?
What about the pullups?

I've just bought the same RTC module and am waiting for the post man to bring it so it will be interesting to see if I can get it to work with the attiny85.


I am using pullups.

However what are you refering to about speed? Did I miss something?

I am running at 1 mhz and I have tested 8mhz with same results.


I am using pullups.

However what are you refering to about speed? Did I miss something?

I am running at 1 mhz and I have tested 8mhz with same results.

It was one of the bolded items on the tinywireM entry

tinywireM is something I will be looking at using in the future but haven't played with it yet.


Oh yes, sorry, that I did. No dice. It doesn't help that I dont understand how to hook up the LCD or serial monitor to this setup to get the error code.

All is compiling now. However:

After tweaking some code and adding some leds, I am convinced the attiny85 isn't even communicating with my RTC.


In my only attiny project to date I debugged it by flashing an LED at certain code points.

If I had some pins free though I would have used an LCD via a shift register.


I just recently discovered that you can use Serial.print() etc. when you are debugging Att85.


It is more informative than a blinking LED  :D



Sadly for me, every pin was in use so I couldn't spare one. The LED was part of the project circuit.


Has anyone successfully interfaced an RTC and an ATTiny85? If so, can you post a link to their project?

Thank you so much. I cant believe I am stuck on this part.


You already have an example of TinyWireM with an RTC.
See the "examples" for that lib - "Tiny85_Temp_LCD_RTC".
"Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom."
~ Clifford Stoll


The mailman delivered my parts and I have this working.

I encountered issues with the LCD libraries and examples because they are LCD product specific  :smiley-roll:

I had to rework them for more generic use and to include the reset fix but I haven't completed that task.

The LCD i'm using is a DFRobot I2C LCD and they are the best way to determine if your I2C is working on the attiny as they give a definite visual clue.

The code for the clock module is identical to code used for the Arduino uno. I just switched the wire and tinywireM

I originally sourced it from http://tronixstuff.wordpress.com/

The resistors  are 39k (by accident) and 4.7k but seemed to work fine.

main mod for the LCD module (in the library header):
Code: [Select]

#define LCD_TYPE_DFROBOT 1 // define your hardware here
//#define LCD_TYPE_GPIO 2

#if (LCD_TYPE_GPIO == 2)
//(PCA8574A A0-A2 @5V) typ. A0-A3 Gnd 0x20 / 0x38 for A
// flags for backlight control
#define LCD_BACKLIGHT 0x00
#define LCD_NOBACKLIGHT 0x80
#define En B00010000  // Enable bit
#define Rw B00100000  // Read/Write bit
#define Rs B01000000  // Register select bit

#define I2C_ADDR 0x3F


// flags for backlight control
#define LCD_BACKLIGHT 0x08
#define LCD_NOBACKLIGHT 0x00

#define En B00000100  // Enable bit
#define Rw B00000010  // Read/Write bit
#define Rs B00000001  // Register select bit

#define I2C_ADDR 0x27


Code and LCD library attached. It's easy to comment out the LCD code as it's not intermingled.

I found that the time was not set initially and that the module was disabled and I had to turn it on.

Using the setDateDs1307 achieved that.


More info...

Apart from the unit not being enabled initially the only issues I had were getting the wires around the right way and remembering the pullups.

I am running a true 8mhz with correct fuses and boards info. I say that because it's very easy to think you have it configured correctly when it's not. One day someone will write an attiny diagnostic sketch to read out the fuse and prescaler settings.

My attiny is programmed via arduinoisp from the http://code.google.com/p/arduino-tiny/downloads/list

I found the high low tech configuration was a bit troublesome to get the fuses set cleanly and had to spend a lot of time tweaking it to get it to work. I recommend not using it if you are starting out or stick to 1mHz.

Go Up