Tips for using ATMEGA328 without UNO board

I've got a project where, for reasons of size and cost and the fact it involves several chips each performing different high speed tasks which can't be done together on one chip, I'm wanting to use ATMEGA328 chips along rather than built into an uno/duemilanove. I'm aware that there are many ways to set up a lone chip so it can be programmed from the arduino IDE and quite a few ways to use them in terms of the circuitry they need to operate, but it seems some of the tips I've found online are contradictory, so I'm not sure which methods are actually best. To this end I have a couple of questions:

  1. Can only ATMEGA328P chips such as https://uk.rs-online.com/web/p/processor-microcontroller-development-kits/7589339/ be used, or can any ATMEGA328 do? I've found the latter available cheaper by a few £, which matters when you need quite a large number of them.

2.Assuming that a 16MHz oscillator and a pair of 22pF capacitors are used is an ATMEGA328P (or 328 non P if that is possible, see Q1) able to be programmed just like a normal uno in terms of settings or must breadboard arduino settings be used? The same goes for the process of putting a bootloader onto the ATMEGA, must weird settings be used?

3.When wiring it up to program I've found that one takes an uno board, carefully levers out the ATMEGA (any tips on technique and tools for this?) from it and runs wires from 0 and 1 on the uno board to places on the chip. Are the oscillator and capacitors supposed to be fitted while doing this?

4.With a lone ATMEGA328 chip will I2C work exactly the same as with a full uno? I know that there are pullup resistors on these pins (4 and 5 on the uno, other numbers on the ATMEGA), but are they built into the ATMEGA or are they on the uno board? I'm thinking specifically in the context of having the ATMEGA as a slave I2C device to a raspberry Pi, with a full uno you don't need to worry about level shifting, you just run wires straight from the Pi's I2C to the arduino's and as long as the arduino stays slave this works fine despite the 5V versus 3.3V, should the same still be the case with a raw ATMEGA328.

5.Are there any safety circuits on an arduino to prevent damage which are not built into the ATMEGA328 itself, if so what extra pre-cautions need to be taken to avoid burning out a raw ATMEGA chip which aren't a worry with a full arduino?

Thanks

Infraviolet:

  1. Can only ATMEGA328P chips such as https://uk.rs-online.com/web/p/processor-microcontroller-development-kits/7589339/ be used, or can any ATMEGA328 do? I've found the latter available cheaper by a few £, which matters when you need quite a large number of them.

That one comes with the bootloader installed, which allows you to upload sketches to it over USB-serial just as you do with your Uno. If you buy ATmega328P without the bootloader installed then you only need to connect an ISP programmer to the chip and then do a Tools > Burn Bootloader in the Arduino IDE to flash the bootloader to the chip, after which you have the exact same thing RS is trying to sell you at a steep markup. You can use your Uno as an "Arduino as ISP" ISP programmer if you like or you can buy a dedicated ISP programmer, which is more convenient if you'll be doing a lot of this. I like the 6 pin USBasp programmers. You can buy them for as low as <$3 USD w/ free shipping on eBay if you don't mind waiting for shipping from China.

Infraviolet:
2.Assuming that a 16MHz oscillator and a pair of 22pF capacitors are used is an ATMEGA328P (or 328 non P if that is possible, see Q1) able to be programmed just like a normal uno in terms of settings or must breadboard arduino settings be used? The same goes for the process of putting a bootloader onto the ATMEGA, must weird settings be used?

You can just treat it as an Uno.

Infraviolet:
3.When wiring it up to program I've found that one takes an uno board, carefully levers out the ATMEGA (any tips on technique and tools for this?)

I use one of these:

I only recently found they're not intended for pulling DIP ICs from a socket and it is kind of awkward but I still use it. The trick is that if one end of the chip comes loose from the socket before the other then you will bend a bunch of the pins. After they're bent they lose some strength and you will have trouble getting them in a socket without bending them again, losing more strength until they eventually break off. Ideally you would not use a standard socket for a lot of insertion/extraction cycles. They're not really intended for that purpose. My advice is to leave your Uno alone and instead just buy a cheap USB-TTL serial adapter board that is made for this specific purpose. Make sure to get one with the FTDI header pinout that has the DTR/CTS pins broken out. It's also nice to get one with adjustable 5 V/3.3 V power. I use these:
https://www.ebay.com/itm/253506053642
You just need to know that the FT232 chip on them is counterfeit and the official FTDI Windows drivers were at one time bricking counterfeit chips. I don't know whether they are still doing this and there are easy workarounds for the issue to fix the "bricked" chip.

Another option, which won't have the bricking issue is this one:

It's not so easy to change the power level on that one.

Infraviolet:
Are the oscillator and capacitors supposed to be fitted while doing this?

When you do Tools > Burn Bootloader you set the fuses according to the hardware definition of the board you have selected in the Tools > Board menu. If, as with the Uno, those fuses specify an external clock source and you don't have an oscillator connected then the chip will be "bricked" until you connect an oscillator. You also have the option of running the chip at 8 MHz or less on the internal oscillator but you need to use the hardware definition for it. That's the point of the "breadboard" hardware definition you mentioned but I recommend using this one instead:

Infraviolet:
4.With a lone ATMEGA328 chip will I2C work exactly the same as with a full uno?

There's no magic to an Uno. It's just an ATmega328P on a PCB with the minimal support circuitry. You can find the schematics here:

