Programmed an attiny25 with Arduino IDE

I know there are similar threads out there, but I didn't want to hijack one of those. I just wanted to report on something I had tried that worked.

Using the instructions from this web site: http://hlt.media.mit.edu/wiki/pmwiki.php?n=Main.ArduinoATtiny4585

and the following addition to the boards.txt file in my sketchbook/hardware/attiny45_85 directory:

attiny25.name=ATtiny25
attiny25.upload.using=arduino:arduinoisp
attiny25.upload.maximum_size=2048
attiny25.build.mcu=attiny25
attiny25.build.f_cpu=1000000L
attiny25.build.core=attiny45_85

I was able to write the Arduino Blink sketch to an ATtiny25 and it worked first time!

I used the following command line to set the LFUSE so that the t25 ran at 8mhz:

avrdude -p t25 -P /dev/ttyUSB0 -c avrisp -b 19200 -Ulfuse:w:0xe2:m

The Blink sketch reported that it was writing 632 bytes. That's a lot more than if you coded it using avr-gcc directly, but still leaves a lot of space for additional code.

All this took about an hour. I think it was time well spent and hopefully someone else can use it too.

Thanks for the post. Do you mind my asking ... Why are you using the '25 instead of the '45 or '85?

I happened to have purchased several of the 25's a few years ago and never got around to using them, so I thought I would see if this worked. Now I can utilize my existing stock of these using the same IDE.

Thanks, Thanks, Thanks, Thanks, Thanks, Thanks, Thanks,
and did I say thanks?

I've been waiting for something like this to come a long time. Now I just need to get my hands on some ATT25/45/85s.

Jan

EDIT: Question:

Shouldn't it be possible to program almost every ATmega/tiny with the following:

attiny25.name=ATtiny25
attiny25.upload.using=arduino:arduinoisp
attiny25.upload.maximum_size=2048
attiny25.build.mcu=attiny25
attiny25.build.f_cpu=1000000L
attiny25.build.core=attiny45_85

if you excange "ATtiny25" with the name of the chip, "2048" with the maximum size of the the memory, "attiny25" with the name of the chip but without caps and "attiny45_85" with the name of the folder there you have saved "WProgram.h" etc? If yes, what do you need to change in that folder (attiny45_85 in this case)? I've read about that you need to change the both files "WProgram" and "pins_arduino". Is that right?

if you excange "ATtiny25" with the name of the chip, "2048" with the maximum size of the the memory, "attiny25" with the name of the chip but without caps and "attiny45_85" with the name of the folder there you have saved "WProgram.h" etc?

Yes. It can be helpful to include fuse settings as well.

If yes, what do you need to change in that folder (attiny45_85 in this case)?

The minimum to change is "pins_arduino.c". Sometimes the timers are different which requires changes to other files. Sometimes the analog input is different requiring changes to other files.

I've read about that you need to change the both files "WProgram" and "pins_arduino". Is that right?

I can't remember having change anything in "WProgram.h". But different processor families require a different "pins_arduino.c".

The current Arduino core is a good example and includes support for at least one tiny processor.

I just realized that my boards.txt file specified the CPU at 1mHz instead of 8.

attiny25.build.f_cpu=1000000L

That could explain why I am having so much trouble trying to tune the OSCCAL value. :wink:
If you are going to set the low fuse bit for 8mHz the correct value for this would be:

attiny25.build.f_cpu=8000000L

Yikes!

That could explain why I am having so much trouble trying to tune the OSCCAL value.

How are you tuning? AVR053?

So the f_cpu is the speed in Hz?

good to know

I was tuning it manually with a sketch that sets OSCCAL then turns an i/o port on and off every second and measuring that with an oscilloscope. Then modify the value being written to OSCCAL, redownload the sketch, remeasure, repeat. Kind of the brute force way to go about it. I'll have to look into AVR053.

