Questions tagged [code-optimization]
The process of improving the efficiency of a program such that is uses less memory and/or less computational time.
132 questions
3
votes
2
answers
1k
views
I need compact code to fit in memory
I feel a little like I am back in 1975 trying to fit my code in 4K of RAM.
I am writing some code for an ATTiny88, and the code is starting to get big, relatively speaking. I need to save every byte ...
1
vote
1
answer
285
views
How to optimize checking for specific string in a UART stream
I want to check for specific string (like "RecordStart") in a UART stream (115 200 baud 8N1) from a camera, to know when it is recording or not/if there is an SD. I am using an ESP32-WROOM-...
-1
votes
3
answers
358
views
Is there any way to efficiently code reading of four sensors and sending a serial output once it does detect a reading?
I am actually wondering if there's a way to efficiently do this block of code. There are two things in my specifications and these are:
Four IR Sensors that detects blockage. Basically just to ...
7
votes
4
answers
1k
views
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 ...
-2
votes
1
answer
697
views
How do I create a code that lets me use an array of 10 thermistors on one arduino?
I am new to programming and am trying to create an array of 10 thermistors on one arduino. So far I have found a code for Temperature Sensor Using NTC Thermistor that is only for one thermistor. How ...
1
vote
0
answers
93
views
How do I optimize this IRremote code?
I am using a ATTINY85 Digispark board with an IR receiver to light some LEDs in my project. The Digispark has a limitation that does not allow it to use the IRremote.h library. I know that there a ...
1
vote
0
answers
69
views
Can a Windows 10 computer use Arduino IDE 1.8.10 sometimes AND use Arduino IDE 2.0.0 the rest of the time?
Can Windows 10 computer use Arduino IDE 1.8.10 sometimes, AND use Arduino IDE 2.0.0 the rest of the time?
1
vote
1
answer
404
views
send and recieve analog data from one arduino to another arduino via web/ethernet
i am able to send audio signal through mic and send it via arduino and receive it on speaker.
i need two things
1.) The voice i am hearing on speaker has on speaker has lots of noise with it. i need ...
1
vote
3
answers
2k
views
Generate a true analog signal using Arduino
I am looking for a way to create a true analog output with the arduino uno. I am constantly reading an analog input on a0 pin, all i want to do is send the same signal as output. I know arduino ...
2
votes
0
answers
88
views
Am I maximising my A0 readout rate with this peak-detection code?
I have a pulse going into A0 on a Nano, and want to detect the peak voltage. With low-pass filtering to slow down the input pulse I'm still reading marginally too slow.
The code overall inhibits a ...
0
votes
3
answers
119
views
I have made a Nano send 4 pot values to an Uno please help with code
Happy New Year!
So I have made a Nano send 4 pot values to an Arduino Uno over serial but I have a problem: I don't know how to separate these values. Here's the code:
Master:
int Pot = A0;
...
4
votes
2
answers
2k
views
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 <= ...
-1
votes
1
answer
254
views
Port manipulation
My UNO having some stability issues because of heavy memory use, I'm now optimizing the code
now looking to reduce the digital read memory use with the help of port manipulation. I got the code for ...
1
vote
0
answers
75
views
Automatic water pump Trigger System - I need my code FIXED
int out = LED_BUILTIN;
int strt = 3;
int stp = 9;
void setup() {
pinMode(out,OUTPUT);
pinMode(strt,INPUT);
pinMode(stp,INPUT);
}
void loop() {
while(true) {
if(digitalRead(strt) == LOW) ...
1
vote
0
answers
1k
views
Reduce time between two consecutive SPI transfers on ESP32
I'm trying to drive an external DAC via SPI interface using ESP32 chip. But I cannot achieve the desired speed (>1M transfers/sec, each transfer consists of 16bits). The reason is not the SPI speed ...
8
votes
4
answers
4k
views
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 ...
2
votes
1
answer
104
views
Thermocouple and multimeter
I've put together this script that should allow my Arduino Mega to be show thermocouple readings on the serial monitor, whilst also showing readings of voltage and ohms across a given component. I'd ...
1
vote
0
answers
118
views
Dragino Lora shield for Arduino sensor use
I am new to arduino and lora technology and i have dragino lorashield for arduino Uno and dragino gateway. I have also MQ-3 gas sensor and I want to detect the alcohol value and to send it to the ...
-1
votes
2
answers
59
views
multiple invdividual servo controll arduino
I want to declare 11 servo motors in my code. Is there a better way to do that than just declare everyone under each other. The reason is that i have a code that will set the rotation for one at a ...
-1
votes
1
answer
144
views
Refactoring bad design?
Could someone help me how to refactor old very complex code ?
Original used just setup and everything else was in single ISR.
But as it was bigger and bigger, code is quite slow and quite random ...
-1
votes
1
answer
976
views
Optimizing for speed using const, static, constexpr etc in a function
In an ISR I want to keep things quick. At the same time I want to limit variable scope. Storage space is not a factor.
I have this line:
const char trigs[] = "aAbBcCdDeEfFgGhHiIjJ";
When this is ...
0
votes
2
answers
297
views
28 BYJ stepper motor runs faster using delay() and little slower using millis(), why?
I'm working to develop a code for the stepper motor to use it in a project. And since using delay() isn't as efficient as millis(). So I first developed the code that use delay with 1ms delay between ...
1
vote
0
answers
434
views
FIltering, FXOS8700, FXAS21002C optimization
I'm working on an inverse pendulum project, and am using an adafruit NXP_FXOS8700_FXAS21002 along with an Arduino due, and an esp8266 (two separate projects, same code however). I'm using a Magdwick ...
1
vote
0
answers
380
views
Why does the program size increase so drastically with these switch-cases?
EDIT: The problem is my op-code catch is op >= 0x20 || op <= 0x2F rather than op >= 0x20 && op <= 0x2F and so most of the switch-case was being optimised away!
This is a really ...
2
votes
2
answers
3k
views
Best practice to declare a 'static' text and save memory
I'm working on a project where I need to create a JSON to send back state of an object. I created the code to achieve it and all works fine, but I used this to declare the JSON fields:
static const ...