The Arduino IDE is wonderfully easy to work with and is to be praised as highly as possible for opening up the world of embedded programming to a wider audience - even as a well-seasoned bit basher who relishes the difficult stuff, I love the simplicity of the Arduino IDE.

Of course, it is designed for the 328P, MEGA2560 and now SAM3XAE processors in the Uno, Mega and Due respectively. Note the absence of anything "tiny" in that list. It's easy to fix - some very clever folk have added the tiny variants to the IDE, all you need to do is download a new "boards.txt" file (and some other stuff) from https://github.com/damellis/attiny/archive/master.zip and put it in the right place.

Hmm...note the absence of anything "24" in that new list...add the following to the newly installed boards.txt file:

Now you need a hardware programmer - something to plug the chip into so that the IDE can talk to it. Those funky Arduino people have even made that easy too - connect your Uno / Mega / Due and load the "Arduino as ISP" sketch. Next get a breadboard and wire the '24 (or 44 or 84) as follows:

Some folk will tell you you need a 10uF capacitor between RESET and GND or various resistors here and there, but it works perfectly on my desk without either. Those 6 wires above are all you need.

Next select the appropriate board as the target, upload your sketch and off you go. It's really easy. Of course the 24 has severely restricted hardware compared with "proper" Arduinos, so don't expect a lot of the libraries to work (especially Serial!) but it's brilliant for bit-banging with more legs than either a 25/45/85 or a spider.

Hi BareMetal, I think this is the topic I was looking for. I would like to use my ArduinoDUE as a ATtiny programmer, but all tutorial I found are about ArduinoUNO or other previous boards. I have some questions and I hope you can help me out :

Should I use 3.3V Vcc instead of 5V?

May I use the same six wires connection as for ArduinoUNO?

Instead of using those 6 pins to implement SPI, may I use the already integrated SPI connector on DUE board?

pyrotuc

