How to program an Atmega328?

Hi all,
I want to start learning about microcontrollers; but I’m also interested on musical devices, so I don’t want to spend much time in the blinking leds phase :slight_smile: for the moment. So my idea is to try to program an atmega328 with the grids code and play with it in a breadboard, and try to change some things, etc (maybe I finish with some custom drum machine, who knows).
But the thing is I don’t know where to start… I’ve ordered a couple of atmega328 in my last order from farnell but I really can’t find useful information about what to do next. I know I have to program the chip but what I don’t know is what kind of device do I need to do that from my computer. Sorry for the noob question but I’m gettin really lost with Arduino and all that stuff… Would I be able to program the atmega328 with an Arduino One? Or there’s some problem with clock rates or something like that?..
I just want to know what to buy in order to start programming microcontrollers and upload some code to them. Any help would be very appreciated :slight_smile:

I’m a bit of a noob myself and I don’t think there’s a single way to learn. I’m also in the process of learning about microcontrollers for music applications and I’ve started like many others with an arduino, doing some midi stuff. It’s probably not the best platform for advanced stuff, but so far I was able to make my ideas real with very little fuss.

At the moment I’m learning how to draw and make a pcb (because my previous project was made on a perfboard and it was a bit annoying to solder) and also how to interact with eurorack stuff (doing cv with dac, etc).

I found that the electronic and programming stuff is rather easy (thanks to tons of tutorials on the net and kind help on this forum !) but I spend a lot of time on the mechanical side of things: find the right pots/switches/whatever, make a case, etc.

You could probably use an arduino as an avr programmer, wether you want to use the arduino libraries or not.

Thanks! I’ve watched the video, and it looks like I can program the atmega328 using an Arduino One.
I’ve seen that I can use something like an USBTiny to do the same.
What kind of solution would be better for a beginner? And, specifically, would I be able to program the grids code with one of these things?

As a noob I wouldn’t dive into grids code but again, your mileage may vary.

Its crucial to have a good development environment. “Building” up the tools yourself from re-purposed arduinos, etc. can leave you wondering if your error is in the programming adapter or your target circuit. Honestly, if you can shell out the money for an arduino, you could just as well buy any cheapo 10€ AVRisp mk2 compatible programmer.

Look for an ISP programmer dongle that works with avrdude. Avrdude is the open source software for downloading the compiled firmware to the chip. It is available as part of WinAVR, Crosspack or as a package on all major linux distros.

+1 for not trying to cut corners on the tools.

Something like this would work?

Would that be more reliable and solid that the chinese avrisp compatible things I see in ebay? Or there’s something better? What would you choose? Money is not a concern at this level; i can of course spend 10 or 20€ more to be on the safe side :slight_smile:

> Something like this would work?

No. This is a board with an ATmega328p. This is not the same thing as a board designed to program an ATMega328P.

Here’s an AVR programmer from adafruit . The chinese things are solid and reliable… unless they aren’t. And when they don’t work there’s nobody to give you help and support. I’d recommend the Atmel AVR ISP mkII if you can still find one. They have discontinued it, I don’t know what replaced it.

ok, I think I know better what I need now, thanks to your help. I am in Spain, and the adafruit shipping costs are terribly high (the cheapest is 59$!), but I found this one from sparkfun that seems to do the job: https://www.sparkfun.com/products/9825
I think this thing is going to work for my purposes, right?

Yes, you’re on the right track!

Good! Thanks! :slight_smile:

I can recommend using an arduino board for programming with avrdude. I’ve also found Nick Gammons tools very handy.
My biggest problem was setting the fuses for different clocks. New chips are fused to use internal oscillator so you can’t have a crystal when setting the fuses the first time.

That’s weird - I’m pretty sure I have flashed just about every AVR I have with a crystal present, even when they’re new - the crystal just won’t get used until the fuses are set right…

That’s correct. It just won’t use the crystal.

I could be wrong. But there is still a problem when you want to go back to internal oscillator (I’ve had some “new” chips that was already fused in the past).