Pages: [1]   Go Down
Author Topic: ATTiny85 and RTC? Please Help. Code Errors? :)  (Read 3021 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)

Anyideas?

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.
« Last Edit: February 17, 2012, 08:18:54 pm by Startgroup » Logged

Offline Offline
Faraday Member
**
Karma: 66
Posts: 2574
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

PORTD
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
Logged

"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

smiley-sad
Logged

Australia
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Australia
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
http://arduino.cc/playground/Code/USIi2c

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

Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Australia
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Denmark
Offline Offline
Edison Member
*
Karma: 36
Posts: 1084
Happy Hobbyist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

http://arduino.cc/forum/index.php/topic,91125.msg684116.html#msg684116

It is more informative than a blinking LED  smiley-grin

Logged

Australia
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 smiley-lol

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

Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Denver
Offline Offline
God Member
*****
Karma: 20
Posts: 779
Inactive - PM
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You already have an example of TinyWireM with an RTC.
See the "examples" for that lib - "Tiny85_Temp_LCD_RTC".
John
Logged

"Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom."
~ Clifford Stoll

Australia
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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

#endif

#if (LCD_TYPE_DFROBOT == 1)
//DFROBOT
// 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


#endif

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.



* attiny_clock1.JPG (59.48 KB, 604x480 - viewed 53 times.)

* attiny_clock2.JPG (51.13 KB, 654x491 - viewed 46 times.)

* attiny_clock3.JPG (68.48 KB, 750x509 - viewed 72 times.)
* attiny_I2C_RTC.zip (7.38 KB - downloaded 32 times.)
Logged

Australia
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: