12

I'd like to use an ATMega328P for my project, I hope to do it without the Arduino board.

I know with the Arduino IDE and an Arduino board I can program the microcontroller. However, would it be possible once I've programmed and debugged the program with Arduino IDE + Arduino board, to take away the microcontroller from the Arduino board and to use the ATMega328P separately, without the board?

If yes, what additional configurations I should do the ATMega328P to work correctly on the breadboard?

7

You can remove an ATMEGA from an Arduino and use it in your own board, however when used on a typical Arduino board the chip will be fused for an external crystal as a clock source, rather than the (simpler but less accurate) internal clock.

You cannot change the clock source over ISP unless the clock source the chip is currently expecting is operational, so if you want to change the clock selection you will want to do that before removing the chip from the Arduino.

However, you can also provide a clock crystal and its two capacitors (or a substitute resonator which often has this built in) on your external board.

Typically chips (even those pre-flashed with a bootloader as a convenience) are cheaper than boards, so it's unclear why you would want to move the same chip off the Arduino as opposed to using another. You will want a USB-logical level serial adapter anyway, and once you have that you can do development on the bare chip on your board, even if you do initial testing on the Arduino. In a pinch if you don't have the USB converter you can either pull the chip out of an Arduino board and run wires from its D1 and D0, or hold the on-board chip in reset to allow you to borrow those serial lines without interference.

  • 1
    My idea is to use only a microcontroller without a board. As it is easy to program an Arduino, I thought I may chose an ATMega. So, I have an Arduino uno, my idea is to buy only one ATMega and to program it and debug it using the uno board. However, I've just reaslised that if I separate the ATMega from the Arduino, I would need to add components(crystal, pull up resitances..). Can you please explain what you mean in the last paragraph of your post? Is there a simple way to program directly an ATMega(or any other microcontroller) without using the arduino IDE? Thanks. – George Oct 11 '15 at 18:09
  • While you can skip the IDE, using it or not is essentially irrelevant to the complexity of your circuit, as you can either use the IDE or not with a circuit that either has or doesn't have an external clock and either using a USB-serial on your target board, on a cable, or by programming your sketch with an ISP programmer. Yanking a chip off a board gets you nothing compared to just buying a chip either with a bootloader or without and loading one yourself, potentially using your intact Arduino as an ISP programmer, or using ISP to directly load your sketch without a bootloader. – Chris Stratton Oct 11 '15 at 18:54
7

Yes you can use ATMega328P without arduino board. I always use the IC without arduino. There are two ways of doing it.

  1. You can use arduino board with the IC. Program the IC and then take it out and use it in your circuit. You will have to use 16MHZ Oscillator with capacitors.
  2. If you don't have arduino board, you can use other programmers like USBasp to program your Atmega328p. In this case, do not use the direct upload button instead use the upload using programmer options from file menu. Do not forget to select board as Arduino Pro or Pro Mini (5v, 16mhz) With ATmega328 and programmer as USBasp.

NOTE: Refer to Atmega328p Pin Mapping and program your device accordingly. Enjoy!

2

Search for "Build an Arduino" - you'll find tons of how-to articles about doing just that. You'd need to be able to solder connections on a printed-circuit board (and not even that if you wanted to use a solderless breadboard), but it's really straightforward. You can even build it first and program the MCU on the PCB using an FTDI cable. I use an Arduino board and a solderless breadboard to experiment with unfamiliar parts, but I usually go immediately to a hand-built board once I'm familiar with all of the components I'll be using.

Prototyping with the Arduino board lets you throw together a bunch of parts and get something working quickly, and if the Arduino is more capable than your final target - f/ex, a Mega 2650 - you can temporarily ignore the memory and I/O constraints of the smaller device.

0

It's fairly easy to use a standalone Arduino chip. The one tricky thing about the chip used for the official boards is that they are fused to use the faster (and more accurate) external oscillator that's mounted on the board. This applies even when you purchase the loose chips, since most are resold with intention of being installed in an Arduino board to replace a burned-out one, with exception of perhaps the ones from Digikey.

