Programming ATtiny chips

Hello Chris @chris101,
Good work, you definitely won’t be disappointing. From what we’ve talked about so far, the 'Tiny 24/44/84 is probably going to be a mainstay for you. Do some experimenting yourself and see what you think, after you get all setup, if you can discern any difference between the internal clocks, resonators or crystals. Have used resonators to great success in many 328 based projects, but I almost always use the internals on the ATTiny chips. Don’t worry about hooking anything up to get started, just burn the fuse bits to 8 MHz internal and program away. Only just recently decided to use a proper crystal and capacitors on a 328 based synth/sequencer I’m building. Pretty fun stuff I say.
P.S. Any luck with shiftOut() and some 74HC595’s?

Hey Ryan ( @StuckInSynth )

I dug around and was able to get ahold of three shift registers, none of which are 595s. I’ve got 164, 165 and 299 chips. Of those, and according to the descriptions on this page, the 299 seems most similar to the 595. However since I found this instructable, I am gonna start with the 164 - which they describe in the linked article as the “the most basic shift registers out there”. I like basic, and have long been a serial-phobe, so this exercise may just cure me.

If I start with the 8 pin device, I will NEED to do something to … branch out.

I’m also working out the analog side of littleBits over in my op-amp thread. My goal of course, is to be able to make a new bit to submit to the bitlab: the co2 sensor. While the sensor I am using is a simple system like littleBits, there are other parameters I would like to be able to control with the microprocessor, such as air flow, temperature, and pressure (although some of those may be below my threshold of precision.) Air flow for sure though. So controlling/reading several, mostly unrelated, inputs is essential to my application (the tiny85 is practically limited to 5 io pins right?) This means I will need to use a shift register, or use the tiny84 with more lines, or just staying with the ATmega328p that I’m finally getting comfortable with (as an arduino board. That’s why I bought all 3, so I can fall back on my old, parallel ways as needed.)

School will be over in a week and a half, so I will be able to concentrate on this project full time for a few weeks. Until then, I’ll be baby-stepping!

1 Like

WHOOT!!

My ATtiny chips and Pocket Programmer came in the mail yesterday. I battled with wiring it all together correctly (despite the error in the hookup guide about where the marking grove on the ISP socket is located (it’s pointing to pin 3, not one as stated. Demonstrated how hearty these chips are though …)

Anyway, I modified “blink.ino” to use pin 3 instead of 13, and here, the result speaks for itself:

I have a question for @StuckInSynth:
When I set the fuse to 8MHz the sketch runs very slow - about 5 or 10 seconds between blinks. When I set it to 1 MHz, it runs as expected. I suspect this is caused by an anomaly of the delay() function. Any insight?

Shout out to @StuckInSynth @JackANDJude, @Philip_Verbeek, @matthiasmwolf, @syedBits, @alexpikkert

Thanks to you all for your encouragement and help with this. I love this forum! I am ready to try to use this chip in my bitlab project with the people counter.

4 Likes

Looking good! That feeling is…indescribable :innocent:

You also have to burn the bootloader with 8MHz if you set the fuse to 8MHz. Or did you already do that?

Good luck with further developments and keep us up to date;)

1 Like