think this will work on an 85? i just picked up a couple of these at tayda ( http://www.taydaelectronics.com/ic-integrated-circuits/microcontrollers/attiny85-attiny85-20pu-8-bit-20mhz-microcontroller-ic.html ) I will try it on the morn. seems like these would be *perfect* for building a fleet of sensors with an extra kick, smart switches, automation/security features... 6 pins...hmm... 6 pins.. how to use them...

so glad there is already a known way to use these things, seems like at that price they open up all sorts of new possibilities.... muwahahahhaa

avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85^This says 'ATtiny85', but I made the hardware boards.txt changes above.

Are my pins right? What pins do I use on the ATTiny24A when it is programmed?Please Help.Here is my code:

/*Only send a new value to the Serial Port if the adjustedLightLevel value changes.*/ if(oldLightLevel==adjustedLightLevel){ //do nothing if the old value and the new value are the same. }else{ //Update the oldLightLevel value for the next round oldLightLevel=adjustedLightLevel; } if(adjustedLightLevel<setPoint) { analogWrite(8, 1200); // turn the LED on (HIGH is the voltage level) analogWrite(6, 1000); // turn the PIEZZO on (HIGH is the voltage level) delay(200); // wait for a x-milliseconds digitalWrite(LedOne, LOW); // turn the LED off by making the voltage LOW digitalWrite (piezzoPin, LOW); // turn the PIEZZO off by making the voltage LOW

delay(2000); // wait for a second } else{ digitalWrite(LedOne, LOW); // It is light again, turn the LED off. digitalWrite (piezzoPin, LOW);

avrdude is uploading to an 85. either your boards.txt is wrong or yoh selected wrong board. while you will get those errors and can ignore them, 85 code wont run on a 24 ...all the pin numbers will be wrong for a start. check boards.txt

aldo_oner

Maybe the modified code is incorrect?I placed the 'hardware' directory in my Arduino Sketchbook Location it looks like this: /Users/Me/Documents/Arduino/hardware/attinyInside 'attiny' is the 'variants' directory and the boards.txt file that I modified (pasted my modified code on the end of page).

good. we have lost the tiny85 confusion. next question is...do you have an external 20mhz crystal in your tiny24 circuit? if you dont, the fuse settings in boards.txt will set the mcu to expext an external crystal for its timing. if there is none, I honestly dont know wwhat will happen, but it wont be good. the -20 on th chip doesnt mean that what the chip rjns at, its the max that it CAN run at, but anythkng over 8mhz will require external clocking.

out of the box, they are set to 8mhz internal clock with clkdiv/8 ie an internal prescaler that divides the raw clock by 8 giving an actual speed of 1mhz. try it again with the 1mhz internal clock option. the ide takes the correct fuse settkngs and will set the mcu back to 1mhz...if you copied them correctly!

if it still doesnt work I will look at your code in detail, but it aint going to work set to 20mhz and no external clocking.

ps that 20mhz even with externak xtal is only possible with vcc at 5v. if u have 3.3v you wilonly get to 8 or 10...cant remember whic, you need to check the datasheet. anyway, 1mhz is plenty for anyone unless u are building a space shuttle, life support system or massive hadron collider. try everything at 1mhz till you get more of a handle on things or jntil you have circuit that needs some sort of respone in less than a millionth of a second.....none of mine does!

avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny24avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny24

I must be doing something wrong with how I am wiring the pins on the ATtiny24. The sketch is working fine on the UNO. It reads the ambient light with the Photoresistor... when it is set with a bright light and back to ambient it will blink an LED and sound a piezo when the Photoresistor is shined on again.

/*Only send a new value if the adjustedLightLevel value changes.*/ if(oldLightLevel==adjustedLightLevel){ //do nothing if the old value and the new value are the same. }else{ //Update the oldLightLevel value for the next round oldLightLevel=adjustedLightLevel; } if(adjustedLightLevel<setPoint) { analogWrite(2, 1200); // turn the LED on (HIGH is the voltage level) analogWrite(3, 1000); // turn the PIEZZO on (HIGH is the voltage level) delay(200); // wait for a x-milliseconds digitalWrite(LedOne, LOW); // turn the LED off by making the voltage LOW digitalWrite (piezzoPin, LOW); // turn the PIEZZO off by making the voltage LOW

delay(2000); // wait for a second } else{ digitalWrite(LedOne, LOW); // It is light again, turn the LED off. digitalWrite (piezzoPin, LOW);

petty sure your pin numbers are wrong. you need to check the datasheet. I dont have on right now as im on the train but will check tonight and reply. aalso not sure why you reserve an int for the pin number then use an absolute value in pinmode...the usual way is #define mypin 5 or whatever and then use mypin everywhere. this method saves space as it doesnt reserve memory for the int, its just a textual shorthand for the compiler..ie replace mypin with 5 before compiling.

The main problem you have though is your analogue writes. analogWrite uses PWM functionality on the pin. From the arduino docs:

"On most Arduino boards (those with the ATmega168 or ATmega328), this function works on pins 3, 5, 6, 9, 10, and 11. On the Arduino Mega, it works on pins 2 - 13 and 44 - 46. Older Arduino boards with an ATmega8 only support analogWrite() on pins 9, 10, and 11. "

Those datasheets will show which pins have PWM functionality. On the tiny24 (see above) its chip pins 5,6,7,8 ie digital pins 5,6,7,8 (altho confusingly not in the same order!)

So, if you have to pulse PIEZO and LED, they need to be on one of those pins. On the UNO through what a poster on here calls "dumb luck" 10 and 11 support PWM so your sketch works (though you were lucky that calling analogRead before setting the pinmode also happened to work...the chip boots up with pins as inputs!)

so:#define PIEZO 5#define LED 6 should sort that. Next we go back to the doc for analogWrite:

"Parameters

pin: the pin to write to.

value: the duty cycle: between 0 (always off) and 255 (always on)."

you say: analogWrite(2, 1200); // turn the LED on (HIGH is the voltage level) analogWrite(3, 1000); // turn the PIEZZO on (HIGH is the voltage level)

I'm not sure why you chose those values, and I dont want to go into 2s-complements maths on 8-bit values, but that code just aint going to do what you think it does. E.g. 1200 is 0x4B0 since you are stuffing into 8 bits, you lose the 4, giving 0xB0 which is 176 if its treated as unsigned, or -80 if its a signed value. Neither of them are close to what you thought you meant!

176/255 = 69% full brightnes (or squeak volume) so (luckily) your dodgy code will actually cause what LOOKS like a flash and a squeak. If all you want to do is turn the LED on or off, use digitalWrite (also consider the tone library for squeaking the buzzer)

To make your code clean, you need to map your value to 0-255 and also say:analogWrite(PIEZO....digitalWrite(LED...for portability and ease of modification / rewiring...all you do if you move a wire is change the #define and the rest of the code "just works" without search and replace of all "2," for e.g. "11," which can change of a lot of wrong stuff accidentally if you arent careful!

A final note, UPPERCASE is usually used for such constants (just a style thing) and analog pins have special names in the pins_arduin.h file, e.g. analog pin 0 is A0.

Using A0 instead of 0 makes your code portable, ie on a UNO, A0 will be mapped to the correct pin for you, and its one less thing to change. if the framework had similar definitions for e.g. PWM pins such as PWM1, PWM2 and digital pins like DIGITAL1, DIGITAL2 etc, we wouldn't be having this conversation at all, as it just would have worked on any variant if you had said:

#define PIEZO PWM1#define LED DIGITAL1#define PHOTO A0

.and put the wires in the right holes (aprt from the 1200 vs 255 discussion of course!)