Sunday, August 7, 2016

Tiny45 programming with the Arduino IDE

Right at the outset of my Arduino I2C experiments (details to follow), I discovered that my ambition to control three motors (two servos and one for each track) was barely doable with the Mega328-based devices...no big deal for the current thing, but I had a few tiny45's laying around and I got to wondering...

And YES, it is completely possible to use an Arduino to program a 'bare' AVR!  Here's a link to the basics:

Programming an ATtiny w/Arduino 1.6

One gotcha with these instructions...you have to make sure to load the ArduinoISP software onto the Arduino BEFORE you try to change the board/processor/programmer combo to send anything through the Arduino to the ATtiny chip.  You just load File/Examples/11. Arduino ISP and upload it; I am using an Uno, and after that...all works great.

And to make sure the PWM on pin 0 and 1 (pin 5 and 6 on the actual tiny45) worked as advertised...I wrote the following:

/*
LED Fader for tiny45
Change FADEPIN appropriately for PWM output...
pin 0 maps to pin 5 on tiny45
pin 1 maps to pin 6

*/

#define FADEPIN 1

unsigned char fcnt = 0;
char fpause = 7;
char updn = 1;

void setup() {
pinMode(FADEPIN, OUTPUT);
}

void loop() {
fcnt += updn;
analogWrite(FADEPIN, fcnt); // turn the LED on (HIGH is the voltage level)
delay(fpause); // wait for a second
if (fcnt > 254) updn = -1;
if (fcnt < 1) updn = 1;
}



Works as you would expect; I had to experiment a little with the 'fpause' to get the LED to fade from max to min and back in about 4-5 seconds.

I'd already followed the instructions to set my tiny45 to 8Mhz (you use the rather non-intuitive 'Burn Bootloader' tool once you have the right board, speed, and programmer selected), but this works perfectly well at the default 1Mhz a new ATtiny runs at.

Next up is to get I2C working on the tiny45, which IS supported on the hardware, but was NOT include in the board and pin descriptions I installed from the instructions above.  More when I know more....

No comments:

Post a Comment