Go Down

Topic: How to know if a Arduino has enough memory for a project (Read 2485 times) previous topic - next topic

pYro_65

The faster execution has not been evident in practice, and I doubt the OP will see it either.


On a large project the difference can be significant.
The 2560 for example is slower at branching. And jumps do not have to move to far locations on the Uno.
Not to mention the 20MHz capability.

I reckon the statement: 'The only advantage a Uno has is its size', is better off: 'The only advantage a Mega has is its size'

Nick_Pyner


'The only advantage a Mega has is its size'[/i]


This may be true but, when Uno is too small,  it's the deal-maker. So, i guess my comment still stands.

Retroplayer

#17
Feb 07, 2013, 11:10 am Last Edit: Feb 07, 2013, 11:20 am by Retroplayer Reason: 1
For me, the Uno is nice for testing out bits of code on unknown hardware. If I break it, I can replace the IC easily and won't shed tears. But if I break the Mega doing something dumb, I have to buy a new one or pay almost as much for a new SMD chip as I did for the whole thing and attempt to rework it.

And the Uno is also nice for the fact that since it is using a DIP chip, you can prototpye with it and then build your project easily on a perfboard with just the 328P.

I came from using straight AVRs for my projects, and I had the Uno for a couple years that I got for a gift and never used it. I have come to like how easy it is to use and how the direct register stuff is mostly hidden. But, I will admit that the code it generates is huge compared to doing everything the raw way. Such are the sacrifices and the decision to make.

Arduino is really just C (and some C++) with really nice libraries written for you, so once you finish a project, it isn't terribly difficult to just port your code over to using raw gcc code. At the core of arduino, it using the raw C code anyway. So for digitalWrite for example, you can just go into the core code and look at how it was implemented and transfer the pieces over to your raw code. Learning C the Arduino way makes moving over to doing it another way a relatively small step.

In the end, Arduino is really, at it's base level, just an AVR development board. So there is also nothing stopping you from using the boards with just AVRStudio and writing code that way and just using the boards for all the support circuitry and shields. In fact I was doing just that when I first pulled my arduino out of the toolbox (maybe a month ago, actually) because I didn't see the beauty of the Arduino "package" at first.

It may not seem obvious to someone first starting out, but there is "Arduino, the hardware", and "Arduino, the software." And they are really separate from each other.

I do think someone needs to smack the person upside the head that decided to put in the offset headers, though. Definitely a marketing ploy to sell shields! There was no reason to do that other than to purposefully make it non-standard in a way that (mildly) forced people to buy shields. The marketing guys will say it is a "feature" to ensure you only plug in "blessed and tested" shields, but the marketing guys always say stuff like that. Obviously, many people have found ways around that, and of course they would.


With all that said, because the hardware and software are separate in the Arduino world, the code you develop on the Uno could easily just be compiled right on to the Mega by changing the "board" in the IDE if you start running out of room. If you have to make any chages at all to your code, it will be minor. But before changing out boards, I would experiment with trying to optimize code. There is more than one way to skin a cat, and some compile to smaller code than others. 32K is relatively huge in the microcontroller world. I have skimmed off a few K before just by changing the way I do things. Many people leave in Serial.begin for example when they aren't using the serial port in their final design. This adds in the entire serial library to the compiled code. By removing just that one line, you leave out a ton of code that you weren't using anyway.

Retroplayer

I have also stripped down libraries and clone it to a new library when they have way too many features that I am not using. Whether you use functions in the library or not, the entire library will get added into your code when you #include them. So, I often strip out all the stuff I don't use in my particular project if I want to save the room. Stuff like ifdefs which reconfigure the functions for different boards and such are easy targets.

MrGlasspoole

I have an old Mega and the last revision.
The reason i took the Nano for the bathroom was that i can solder him on a Stripboard.
Yes i saw there is a shield with screw terminals. But it costs money, you have to order
it and wait for another part and then i also have to solder the cables to the PCB/Stripboard
and then screw them to the shield.