Yes, f_cpu is the speed in Hz. If you look in the Arduino code (don't recall which file) it is actually using f_cpu in some calculations for the timing routines.

Have you seen this...
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1287558192/0#0

I had not seen that specific post, but had thought about timing serial data in order to calibrate. I will look that post over in detail.

I have been playing around a bit more. I set the clock to 8mHz in the boards.txt file as shown above (and set the lfuse appropriately), and was able to run the program below with the factory calibration. This program outputs the alphabet to a serial LCD at 9600 baud. I haven't tried a serial receive, but don't see why it wouldn't work.

#include <SoftwareSerial.h>

#define RXPIN 255
#define TXPIN 0

// set up a new serial port
SoftwareSerial mySerial =  SoftwareSerial(RXPIN, TXPIN);

void setup()
{
  pinMode(TXPIN, OUTPUT);
  mySerial.begin(9600);
  
  // Let the LCD get booted up
  delay(5000);
  // Home the cursor
  mySerial.print("?f");
}

void loop()
{
  for( char c='A'; c<'Z'; c++)
  {
    mySerial.print(c);
  }
  delay(5000);
}

In my testing, 9600 baud has worked consistently with "uncalibrated" processors. But I've only tested about a dozen. :wink:

Oh, and SoftwareSerial is a bit flaky. I think the bit timing is not quite right. I had all sorts of problems at baud rates above 19200. Even on "calibrated" processors. NewSoftSerial (which won't compile without changes on an 25 / 45 / 85 processor) works much better.

I wish the Arduino team would really make the ATTiny natively compatible. It's a great chip for small home-built Arduinos that don't need a kazillion I/O pins and need to save space.

They probably don't have interest because an ATMega2560 SMD chip is practically smaller than an DIP ATTiny85 so what would be the point I guess.

I wish the Arduino team would really make the ATTiny natively compatible

Bootloader? Sketches can be built with the Arduino IDE? Servo works with ATtinyXX? What do you feel is missing / not working?

Oh, and SoftwareSerial is a bit flaky. I think the bit timing is not quite right. I had all sorts of problems at baud rates above 19200. Even on "calibrated" processors. NewSoftSerial (which won't compile without changes on an 25 / 45 / 85 processor) works much better.

That is exactly why I used SoftwareSerial, it didn't need any changes to run. I've looked at the NewSoftSerial code and IMO it would need extensive changes as it makes much heavier use of interrupts. It's a great library for a regular Arduino, but way beyond my abilities to modify for a Tiny25. I don't need anything beyond 9600 anyway, so I'll wait for someone else to port NewSoftSerial.

I also meant to mention that the program I used to write to an LCD used a little over 1100 bytes, so there is still quite a bit of room for other code even on the Tiny25.

I wanted to report that I also have had success programming a Tiny25 with the code from this site Google Code Archive - Long-term storage for Google Code Project Hosting.

For this one I also had to modify the boards.txt file to include entries for the Tiny25 which I created by copying the Tiny45 section and changing the relevant bits to Tiny25.

I was able to download the above LCD write sketch and also did tests of analogRead, analogWrite, tone, noTone, etc.

It's nice to have a few options. :slight_smile:

I wanted to report that I also have had success programming a Tiny25 with the code from this site Google Code Archive - Long-term storage for Google Code Project Hosting.

Excellent!

That is exactly why I used SoftwareSerial, it didn't need any changes to run

The latest version of the Arduino Tiny core includes "Tiny Debug Serial". If you only transmit, it should make a very nice replacement for SoftwareSerial. I beleive it's smaller and the timing should be dead-on. Some details are here...
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1285218245/25#25

For this one I also had to modify the boards.txt file to include entries for the Tiny25 which I created by copying the Tiny45 section and changing the relevant bits to Tiny25.

Please post your changes. I'll add them to the Arduino Tiny core.

I was able to download the above LCD write sketch and also did tests of analogRead, analogWrite, tone, noTone, etc.

Any problems?

This is the addition I made to the boards.txt file.

###########################################################################
attiny25at8.name=ATtiny25 @ 8 MHz

# The following DO work (pick one)...
attiny25at8.upload.using=arduino:arduinoisp

attiny25at8.upload.maximum_size=2048
#attiny25at8.upload.speed=19200

# Default clock (slowly rising power; long delay to clock; 8 MHz internal)
# Int. RC Osc. 8 MHz; Start-up time PWRDWN/RESET: 6 CK/14 CK + 64 ms; [CKSEL=0010 SUT=10]; default value
# Brown-out detection disabled; [BODLEVEL=111]
# Preserve EEPROM memory through the Chip Erase cycle; [EESAVE=0]

attiny25at8.bootloader.low_fuses=0xE2
attiny25at8.bootloader.high_fuses=0xD7
attiny25at8.bootloader.extended_fuses=0xFF
attiny25at8.bootloader.path=empty
attiny25at8.bootloader.file=empty45at8.hex

attiny25at8.bootloader.unlock_bits=0xFF
attiny25at8.bootloader.lock_bits=0xFF

attiny25at8.build.mcu=attiny25
attiny25at8.build.f_cpu=8000000L
attiny25at8.build.core=tiny
 
###########################################################################

It would be easy enough to also include make a 1mHz section.

I had no issues with any of the library functions that I listed above.

I will check out the Tiny Debug Serial. Sounds like a great addition.

Thanks. The next update will include definitions for the ATtiny25 @ 8 MHz and the ATtiny25 @ 1 MHz.

They probably don't have interest because an ATMega2560 SMD chip is practically smaller than an DIP ATTiny85 so what would be the point I guess.

price maybe...