Caveats: The Arduino is designed as a prototyping board, and few things do better than it does at this task. You may want to leave the chip on the Arduino board until you are done designing and testing your circuit. Only then do you connect it directly. It can be used in-place if you have a clock circuit in place, or you can change the fuses (see later) and reprogram the Arduino with an ISP adapter and a clock speed of 8mhz (PlatformIO lets you do this (and allows direct imports of an Arduino sketch) -- check their docs page for the Atmel AVR plugin, but you can also look up a number of guides on how to add a board file to Arduino to tell it to use the 8mhz option for a bare chip)

If you remove the chip for use in a different circuit, it either needs that clock circuit added back in, or to have its fuses changed (I'll get to that in a minute). It will also be hard to program, for a number of reasons, so you'll want to purchase a bit of fairly cheap hardware:

Programming a standalone chip: The Arduino's CPU is not natively designed to talk to a computer. You need an intermediary. On the Uno, this is done via a second Atmel chip that has USB capability, and a bootloader on the main chip. What that does, is that it uses the UART for upload of the program while the USB chip converts the PC's messages to UART signals. Since the bootloader is somewhat of a pain when the chip is on its own (since UART is picky and installing it sets the chip to use an external clock as a result), you'll want to buy an ISP programmer for the Arduino (or follow the Arduino-as-ISP sketch and instructions to make your own, which requires an Arduino with chip present, so you'd need a second to be programmed).

These can program the ATMega 328 directly over SPI, without a bootloader (there are many instructions on the Internet; search "program bare ATMega 328P with USBAsp", for instance). This makes it a lot easier to change and debug your program outside of popping the chip out and back into the original Arduino board. You also need one to change the clock settings if you don't want to use an external crystal.

If you want to debug the chip, it's useful to also purchase a FTDI adapter or other USB-to-UART converter. Note that without the reset circuit part of the board (or again, adding your own), this still won't let you program the ATMega even with the bootloader, though. For that, connect the ground, RX, and TX pins to the adapter. You may or may not want to connect the VCC line, but it's advised to not do so if there's a lot of things connected to the chip and/or it has its own power supply. Note that the RX and TX need to be swapped when you connect them; that is, RX to TX and TX to RX -- you want the chip to RX (receive) what the adapter is TX( transmit)ing, and vice versa.

The clock circuit is not hard to build, but it requires a few components you may not have. So, to change the clock source, go to http://www.engbedded.com/fusecalc/ and select the ATMega 328P. The defaults are good, but you may want to enable EEPROM keep-on-erase and disable the clock divide-by-8 or adjust the brownout settings. Don't touch anything else (disabling reset or SPI or enabling DebugWire result in "fun" that requires a HV programmer to fix). When done, paste the command it provides to the AVRDude command. You will need to change the -c options (-p is already set to the ATMega 328P, but will fail for non-P 328s -- don't buy those), and perhaps add the -P option (for Port). Do not omit the lowercase -u option, or it will refuse to update the fuses.

avrdude -p m328p -v -c usbasp -B 100 -u [add extras here: (-P <PORT>) <fuse set command here>]

Note that if you purchase a USBASP (make sure it has three sets of jumpers!), for all that they are my favorite programmer, they may not have the updated firmware that supports the -B option (which you'll probably need). That means that you need to attach it to an Arduino via the six-pin programming port, in the exact same way that you'd use it to program the Arduino's bootloader, but then use the Arduino-as-ISP sketch to program the new firmware to the programmer (search "update the usbasp firmware via arduino-as-isp")! For reference, that usually means that the cable faces away from the body of the board, and you'll probably have to program the sketch before connecting the cable. Also enable the power-from-programmer jumper on the USBASP (5V), and the "self-program" one. (see https://forum.arduino.cc/index.php?topic=560719.0 for the location of the power and program jumpers (JP2)).

Not the answer you're looking for? Browse other questions tagged or ask your own question.