6

I have an Arduino board where I am using some of the peripherals like LCD with I2C.

Now I want to convert this Arduino-based circuit to an atmega328p based circuit, i.e. atmega328p with LCD and I2C.

Here is my actual question: Can I use the same sketch (binary) that I have compiled and uploaded for the Arduino board for the atmega328p and does it work? Or do I need to write atmega328p based C++ code?

5 Answers 5

4

A compiled sketch will run just fine on a bare ATmega328p, if all the necessary surrounding components are there, and if you have a way to program it.

This could be as simple as putting the chip on the Uno and programming it there. Don't do that too often; the socket isn't intended for that. You could get a 28-pin ZIF socket, though.

There are a few things to consider:

  • The bare chip needs external components like a crystal, etc. to function; you can check the Uno's schematic to see what you want to copy to your PCB/breadboard;
  • You may want to include a way to program the ATmega328p in-circuit using an ISP or a USB-to-serial chip;
  • The pin numbers will be different, a minor annoyance;
  • Possibly things I forgot.

There is a how-to on the Arduino site, and also a description of how to build a "whole" Arduino on a breadboard.

2
  • Thank you so much! Jan 24, 2021 at 11:31
  • You are most welcome. Please accept the answer (if you accept it) so the question doesn't stay open.
    – ocrdu
    Jan 24, 2021 at 11:33
2

I've built PCBs with a standalone ATMega328p chip on them before for situations where I wanted all my electronics embedded onto a single board. It can be a great learning experience imo.

I would suggest first creating a schematic and implementing it on a breadboard with DIP packages as seen on the photo. You will need a crystal, loading caps (22 pF), as well as bypass caps (100nF) and pull-up resistors. Plus any other components your application requires. enter image description here

After that typically you would burn a boot loader onto the chip so it can be programmed with the Arduino IDE.

Nick Gammon has provided an excellent tutorial on all of this. His article was my main resource when I made my PCBs: http://www.gammon.com.au/breadboard

Once you get everything working on a breadboard, you may want to look into laying out a PCB for a more permanent solution. Best of luck!

1

Unable to write in the comments. If you are looking at using just a raw atmega328p, you can use the Arduino as ISP sketch and then upload your existing sketch to the new chip. I use it for programming ATTiny 85 chips for small stand alone projects. Here is a Link to the Arduino site which explains this in detail.

1

Yes, you can use the same sketch and also the same HEX file. Though the uploading depends on your actual setup. If you include a UART USB bridge, like the Arduino has, then you can upload over USB (assuming you have burned the bootloader to the Atmega328p). Otherwise you can use your Arduino as an ISP programmer and burn your sketch onto the Atmega through it. Google for Arduino as ISP for more information

0

The Arduino has already a 328p chip on the board, but with a bootloader and a 16MHz crystal.

If you use only the chip, you need to create a board like the arduino. Or you can extend the IDE with this board library: https://github.com/MCUdude/MiniCore

So you can still use the same sketch but remove the crystal for example.

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