20 votes
Accepted

Does an Arduino get worn out by too much command execution?

No, the code doesn't "wear out" the MCU. In general no matter what you are doing roughly the same level of activity is being performed. Even delay() does lots of work while it's "idling". There are ...
Majenko's user avatar
  • 105k
18 votes
Accepted

What are the traditional ways to optimize program memory usage?

What are the generally practiced methods for the optimization program memory usage? First, note you are searching for ways to lower SRAM memory. This contains global (variable) memory and heap space (...
Michel Keijzers's user avatar
12 votes

Optimizing code for ATtiny10

As I stated in a comment, this device would be too small for me to consider programming it using an Arduino core. I would rather stick with the avr-libc and direct port manipulation: #include <...
Edgar Bonet's user avatar
  • 42.8k
10 votes
Accepted

OOP vs procedural programming on arduino

Your assumption is quite wrong: The majority of libraries use OOP. The majority of in-built device drivers use OOP. The core is filled with many OOP helper objects and classes. 99.99% of all ...
Majenko's user avatar
  • 105k
7 votes

How to increase life of EEPROM?

The other answer mentioned some general ideas; here are a couple of more-specific notes. • You can direct your writes of single bytes through a routine that reads the EEPROM cell before writing to it,...
James Waldby - jwpat7's user avatar
7 votes

What are the traditional ways to optimize program memory usage?

I just want to add a single bullet to Michel Keijzers’ excellent answer: think about every single item you are storing in memory and ask yourself the question: do I really need to keep this in RAM? ...
Edgar Bonet's user avatar
  • 42.8k
7 votes

Optimizing code for ATtiny10

If the button is pressed by a human and your clock is high enough (MHz range), you can use a trick and get rid of the RNG. You can replace it with a free running counter like this: unsigned char count ...
Redy000's user avatar
  • 171
6 votes
Accepted

Storing an array of function pointers

This all gets very much trickier than just an array of function pointers. Your functions are methods in unknown objects. As such you can't have one single type that stores pointers to the functions ...
Majenko's user avatar
  • 105k
6 votes

Does an Arduino get worn out by too much command execution?

It's not. Well, it might slowly wear out if you run it like 20 years....(like most other physical products)? At least it does not rely on code complexity but how many writing operation done in the ...
Bumsik Kim's user avatar
6 votes

Does an Arduino get worn out by too much command execution?

For a hobbyist: About the only life limiting software related issue might be writing to the FLASH memory as fast as you can from inside a program. But few programs make use of variables that need to ...
st2000's user avatar
  • 7,325
6 votes
Accepted

Does the compiled binary of a sketch include uncalled functions from a library?

In general only the functions actually used by your code are included in the final linkage of the binary. However it's not always possible for the compiler to know what is used and what isn't. In the ...
Majenko's user avatar
  • 105k
6 votes

How to move a servo quickly and without delay function

The quickest way possible from LightON to LightOFF is simply servo1.write(lightOFF); without loops or delays, in one go; no need to do it degree by degree. For example: int lightON = 180; int lightOFF ...
ocrdu's user avatar
  • 1,775
5 votes

Storing an array of function pointers

This is not a direct answer to your question, as I have no such answer, and I believe the answer you are seeking would be of no use to you. The problem with your question is that your method of ...
Edgar Bonet's user avatar
  • 42.8k
5 votes
Accepted

How to increase life of EEPROM?

I can think of a few: don't power it on unless you have to; don't write to it unless you have to; write as little data to you as you can - compress the data; only write to it during brown out or ...
dannyf's user avatar
  • 2,770
5 votes

Does an Arduino get worn out by too much command execution?

... (or generally any other micro-controller) ... The other answers are great, but there is one small exception. Ferroelectric RAM (FRAM) is a form of memory that combines the non-volatility of ...
Ignacio Vazquez-Abrams's user avatar
5 votes
Accepted

Porting code from Arduino IDE to other IDEs - expected code size reduction

You don't need to abandon the Arduino IDE. Let me quote from my forum post about sketch sizes. Introduction Every now and again this subject pops up on the Arduino forum. Why does it take 1000 ...
Nick Gammon's user avatar
  • 38.1k
5 votes
Accepted

Storage usage of methods compared to copied code

It.... depends A call to function involves a few things Save the context Move the parameter(s) to the appropriate registers Enter the function Execute Eventually save the return value to a register ...
frarugi87's user avatar
  • 2,721
4 votes

Storing an array of function pointers

I'm not sure if it will not blow your memory limit as every pointer takes up 16 bits. But in C you usually do it this way: void func1() { puts("Hello"); } void func2() { puts("World!"); } ...
Kwasmich's user avatar
  • 1,513
4 votes
Accepted

Set EEPROM from PC before program

The simplest way would be to have two sketches. One that will store all the strings into EEPROM. After that you can upload the second actual sketch that uses the values stored in EEPROM. You ...
Gerben's user avatar
  • 11.3k
4 votes
Accepted

Is it possible to pass HIGH and LOW values as parameter in a function?

digitalWrite expects the pin and value to be uint8_t type. So you can certainly pass LOW or HIGH to functions. For example: void runMotor(int _dir, int _step, int wait, uint8_t value){ ...
Nick Gammon's user avatar
  • 38.1k
4 votes
Accepted

Const data optimisation for Arduino

This question is not really about the Arduino. It is about GNU C/C++ compiler optimizations. By adding the keyword const the compiler can do a lot of optimization. One is that the value does not ...
Mikael Patel's user avatar
  • 7,969
4 votes

Is there a more elegant way to check highest / lowest sample data?

This is a variation on the struct idea with an object-oriented flavor. If you put the current, low and high values of any sensor inside a struct, you could also morph this struct into a class and ...
Edgar Bonet's user avatar
  • 42.8k
4 votes

What are the traditional ways to optimize program memory usage?

What are the generally practiced methods for the optimization program memory usage? (nb. as per Edgar's comment I emphasise that this is about using PROGMEM more efficiently.) If you can replace ...
Artelius's user avatar
  • 251
4 votes

Generate a true analog signal using Arduino

I see that MCP4725 uses Wire library with the default clock of 100,000 kb/sec. At a rough estimation each call to MCP.writeDAC or MCP.getValue will be at least 32 bits long and you use three of them ...
Dorian's user avatar
  • 359
4 votes
Accepted

How to cut down size of imported DigiKeyboard library

With input from @EdgarBonet, I looked into the functions used and it turned out that the String() function, I used once in my code, takes up about 3kB of space in the compiled program. I ended up ...
emma.makes's user avatar
3 votes
Accepted

Faster and lighter approximate timing code without using timer

Personally I wouldn't be putting too much effort into optimizing away your timers. millis() is pretty fast - the work needed to calculate the result is done in the background anyway (by interrupts). I ...
Nick Gammon's user avatar
  • 38.1k
3 votes

Set EEPROM from PC before program

I think here is a confusion about the three types of memory. EEPROM, FLASH and SRAM are completely separate. EEPROM is like your file storage. FLASH contains you program and static values. SRAM is the ...
Kwasmich's user avatar
  • 1,513
3 votes
Accepted

What is the proper way to implement PID?

Each unique variable you want control over should have a single pid loop, and each loop should only ever stretch across one "order" of time. For example, to control the craft's roll rate, you should ...
BrettAM's user avatar
  • 4,431
3 votes

Problem with inaccurate delays between sensor readings

The problem is that you are using delay(). delay() will wait, from the moment delay() is called, for the given number of milliseconds. That is, in more structured terms: Do something Do something ...
Majenko's user avatar
  • 105k

Only top scored, non community-wiki answers of a minimum length are eligible