Hi @chris101,
Great you were able to get off on a good start! Like @Philip_Verbeek stated, and as described in the SparkFun Pocket Programmer page ( https://learn.sparkfun.com/tutorials/pocket-avr-programmer-hookup-guide?_ga=1.196733673.438987170.1428722892 ) under “Burning a Bootloader” after you select AT85, 8mHz Internal on your boards list, then select burn bootloader under same tools menu in Arduino IDE (I’m assuming that’s what you started with, as apposed to avrdude, ect.) If this is already what you are doing, one other essential I’ve found for ATTiny’s, is to always define all pins with pinMode in your setup. I’m sure there are a few other minor details that I am forgetting, but as I come across more I will post. Keep any other questions coming.

1 Like

Hi Philip! @Philip_Verbeek

Making something work the first time is indeed a great feeling - the blink sketch has never made me so happy before! :wink:

So from reading your (and Ryan’s) comment, it is necessary to load the bootloader in order to use the internal 8 MHz clock? I have done the bootloader procedure, but only to an arduino clone board (OSEPP uno R3). The 8K space inside the tiny85 is pretty tight, and I was hoping to be able to leave the bootloader out, since my (unrefined) co2 sensor code now sits at 6.4K.

Because of this I have been running the tiny85 at 1 megahertz. That seems fast enough for this application, but I know, as it gets more complex, I’ll want more.

Thanks as always for ‘following’ my progress on this project Ryan (@StuckInSynth),

Thank you for the hint to define all pins - I had not run across this ion any of my web-reading. I’ll now include that in my sketches.

The first thing I did with my pocket Programmer was to install the blink sketch on an Arduino (clone) board, so I could familiarize myself with how it worked before interfacing to a chip I’d no experience with. Smooth as butter, then I used the programmer to replace the bootloader back on the board. But I’m still not clear on the need for the bootloader on the tiny chips. When I read this from the Pocket Programmer tutorial:

If you’ve uploaded a sketch via the programmer, you’ve also wiped off the bootloader. 

I took it to mean that I can’t have a bootloader AND a programmer uploaded sketch simultaneously. What you and @Philip_Verbeek have suggested is that I will need to install the bootloader to run faster than 1 MHz - am I understanding that correctly? If so, then how can I install a bootloader AND upload a sketch?

ps, yes, I am using thre Arduino IDE for programming. Until I run into a limitation, I’ll hold off on learning to run AVRDUDE from the terminal.

Good Evening @chris101,
Basically in the Arduino IDE, when you burn a bootloader on a 'Tiny chip, all your really doing is setting those fuse bits to what you want, simple internal 8 mHz, external 16 mHz for a '328, ect. There is no room for a bootloader on these chips per 'Se, hence the upload via programming requirement. A bootloader facilitates a different type of programming, like on an Uno. Good note of advice, be careful not to set any chips to an external source unless you have the crystal + capacitors, or at least a resonator. You will not be able communicate until parts are added, kind of a “Brick” type of deal. The reason your program ran slower when you tried to blink! @ 8 mHz is because the sketch was complied for 8 mHz but chip still running at 1 mHz. If you look thru my sketch for the numberplusBit in the “It’s New To You” section this started in, you can get a little better idea of what is required, but quirky none the less.

2 Likes

Hi @chris101,

I have checked it and the 8 MHz AND 1 MHz bootloader for ATTiny85 only have a SAME Binary sketch size of 326 bytes (of a 8,192 byte maximum).

I would always go with 8 MHz and would suggest to just try to burn this bootloader. You can always go back if you want to for some reason.

To do so follow these staps.

  1. Set board to ATTiny85 @ 8 MHz etc. (You dont need a sketch or whatsoever, just the Arduino IDE by itself)
  2. Burn bootloader. This should only take a few seconds.
  3. Now your ATTiny85 is set to run on 8 MHz.
  4. Now upload your sketch to the ATiny85 with the same board (8 MHz etc).

You can also burn the 16 MHz (internal PLL) bootloader. I have tested it and it also works. Up to you.

Let us know if this works out for you:)

1 Like

Hi @chris101,
Very interesting, these tiny arduinos…
Good to see you are in control…
I wonder if you have planned to use Attiny chips combined with Littlebits in a project? I googled a few things and saw they can be used for almost anything…
Maybe they fit on a HDK development pcb. :slight_smile:
Let me know if you have design ideas for the future…

Philip @Philip_Verbeek , Ryan @StuckInSynth - you guys rock!

(And having replied since I wrote the rest of this post, @alexpikkert too.)

I think I am there - I have successfully programmed both the tiny85 and tiny84 chips, at 1MHz, and at 8MHz with the later after burning a ‘bootloader’ onto the chips. Ryan, your explanation of what this actually does made perfect sense - that it’s not really a bootloader, but rather just the mechanism that sets the fuse to the desired clock speed. I have a 16MHz resonator - looks like a 3 legged disc cap, but sez 16.00MX on it. For my current application, 8MHz is plenty of cycles. Should I need more speed, I’ll give it a go, but that will “waste” two of my already scarce pins!

Philip, I googled “internal pll” (adding “arduino” to the search field got me to the useful stuff) so that also remains an option, but from my reading, it adds to the complexity. That also seems like something worth experimenting with, but here too, I will likely save that for a future project. (!! 65MHz in liquid nitrogen sounds … wait for it … cool! )

I believe I am ready to incorporate a tiny85 into my “people counter” bit (link to project update.) I cobbled the hardware together1, even though I have not gotten my hands on the proper op-amp. It’s working ok - I can see the %CO2, but I still need to work on the air sampling, and of course, the software that counts people. Doing (somewhat) sophisticated data crunching in 8K is challenging. I feel like I’m back in 1982! :older_man:

4 Likes

Thanks for the salutations @chris101, might not be that worthy myself. But anyway, sounds like you got your start! Glad to hear my explanation was appropriate. Really, in my experience so far, even with ATMega based synths, I don’t think I’ve encountered a particular instance where an 8 mHz internal, a 16 mHz resonator or a true crystal setup really made the difference. Even quite complex C++ code containing math neither of us want to actually have to do is taken care of at 8 mHz in very rapid fashion. Look at a map() or constrain() function in the Reference section of Arduino.cc and think about what your asking an analogRead() to do in real time, probably in a millisecond or two. As far as sketch size, start to get used to arrays, char arrays, strings, objects, ect. These basically allow you to store a “map” of info that may be used often throughout a sketch. Writing even small functions of your own for repeated steps of code will save alot of valuable real estate. Be a miser were ever possible. By the way, checked out your project, pretty neat idea to count bodies. Good luck again and let me know if something just doesn’t work when converted to 'Tiny.

1 Like