Arduino IDE with ATTiny45 (porting)

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
Alessandro

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

Great job:)

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 ...
TIME : OK
External Interrupt (only one 0) : OK
Interrupts : OK
Communication : NO ( no uart in Tiny45)
CAVEAT Emptor
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)

attiny45.name=Attiny45

#I think I can use Arduino as an ISP programmer

attiny45.upload.protocol=stk500v1
attiny45.upload.communication=serial
attiny45.upload.maximum_size=3000
attiny45.upload.speed=19200

#attiny45.bootloader.low_fuses=0xdf
#attiny45.bootloader.high_fuses=0xca
#attiny45.bootloader.path=attiny45
#attiny45.bootloader.file=ATmegaBOOT.hex
#attiny45.bootloader.unlock_bits=0x3F
#attiny45.bootloader.lock_bits=0x0F

attiny45.build.mcu=t45
attiny45.build.f_cpu=1000000L
attiny45.build.core=attiny45

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.

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
attiny45.build.mcu=attiny45
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
Breadboard header for ATTiny 25/45/85 - Electronics-Lab.com or ATtiny45 development board – AVR Projects By Dim

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

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.

to know which mcu are supported by avr-gcc and their names use
avr-gcc --target-help
in a terminal window (works in Mac OSX and probably in Linux)

@karonth
there is another error in your board.txt
attiny45.upload.maximum_size=3000
the processor has 4096 bytes of ram in this way you limit max program size to 3000.

Actually I'm using Arduino as ISP programmer with the attiny on a mini breadboard. I've successfully tested digital and analog read and write.

avrdude -p t45 -c avrisp -P /dev/ttyUSB0 -b 19200 -U lfuse:w:0xe2:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m // to set the fuses for internal 8 mhz oscillator

avrdude -pt45 -P/dev/ttyUSB0 -cavrisp -b19200 -U flash:w:/home/file.hex // to upload the hex file

This cheat sheet Microcontroller cheat sheet – tinkerlog has proved very useful for a quick reference of pin functions.

The error in the board definition is mainly due to my laziness, i wanted to try it quickly so i didn't check the reference...thanks for the heads up :slight_smile:

If I manage to print the circuit on a laser printer at uni I'm going to etch a couple of boards sunday.

Hi, I came across your port for the attiny45 and I must say... GREAT JOB!

I wanted to ask you if you got the eeprom memory routines working? I'm currently designing some little circuit which may need it

Hope you will get this...

DW

EDIT

I confirmed the standard eeprom routines dont work, gives me the following error:

In file included from C:\Users\Charles\Desktop\arduino-0019\libraries\EEPROM\EEPROM.cpp:24:
c:/users/charles/desktop/arduino-0019/hardware/tools/avr/lib/gcc/../../avr/include/avr/eeprom.h: In function 'uint8_t eeprom_read_byte(const uint8_t*)':
c:/users/charles/desktop/arduino-0019/hardware/tools/avr/lib/gcc/../../avr/include/avr/eeprom.h:199: error: cast from 'const uint8_t*' to 'uint8_t' loses precision

(this is from standard sketch eeprom_clear but other sample sketches give the same error)

Changing the 512 value from atmega168 to 256 for the attiny45 didnt work

Eprom use ? mmmh ooops i forgot about it . Let's look into it , will report back here as soon as possible.