The process of improving the efficiency of a program such that is uses less memory and/or less computational time.
Questions tagged [code-optimization]
132 questions
19
votes
5 answers
How can I declare an array of variable size (Globally)
I'd like to make three arrays of the same length. According to the documentation, Arrays must be defined as int myArray[10]; where 10 can be substituted for a known length (another integer), or filled with an array {2, 3, 5, 6, 7}.
However, when I…
user3.1415927
- 293
- 1
- 2
- 5
12
votes
5 answers
Does an Arduino get worn out by too much command execution?
Excuse me if it is a silly question, but I couldn't find an answer.
I've been wondering for a while whether an Arduino (or generally any other micro-controller) gets happy if the code is light and it does not have to execute too much operations.…
ahmadx87
- 549
- 2
- 9
- 16
9
votes
1 answer
Overview of compiled code size
When I compile my code, the Arduino IDE returns the binary sketch size in byte.
Is there a good way to find out (approximately) what function or what part of my code takes up how much memory in flash, so that I get a feeling what feature takes most…
fuenfundachtzig
- 1,535
- 1
- 14
- 26
8
votes
4 answers
What are the traditional ways to optimize program memory usage?
While doing big projects using Arduino boards (Uno, Atmega328P MCU). I used to get warnings like this
Sketch uses 13764 bytes (44%) of program storage space. Maximum is 30720 bytes.
Global variables use 1681 bytes (82%) of dynamic memory, leaving…
Mayoogh Girish
- 205
- 2
- 7
7
votes
4 answers
What's the most efficient implementation of map(x,0,1023,50,250)?
I recently noticed how the map() function in Arduino was bulky in both terms of flash space used and time taken to execute, largely because it deals with long and involves a division and multiplication.
Many times you can replace maps with more…
Cybergibbons
- 5,420
- 7
- 34
- 51
7
votes
4 answers
Optimizing code for ATtiny10
I'm trying to squeeze code onto an ATtiny10, but I'm just not getting there. I'm using 1060 bytes and only have space for 1024 bytes.
The code is simple enough; I need to read a button pin. If high it needs to pick a random value and that causes one…
Earthbound Ruben
- 111
- 4
7
votes
2 answers
Storage usage of methods compared to copied code
When you have really small snippets of code that are repeated several times in your micro controller program, is it better to write a method? I mean better in terms of performance and storage usage. I know that when programming for PC, code…
Lehue
- 193
- 1
- 6
7
votes
4 answers
How to increase life of EEPROM?
I want to store a few (8 as of now) IR codes into my Board's EEPROM.
It would be great if someone could suggest a few tips to maximize the lifetime.
The IR codes in my sketch are saved in array of unsigned longs.
I know that the count of times that…
karx
- 235
- 3
- 9
6
votes
2 answers
What is the proper way to implement PID?
I'm having some trouble conceptualizing how to go about implementing PID into my drone. There are a few ways I'm thinking about implementing the pipeline:
Having one PID Object for each of the six motors.
Having one PID Object for each axis.
How I…
tuskiomi
- 205
- 1
- 11
5
votes
1 answer
How to enable maximum Dead Code Removal?
I am running out of code and data memory space on ATMega328P.
Code size is big as I used several libraries, but, I only use a few functions of those library.
Apparently, the default IDE is only doing a partial job in dead code removal (remove…
EEd
- 904
- 1
- 14
- 21
5
votes
3 answers
Set EEPROM from PC before program
I have been working on an arduino program, which has gotten rather large. I am close to hitting the 32k limit on Flash for my ATmega328p. I would like lower my program size by saving some of my many string literals into EEPROM.
All of the example…
riverrun
- 85
- 1
- 4
4
votes
2 answers
How to cut down size of imported DigiKeyboard library
I'm working on a project with a Digispark ATTiny85, that performs keystrokes using the DigisparkKeyboard library (https://github.com/digistump/DigisparkArduinoIntegration/tree/master/libraries/DigisparkKeyboard). Besides the DigiKeyboard, I also…
emma.makes
- 105
- 6
4
votes
2 answers
How to move a servo quickly and without delay function
Im trying to move a servo from one place to another while using the typical for loop you find in the servo's library example:
int lightON = 180;
int lightOFF = 90;
for (pos1 = lightOFF; pos1 <= lightON; pos1 += 1) {
servo1.write(pos1);
…
Marcelo_M
- 121
- 1
- 7
4
votes
1 answer
Does the compiled binary of a sketch include uncalled functions from a library?
I am writing a GUI using a TFT display and the Adafruit GFX library and its default font on Arduino Nano.
I want to be memory efficient and I assumed that the 'optimise for size' default setting of the compiler would not compile and include all…
WildCat
- 323
- 3
- 11
4
votes
2 answers
Problem with inaccurate delays between sensor readings
During the last two months I have been working on a project that consists of using a Seeeduino Stalker V2.3, two AM2305 sensors, a TSL2561 sensor, an HC-05 XBee module, a 1,800 mAh 3.7V LiPo, a 7 cm x 7 cm 5V solar cell, and a waterproof suction…
OpenAGRO
- 41
- 2