Also with just plugging the cables in the shield headers (something i don't like for fixed installation)
it's a cable mess.

liudr

Nick, you dont have to always be right, like not every needs mega. Read long comments retroplayer wrote to make up for the lack of extensive exper ien you got with uno and standalone projects. The whole point, I repeat whole point of having a dip chip in the world of surface mount, is clearly to be able to prototype and remove the chip to make a standalone project or damaged chip. If you designed as many arduiblno standalone projects as I did, while not having the steady hand or skills as I dont, you wil know surface mount 100+ leg chips are absent from these designs.

Nick_Pyner



Many people leave in Serial.begin for example when they aren't using the serial port in their final design. This adds in the entire serial library to the compiled code. By removing just that one line, you leave out a ton of code that you weren't using anyway.


This is one of the best rambles I have seen on this forum. While I recognised that the serial port may be only used in debugging, it never dawned on me that there is a prize for dropping the serial begin command.  As it turns out my jobs need the serial for bluetooth but this is a trick to keep in mind.  I had the view that, while I was took a future bluetooth card as a final reason for moving to the Mega, this had turned out to be the only reason for not moving. Apparently that was not quite true after all......

Retroplayer

Yep. Just tested it:

For a blank sketch:

Code: [Select]

void setup(){

}

void loop(){
 
}


It compiles to 466 bytes.

Just adding Serial.begin(9600); in the setup:

Code: [Select]

void setup(){
Serial.begin(9600);
}

void loop(){
 
}


Results in 1.75K compiled. Just one line! That's beacuse it is now including Serial and all support libraries for it.

Obviously you aren't going to save 1.75K by removing it because many of the same support libraries are used by other functions, but every bit makes a difference.

Code: [Select]

void setup(){
Serial.begin(9600);
}

void loop(){
  digitalWrite(3,HIGH);
}


Compiles to 2K. While:


Code: [Select]

void setup(){

}

void loop(){
digitalWrite(3, HIGH);
 
}


Compiles to 732 bytes. Nearly 1.2K is used by the serial library and we weren't even using it.

Here's my raw measurements:

466 bytes for blank sketch
1,744 bytes for blank sketch with Serial.begin() in setup
2K with digitalWrite in loop
732 bytes without serial.begin
1K for just analogWrite in loop
2.3K for analogWrite in loop and Serial.begin in setup

PeterH


It may not seem obvious to someone first starting out, but there is "Arduino, the hardware", and "Arduino, the software." And they are really separate from each other.


I would go a step further - there's really:
Arduino, the hardware.
Arduino, the runtime software.
Arduino, the integrated development environment.

The hardware and runtime software is great.
The IDE isn't great but it's free, and makes it easy to get started in firmware development.
I only provide help via the forum - please do not contact me for private consultancy.

Nick_Pyner

#24
Feb 07, 2013, 04:28 pm Last Edit: Feb 07, 2013, 04:48 pm by Nick_Pyner Reason: 1

Nick, you dont have to always be right, like not every needs mega. Read long comments retroplayer wrote to make up for the lack of extensive exper ien you got with uno and standalone projects. The whole point, I repeat whole point of having a dip chip in the world of surface mount, is clearly to be able to prototype and remove the chip to make a standalone project or damaged chip. If you designed as many arduiblno standalone projects as I did, while not having the steady hand or skills as I dont, you wil know surface mount 100+ leg chips are absent from these designs.


Assuming I have read your garbled first sentence correctly, I said nothing of the sort. What I said was

"..... tralala... and that is where the memory goes........In my case the cosm library was the straw that broke the camel's back......I think it would be fair to say that, if you want to have a proper system sending  data the to internet, a Uno will not suffice. ...... "

By this, I would have thought was quite clear, I mean it is likely to have insufficient memory to do the job. I will stand corrected in the light of a proper demonstration to the contrary, but I have yet to hear of one and therefore rely on my own experience in the same arena. Both the experience and the arena are not so different from the OP's, hence my comment. I have read Retro's post, unsterstood it perfectly, and awarded it the applause it deserves. I don't see the slightest relevance in your blather about 100 leg chips, your definition of a standalone project is dubious, and none of this has anything to do with the issue at hand - memory.  As it happens, my 32K board has a soldered-in chip anyway. This has nothing to do with the reason for retiring it, but having a 42k project has quite a lot to do with it..

Nick_Pyner



The IDE isn't great


Getting into the Arduino IDE was traumatic enough so I don't think I will change in a hurry, but is the AVR Studio Retro mentions really a better way? Are there better freebie IDEs?


Retroplayer

#26
Feb 07, 2013, 04:50 pm Last Edit: Feb 07, 2013, 04:52 pm by Retroplayer Reason: 1



The IDE isn't great


Getting into the Arduino IDE was traumatic enough so I don't think I will change in a hurry, but is the AVR Studio Retro mentions really a better way? Are there better freebie IDEs?




A "better" way? That's subjective. Your code will likely be smaller, faster, and more efficient. But far more complex since you have to do everything yourself like setting up timers and registers, and such. If you use libraries over there, you run into the same issue anyway (though it will still likely be smaller code).


Arduino is great because it is simple and does a ton of work for you and hides all the really scary bits. But you sacrifice on code size. You are trading some things for another. In the end, you can actually just write the same code in the arduino IDE as you can in AVRStudio. Both are using avr-gcc as the compiler. You can access everything directly if you want.

Nick_Pyner


I have skimmed off a few K before just by changing the way I do things. Many people leave in Serial.begin for example when they aren't using the serial port in their final design. This adds in the entire serial library to the compiled code. By removing just that one line, you leave out a ton of code that you weren't using anyway.


By way of interest, how big is the ton? I am producing three three stations and the code is about 42k. I don't expect to do anything about the remote ones using Megas, but I could "change the way I do things" and just might be able to get the Uno back into service here at home. I could dispense with the serial altogether and read the card instead and I will change the display to a 4x20, which may reduce demand, as I believe its library is smaller and the relevant code will be a lot less. 

liudr

I apologize if you don't understand me Nick. I meant your remark on UNO being given the death sentence was wrong.
FYI,

Quote
The only advantage a Uno has is its size, and I imagine it will be squeezed from both ends and die a natural death - rather like the VIC-20.


A standalone project is a project that mostly uses the ATMEGA328 instead of the entire Arduino in the project with a custom built board. There is no official definition.

If you now can understand my point of the usefulness UNO and stand alone project, good for you.  I have seen you and me don't see eye to eye. Don't let all the negative attitude you have against me show to the public.




liudr

Nick,

Pretty sure "ton" in not a real code measurement unit. Retroplayer was just proving a point that many people can easily shed code and memory space by being a bit careful with what they don't use. To understand the "ton" qualitatively, Retroplayer gave a couple of examples. I would extend the example to include Serial.print(float) vs Serial.print(integer,integer);

If you output a float then you need the overloaded print(float) but if you make a simple integer(before decimal).integer(after decimal), you save a "ton".

You can also save half a "ton" by modifying the core to not instantiate the Serial or Serialx (MEGA) if you don't need them.

A "ton" can also be saved by using arrays, functions, understanding PROGMEM, f(), length of integer vs. that of char etc. Sometimes resorting to MEGA is an indulgence of one's own inability to cut wasteful spending in code mall. So I always give an extra push to someone "running out of space" to learn to optimize code before getting a MEGA, instead of a nudge in the MEGA direction regardless. Don't take this as me against you. I only take a stand on issues not who raised them. I do this even if the other side is Grumpy or Paul but seldomly find them to have anything I can nitpick about.

Go Up