Go Down

Topic: Arduino IDE with ATTiny45 (porting) (Read 11481 times) previous topic - next topic


I'm in the process of  creating a core for the ATTiny45, just out of curiosity, for a project i'm doing now and because I just want to do it to prove it's possible.
Basic functionality , reading digital pin writing digital pin , and delay are ok , what i'm stuck on is PWM .
As I understand it , analogWrite is implemented in wiringAnalog.c and Wiring.c, but I can't make it work essentially I can't figure how wiring implements PWM on timer0 . Wath i need is a clear explanation on how the chain of initialization instrcts are laid out ...
Thx in in advance


An update on porting a an attiny45 core to arduino ide.
digitalWrite OK  
analogWrite OK -- 2 pins as tiny45 has only 2 timers
analogRead OK - all pins to be tested
delay OK
digitalRead *** Not Working

still working on it



On the ATMEGAxx8, each timer can control two PWM outputs, via two separate "output compare" units.
It looks like this is true on the tiny45 as well, so in theory it should support 4 digitaWrite() outputs.  However OC0B and OC1A end up sharing the same pin, so you're probably limited to 3 actual pins...


westfw : yeah that's right , but i decided for only 2 due to constraints in pin availability. anyway anyone can modify the core files.
Report on status of porting :
digitalRead is now working ok !
    weird thing , to make it work I had to change pgm_read_word with pgm_read_byte in pins_arduino.h , still looking into it.
next ...
Interrupts !


I'd be really interested in details of what changes you made and how the whole thing fits together.


Status Report:
Reached Final Candidate 1.0
Every Arduino instruction is working, besides those that don't have hardware support like TWI...
function ( as in Ardu ide reference)
Digital I/O : OK
Analog I/O : OK
Advanced I/O : to be tested , should work anyway ... never say ...
External Interrupt (only one 0) : OK
Interrupts : OK
Communication :  NO ( no uart in Tiny45)
Programming the chip from ARDU IDE not working , use an external programmer .
Pin mapping is a mess as ATTiny as only 6 pins with multiple function so fisical pin 7 is digital pin 2 , analog input pin 1 and INT 0
HOW TO do it
change all the relevant CORE files to adapt for Tiny45

Stay Tuned


I made a small page about the mods to cores files i used.
With all respect due and paid to everyone involved you can find it here


Thanks, that's highly interesting! I have to try it out.
It seems that hardware PWM is not available on the attiny45, but is the I2C bus working? (I am interested using it as slave.)


It seems that hardware PWM is not available on the attiny45, but is the I2C bus working? (I am interested using it as slave.)

You got it reversed , it' TWI that not available in h/w , you want it ? you gotta emulate.
H/W pwm IS available , TWO of them in my implementation.


I have played with tinys and I have ported a C library for USI TWI to Arduino. I didn't test it yet, as I can't program the tiny861 from Arduino and I don't use the AVR Studio. I posted the lib in this thread: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1254371365, but since then I made some corrections and tried to add that user function, but something is missing and I can't figure out what. Also, I got the pin change interrupts working if you're interested but I also need the analog pins to work. I am working on a VU-meter based on tiny861 to act as a mouth for my robot but also use the twi to trigger other cool effects.


I've tried to use your core files with arduino ide 0018 but I get a compilation error

/home/user/Scrivania/arduino-0018/hardware/arduino/cores/attiny45/wiring_analog.c:103: error: 'OCR1A' undeclared (first use in this function)

The board definition is as follows (i've invented one since i couldn't find it in your site)


#I think I can use Arduino as an ISP programmer




The program i'm compiling is a simple blink

int ledPin =  1;    // LED connected to digital pin 1, I don't know the pin layout

// The setup() method runs once, when the sketch starts

void setup()   {                
 // initialize the digital pin as an output:
 pinMode(ledPin, OUTPUT);    

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()                    

 digitalWrite(ledPin, HIGH);   // set the LED on
 delay(1000);                  // wait for a second
 digitalWrite(ledPin, LOW);    // set the LED off
 delay(1000);                  // wait for a second

Do you have any advice, is there something i'm doing wrong?
Thank you in advance, best regards.


Jun 08, 2010, 05:13 pm Last Edit: Jun 08, 2010, 06:21 pm by saposoft Reason: 1
did you get the new version of the files ? they are compatible with Arduino 0018.
Your board.txt is as good as mine as long you use a meaningful name for the board definition and .... keep this lines

attiny45.build.mcu=attiny45 // for (from) the compiler defs i've read them somewhere can't remember now
attiny45.build.f_cpu=8000000L // max speed change to suit your fuses
attiny45.build.core=attiny45  // this is the folder name of the cores files

The pin definitions are in pins_arduino.c in the core folder
I'm using an external programmer to program the board via isp, the one from OBDEV .
Feel free to ask , the descriptions are pretty sketchy I know ... what's not here and in my files is on the arduino site.


Yes I got the new version of the files, the problem was the mcu parameter
I used the t45 name from the avrdude definition and it doesn't work that way.

There's also something strange that depends on my distribution i think (I'm using ubuntu 10.04); when I compile the blink example the .hex file doesn't end up in the sketchbook but in a temporary folder /tmp/build4541789516165904686.tmp/
I guess all the numbers in the folder name depend on a hashing function but the build part is always present so it's fairly easy to get to the compiled program.

I'm going to build a test board, maybe something with an ICSP header like
http://www.electronics-lab.com/projects/mcu/012/index.html or http://dselec.wordpress.com/attiny45-board/

I think pin mapping should be documented a bit more, since it's not very clear. I know there are multiple functions on a single pin, but since they must be mutually exlusive that shouldn't be too much of a problem.

I'll try this out and post when i make some progress.
Thank you for your support, keep up the good work :)


Yeah the error was the mcu parameter , you can find a list of the supported mcu somewhere inside avr gcc documentation or include.
For the strange location and name of your hex file , it's a "feature" of ardu 0018.
The Attiny45 implementation relay heavily on the assumption that one has already hacked and digged a real Arduino board and the Arduino site.
The best I can do for the pin mapping is in the pins_arduino.c in the core folder, the function are multiple per pin depends on the function you use to refer to the pin;
I.E. analogWrite (0,231) // output a pwn signal to real pin 5
digitalRead(5) // read a digital value from real pin 1
analogRead(5) // read an analog value from real pin 1
and so on ... like in a real arduino .
May I suggest the board in my site ? it doesn't have a quartz so you can use two more pins and has a standard isp header with 10 pins.
Have fun and keep asking so I can improve the documentation.

Go Up