How to know if a Arduino has enough memory for a project

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.

Retroplayer:
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......

Yep. Just tested it:

For a blank sketch:

void setup(){

}

void loop(){
  
}

It compiles to 466 bytes.

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

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.

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

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

Compiles to 2K. While:

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

Retroplayer:
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.

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.

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..

PeterH:
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?

Nick_Pyner:

PeterH:
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.

Retroplayer:
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.

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

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.

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.

Retroplayer:
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.

I think you need to be clear whether you're referring to the Arduino IDE or the Arduino runtime libraries.

There are various things about the IDE that really irritate me. But it's good enough to get the job done.

There are other IDEs that you can use to write sketches and these can make use of the identical Arduino runtime libraries and the hardware abstraction that these libraries provide. Or you could write the source in any text editor and build the image manually - you don't have to use an IDE.

It's also possible, as you suggest, you avoid the Arduino runtime libraries completely and write your own code that interfaces directly with the hardware. For people already familiar with working in this environment, that would be a reasonable solution. But the Arduino runtime library does take away a lot of the pain and complexity of dealing with the hardware and if you aren't certain whether you need it then I'd suggest the answer is that you do. But you can use the Arduino runtime library without using the Arduino IDE, if you want.

Possible alternative IDEs are the AVR IDE, Eclipse and Visual Studio. No doubt there are others too. If you're already familiar with any of them, you might want to search for explanations of how to use these to build Arduino sketches.

PeterH:
Or you could write the source in any text editor and build the image manually - you don't have to use an IDE.

Yep. In fact, I typically write my sketches using ultrastudio because I enjoy the function list feature and the code-folding. It also has autocompletion, but I am finding that more of a pain than help.

Does anyone know if you set up visual studio for the arduino, does it include code completion similar to what you get with visual basic and the like? I liked that it listed all the methods of the objects for me. Something to help keep track of variables and their scope would also be nice. Typos, forgetting how a function is called, or forgetting whether I used a capital or not in my variables is my biggest source of frustration.

Retroplayer:
Obviously you aren't going to save 1.75K by removing it because many of the same support libraries are used by other functions

I had completely missed your reply #22 when I was asking about the ton. I guess the above explains why, when you develop a project with various libraries, the increase in memory required can be deceptively gradual. You can't tell what is really going on because a new facility you add might be demanding resources that are already in place. Then you get one that doesn't have the resources in place, and it all hits the fan........

Not that I said anything truly profound or magical, but it is stuff like this that should really be put up somewhere with tips, tricks, and gotchas. With the arduino, it is so easy to use libraries. I try really really hard not to unless I understand completely how they work just to keep my code from getting bloated. Even when I am well under the 32K and 2K marks, I still loathe the idea of wasting space. I guess that comes from the Commodore 64 days.

Retroplayer:
Not that I said anything truly profound or magical, but it is stuff like this that should really be put up somewhere with tips, tricks, and gotchas. With the arduino, it is so easy to use libraries. I try really really hard not to unless I understand completely how they work just to keep my code from getting bloated. Even when I am well under the 32K and 2K marks, I still loathe the idea of wasting space. I guess that comes from the Commodore 64 days.

I once was scr**d by a library a particular popular DIY store published for OLED. There are so many commands that don't work and they don't even have specsheet. They put the displays on the market with that library anyway. It bothers me if I can't even use lcd.clear(). I tend to look inside library code just to see how neatly the code is written. That tells you the quality of the library. Coming from x86 back ground, I'd argue the same thing about wasteful behavior of then c compilers. If I write an assembly source program that stores as 2K on a floppy, the compiled and linked executable is always less than 2K. I have many comments but still was amazed how some programs are megabytes large.