Migrating from an ATmega328p to a larger uC

As the title so eloquently states, I was wanting to ping some of the more experienced and helpful guys and gals here about a concern of mine.

I have been hand-jamming away on my ATmega328p (Arduino Uno) and I have been designing systems that now use multiple uC (standalone) that communicate wirelessly. This is causing my central hub to get bigger and bigger. Reason being is that I don't want large uCs on each peripheral; instead, I want a small chip (ATtiny8) on the peripherals and a larger central microcontroller at the hub that does all of the real crunching.

I have been looking at larger micros, preferably ones with more flash. Something like an ARM Cortex or any of the TI processors (yes, I know that a processor is not the same and that it would require additional resources).

How difficult is it to port firmware that was designed on, say an ATmega328p, over to something larger and a bit more complex? Is it just as simple as changing a few lines of code (GPIO pins, platform-specific references, et cetera) or does something like that usually require a complete overhaul?

Thank you in advance for your helpful comments and experiences.

Cheers.

Would the processor on the Due do? 32 bit, supported by the IDE. Should be "easy" to port. Change from 5V system to 3.3V system needs to be considered.

@CrossRoads you make a good point. I've just heard stories about meshing together certain uCs but there's a lot of support out there. I've been leaning towards the ARM Cortex models. As long as I can program them in C/C++ it seems alright with me. Is that gonna be too big of a jump from the Atmel AVRs?

No idea. Anything beyond 1284P, maybe 2560, becomes too much of a programming task, I prefer to stay with the embedded hardware design part of Arduino.