Infraviolet:
5.Are there any safety circuits on an arduino to prevent damage which are not built into the ATMEGA328 itself, if so what extra pre-cautions need to be taken to avoid burning out a raw ATMEGA chip which aren't a worry with a full arduino?

There's a PTC fuse and some power switching circuitry to prevent problems if you have power connected to the barrel jack and the USB socket at the same time. I suppose you could consider the voltage regulator on the barrel jack a protection of sorts since it will prevent the chip from >5 V supplied to the barrel jack.

Thanks for your tips.

To clarify, are ISP programmers for bootloading and USB-TTL FTDI adapters for programming typically the same device or not? I tend to use a Linux OS rather than windows, so would my situation be the same when you mention drivers attempting to brick FTDI devices? Often I also run the arduino IDE on a raspberry pi too as well as using a normal x86 linux PC, just because a Pi can be easier to carry around when necessary. When using such device(s?) do I just run the arduino IDE as normal and use it for programming as normal, except that a specialised little USB will be used for bootloading or programming the ATMEGA chip, or must other settings changes be made?

Infraviolet:
To clarify, are ISP programmers for bootloading and USB-TTL FTDI adapters for programming typically the same device or not?

The short answer is they are different tools used for different purposes. The long answer is that it actually is possible to use an FTDI FT232 as an ISP programmer but it's super slow and there is no support for doing so via the Arduino IDE. I've never heard of someone actually doing it, other than an article on adafruit.com. The only occasion where I would consider doing that is if I needed an ISP programmer and only had an FTDI. But that would be rare in the Arduino world since we can make a spare Arduino board into an Arduino as ISP programmer, which is easier and superior to the FTDI as ISP option.

Infraviolet:
I tend to use a Linux OS rather than windows, so would my situation be the same when you mention drivers attempting to brick FTDI devices?

I'm pretty sure that situation was always limited to Windows and I think FTDI even stopped doing the bricking thing. I switched to an alternative driver after that happened so I don't know what the situation is.

Infraviolet:
When using such device(s?) do I just run the arduino IDE as normal and use it for programming as normal, except that a specialised little USB will be used for bootloading or programming the ATMEGA chip, or must other settings changes be made?

To upload using your FTDI or CH340 adapter you only need to select its port from the Arduino IDE's Tools > Port menu. No special settings are needed.

Quick check then:
These https://uk.rs-online.com/web/p/microcontrollers/1310277/ should be able to be bootloaded then programmed as if they were an uno?

I know that an ATMEGA328-PU is NOT the same as an Atmega328p but are both of them easily arduino programmable?

Thanks

The addition of the P means it is the lower “pico” power version. You can put a bootloader on and use it but not as the Uno since the chip has a different signature which is checked before programming.

Use the Duemilanove board type in the IDE as it used the non-p version of the chip. Other than the lower power and the different signature, they’re the same device.

It’s probably worth mentioning that if you’re going to be programming the chips with a bootloader, you really want/need to purchase a usbasp programmer. As Pert mentioned, you might be able to do it with the FTDI usb to serial converter but it’s really not advisable. A usbasp can be had for a couple of quid from China in a few weeks and it’s simply not worth the hassle to try to do it otherwise. The usbasp plugs into the six pin ISP header on the Uno.

If you’re going to be installing bootloaders onto more than a handful of chips, it would be be worthwhile to purchase another Uno (or clone) and one of the “isp shield” that plugs into the Uno and has a 28 pin zif socket. That will save wear and tear on the chips and lots of time.

eBay isp shield

Buy 20 pro minis :wink: design around these.

avr_fred:
Use the Duemilanove board type in the IDE as it used the non-p version of the chip. Other than the lower power and the different signature, they’re the same device.

The board definition for Duemilanove specifies ATmega328P:

diecimila.menu.cpu.atmega328.build.mcu=atmega328p

That will cause the signature verification to fail if you try to burn the bootloader to an ATmega328 with the Arduino Duemilanove or Diecimila board selected.

MiniCore has a board definition for ATmega328:

  • Tools > Board > ATmega328
  • Tools > Variant > 328 / 328A

Would I be better off with this

or this

then?

They look to be the 328P type so should be the same as the chip in an Uno. That one from farnell looks a bit odd though, the data sheet seems normal enough but the image shows it to be rather wider than usual PDIP chips, and there isn't anything on the webpage itself which explicitly mentions pin spacing or width of the device. The datasheet talks of pin spacing and seems to say it is as usual, but for all I know farnell might have taken a standard datasheet for the atmega328p and accidentally put it on the page for a 328p in a wider format.

I would probably go with ATmega328P but you'll be fine with ATmega328 if that's what you end up with as long as you're not needing super low power operation to make batteries last for a long time.

Infraviolet:
That one from farnell looks a bit odd though, the data sheet seems normal enough but the image shows it to be rather wider than usual PDIP chips, and there isn't anything on the webpage itself which explicitly mentions pin spacing or width of the device. The datasheet talks of pin spacing and seems to say it is as usual, but for all I know farnell might have taken a standard datasheet for the atmega328p and accidentally put it on the page for a 328p in a wider format.

I think they just messed up and posted the wrong picture or maybe they just put a generic IC picture on their products so they don't need to have a specific pic for every single one. The ATmega328P is only available in one DIP package. Farnell is reputable so I'm sure they'll send you the part you order. Note that is only available for backorder. That is the ATmega328P-PN, which has a higher temperature rating than the more common ATmega328P-PU. You might find the -PU to be in stock and cheaper. Either will work interchangeably other than the temperature rating.