Skip to main content
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
  • 106k
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
  • 44.8k
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
  • 44.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

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,503
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
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
  • 106k
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,795
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 bytes ...
Nick Gammon's user avatar
  • 38.8k
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 flash ...
Ignacio Vazquez-Abrams's user avatar
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
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,979
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
  • 44.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
  • 261
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

code optimazation 6x6 Matrix

You can use arrays to hold sets of row pin numbers or column pin numbers, which then allows use of for loops for pinMode() settings and for testing LEDs one after another, as shown in code below. ...
James Waldby - jwpat7's user avatar
3 votes
Accepted

Array Addressing

No, but you can use a struct: struct flags { uint8_t power; uint8_t jump3; uint8_t jump7; .... etc .... }; struct flags myFlags; myFlags.power = 1; if (myFlags.jump3) { .... ...
Majenko's user avatar
  • 106k
3 votes

How to increase life of EEPROM?

If your data occupies only a small fraction of your EEPROM, you could use one of the wear leveling algorithms. The essence of these algorithms is to write to a different location each time, so writes ...
Dmitry Grigoryev's user avatar
3 votes

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

Probably not ... The Atmel chip might get warmer over time (even a delay does not prevent this), however if it has a possibility to release its heat I don't see a problem. But mostly only overclocking ...
Michel Keijzers's user avatar
3 votes
Accepted

Need help optimizing snake game code for Arduino Nano

16x16 = 256 So there are 256 possible places to put a piece of snake. The max length of the snake will be 256 (fill the board completely). So if we take an array of bytes (0-255) that is 256 bytes ...
aaa's user avatar
  • 2,715
3 votes

Merging of two functions

Functions like boolean Water_Level_Check_A(){ boolean Result = digitalRead(Water_Level_A); return Result; } Are really overcomplicated. You're just calling one function and returning that ...
Maximilian Gerhardt's user avatar
3 votes

Best practice to declare a 'static' text and save memory

The "traditional" way is to use PROGMEM and use const char * strings. I don't use the "traditional" way. Instead I use some "helper" classes and macros that WString.h provides. This does mean, ...
Majenko's user avatar
  • 106k
3 votes
Accepted

FIXING BUG when Using Wire library to obtain compass heading

The problem comes from the low-pass filter you are using: // Smoothing the output angle / Low pass filter headingFiltered = headingFiltered*0.85 + headingDegrees*0.15; This filter is designed to ...
Edgar Bonet's user avatar
  • 44.8k
3 votes

I have made a Nano send 4 pot values to an Uno please help with code

If your goal is to "talk" to a computer vs. a human, then a format that can be parsed easily is better than one that is easy to read. For example, you have: I received: 255 I received: 247 I ...
jwh20's user avatar
  • 1,045
3 votes

How do I create a code that lets me use an array of 10 thermistors on one arduino?

You haven't said which (of the many kinds) of "Arduino" you plan to use, but Uno being the most common, I'll assume that. You also haven't said why/whether you must use a particular ...
JRobert's user avatar
  • 15.4k
3 votes

Optimizing code for ATtiny10

Are you sure the pins are correct? Maybe use a smaller random number generator per https://arduino.stackexchange.com/a/18092/6628 ? static uint8_t lfsr = 0x01; const byte LFSR_MASK = 0x8e; void setup(...
Dave X's user avatar
  • 2,340
3 votes

Is there any way to efficiently code reading of four sensors and sending a serial output once it does detect a reading?

There are always other ways to code something (at least if it's non-trivial). What does 'efficiency' mean to you, in this case? If speed is a concern, increase the baud rate. Whenever at least one ...
JRobert's user avatar
  • 15.4k

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