That brings up an interesting point. What is life like outside of ArduinoLand for people started programming with an arduino and
were thinking of going outside the arduino compatible arena . What do you have to do that you don't normally if all you've ever
known is an arduino ? Do you have to deal with addresses ? What else is different ? (assuming the language is still C++ (pure C++)

Browse the posts of folks asking about getting the Arduino libraries working in Atmel Studio.

raschemmel:
What else is different ?

How long is a piece of string?

I reckon if you understand the underlying Atmega hardware - i.e. if you are comfortable working with the Atmel datasheets - you will have a good grounding for using any Microprocessor. I had used PICs before I discovered the Arduino system and the transition was very easy - the concepts are pretty much identical.

The programming environment for other devices may appear more complex after the hand-holding built into the Arduino IDE - you may have to learn a bit more than you would like about C/C++.

The sort of person who likes to ask a question on the Forum everytime something new crops up (rather than figure it out for himself from the datasheet) should probably stick to the Arduino system.

...R

Browse the posts of folks asking about getting the Arduino libraries working in Atmel Studio.

The language is the same. You can either use Arduino IDE or Atmel Studio (http://www.engblaze.com/tutorial-using-atmel-studio-6-with-arduino-projects/) The Arduino libary is more of a wrapper to make it easy to do things, like digitalWrite, which you do not have by default in Atmel Studio (or you can define it yourself). With Atmel Studio you would flip a bit in a register to turn on the digital port. Now for the AtMega2560 and the AtMega328 these registers are different. So you can't just compile the same source and expect it to run on both MCU's when using the registers. Again, of course, you can specify a compiler flag that you are now using AtMega2560 or AtMega328 and define the registers in your own digitalWrite function accordingly, and that is exactly what the Arduino library is doing for you.

You can choose to use the Arduino Library while working in Atmel Studio, or you can choose to use native register operations toggling bits and so forth using Arduino IDE. To get Atmel Studio running with Arduino library and AVR dude requires some setup, but it might be worth it, depending on how large your code project is. Atmel Studio is based on Microsofts Visual Studio with code suggestion/completion and intellisense which could drastically speed up the development of the code.

What do you have to do that you don't normally if all you've ever known is an arduino ?

You pretty much need to read and understand the chip datasheets A LOT MORE than in arduinoland. Actual chip addresses and such will be symbolically defined (PORTD, etc), but you need to deal with them a lot more directly.

Paul Stoffregen has a nice arduino 'mostly' compatible product... Even uses the same IDE with his software addition to the Ver 1.05 IDE it's an add on that doesn't incapacitate the basic Arduino IDE use.
It runs Arduino code too and is a lot more capable. A 32 Bit ARM processor board similar to the Pro Mini in size called the Teensy3.1
Although the Arduino paradigm is still my favorite by a long shot because, although I have 20+ years in hardware design my code skills are poor at best compared to PaulS or Awol or any of the other heavy hitters... So I get the best of both worlds.
Although the Teensy lacks really strong pin drive capacity, it's other features make it ideal when casting about for a bigger controller...
Perhaps it's real lack is the plethora of pins that a Mega or a Due has (34 for the Teensy 3.1) 256K of flash and 64 KB of Ram make it very attractive for fast (overclocking @ 96 MHz) projects.. I use smaller processors (Mega1284 Bobuino) for high pinout devices like large GLCD's or large keyboards... I have a project involving a scrolling display and a 5" GLCD with a 40 key tactile keyboard and for that I use a Mega for display(s) and keyboard control...

Doc

In looking at alternate larger resource chips, you have a couple of ways to go,
Move to a larger AVR like the 1284p or leave the AVR behind and move to something even better like
an pic32 or an ARM.

A lot of it depends on if you need shield compatibility and if you need to use
the Arduino and the Arduino IDE for programming.

Another thing to consider is i/o drive capability.
The non AVR solutions like ARM or pic32 are typically 3v outputs vs 5v outputs
and also tend to have much lower current capabilities.
The DUE is 3v only and will blow up if you feed it 5v signals.
The pic32 parts and the Teensy 3.1 are 5v tolerant which is a big plus over DUE.

The biggest issue when moving from an AVR to another processor architecture is the s/w.
While Arduino is supposed to make that transparent, in reality it doesn't since it lacks
many needed capabilities. Because of these lacking capabilities, many library writers step
outside of the Arduino core code functions and write to the hardware directly.
Any code that does this will not function on different chips.

If all you need is something a little larger and need AVR backward compatibility then
the 1284p is nice. A major drawback is its physical size. Is is a very large package.
But there are some 1284p boards out there that are the same size as an UNO
if shield compatibility is a requirement.

If you need something much faster with lots more resources, then look at the pic32
or an ARM solution.
The nice thing about these solutions is that not only are you bumping up the clock rate
a lot, you are also going to 32 bit and you no longer have to worry about all the
proprietary AVR PROGMEM crap to put data in flash.
With the other parts, you simply declare your data const and it works as the C compiler intended.
It makes coding much simpler since you can directly access your data regardless of whether
it is in RAM or flash.

There are some nice pic32 chips out there including some in 28pin packages that
are the same size as the m328 but have 128k code and 32k ram.
http://chipkit.net/tag/breadboard/

And then there are the chipkit boards if you need something with shield compatibilty.
http://www.digilentinc.com/Products/Catalog.cfm?NavPath=2,892&Cat=18&CFID=6048966&CFTOKEN=aed4ff819c7cfa19-AE834A4A-5056-0201-02AEEACCE383F469
Perhaps something like a uno32.

The pic32 based boards will use mpide.
While it provides an experience similar to the Arduino IDE (it was based on the Arduino IDE code)
it will not be exactly the same, and as of right now the code and libraries that come with mpide are
not 1.x yet. They are close to 0023 but have pulled in some of the 1.x updates.
So depending on your code this may or may not be an issue.
Also, no all the libraries available for the AVR work or are available for the pic32.
Again, this may or may not be an issue.

For an ARM based solution, I'd definitely look at Teensy 3.1
especially if you don't want/need shield compatibility.
Not only is it much smaller than DUE, but it is also 5v tolerant.
Which means that it will not blow up when connected to 5v parts like the DUE can.
In most cases, while the output pins are only 3v usually that will work with 5v parts.
Also, the s/w for Teensy 3.1 is much better than DUE as Paul has done a tremendous amount
of work ensuring that many libraries work with the Teensy 3 boards and has added some
compatibility code to "trick" some AVR specific library code to work.
For s/w compatibility, and features it will be much better then DUE.

Then there is radical approach of totally changing what your hub does/is.
I think this is worth serious consideration.
Consider using a Raspberry PI for your hub.
This will give you a system with a real operating system.
Now you can use full tools, languages, and debuggers to get everything working
(You can even potentially debug it on your PC - assuming you are using linux)
and can have network access and web interfaces and do all kinds of things.
And then you also have video and audio capabilities as well.

There are many ways to interface to the Raspberry PI.
I can't seem to find the link but I did see a project where it was used as hub
to wireless communicate with dozens of arduino based sensor and i/o modules.

The beauty of switching to something like a Raspberry PI or BeagleBone
board is that it has a real OS with lots of room to grow as a central
hub type controller. It can do things that are difficult or impossible
to do with any Arduino type board.

--- bill