Keeping the same arduino code, migrate to another micro.

Hi all.

I made some progress on a project I am working on, with Arduino mega2560, and I want to go to the next step, which is to build my own PCB.

However I don't want to use a ATmega2560 for my project but a ATmega1284.

I built this project in Atmel Studio with the arduino create project, so it uses libraries and working with hardware from ATmega2560.

Is there any process I have to follow to get this to work? How should I instruct my code to work for another micro? I don't think that by simply changing the name of the micro in the settings will do it for me!

Any help is valuable!
Thanks everyone.

It really depends on the code, including the libraries you use. A lot of Arduino code is portable to any microcontroller that has a core library that follows the standard API. Other code is processor specific. This hardware package:

does an excellent job of offering a seamless transition. It also contains documentation to help you when porting is necessary:

I recommend you to go ahead and try it out, that's the best way to see what will be required. If you don't have an ATmega1284 yet you could at least compile the code for ATmega1284.

Even within the "normal" range of Arduino boards there are differences in the hardware - for example a Mega has 4 USARTs and an Uno has only one. So transferring code from one board to another must take account of those differences. They are not automatically taken care of by the Arduino IDE. Getting familiar with the datasheets for the different microprocessors is always useful.

...R

I am having trouble understanding the mightycore.

"Here's how to port a library

Download your library and open the header file (the one that ends with *.h)"

I know this might sound like a very silly question, but what is my library that I should download and from where?

My project includes a lot of files and it is written in Atmel Studio, I just created the project from an arduino already existing project and I added other files. So I am mostly concerned with the include files, the peripherals and their addresses.

Thanks for the reply!

Those instructions are targeted to porting libraries that are not compatible with ATmega1284 or on of the other MightyCore boards but they could be applied to porting other code too.

A library is a collection of code that can be easily shared between projects. You can find a list of the libraries included with the Arduino IDE here:

There are many other 3rd party libraries for Arduino available.

If you try to compile your code for ATmega1284 and it has an error then you need to identify where the incompatible code is by examining the error messages. That will tell you which file you need to port, following those instructions.