Questions tagged [code-optimization]

The process of improving the efficiency of a program such that is uses less memory and/or less computational time.

Filter by
Sorted by
Tagged with
0
votes
1answer
25 views

FIXING BUG when Using Wire library to obtain compass heading

I am using the HMC-5983 magnetometer module to obtain the compass heading of a autonomous car I am building using the arduino platform.I'musing the Z axis and X axis to obtain the heading. However ...
0
votes
2answers
23 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 ...
0
votes
1answer
53 views

Modular Coding - What types of code portions to convert into library files? Rationale and methods?

I'm working on documentation and combining 2 pieces of code for testing parts of a larger project. I'm supposed to comment and make the code very clear to people who will use it later and make sure ...
-1
votes
1answer
71 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 ...
0
votes
1answer
66 views

Using Serial.write() to send a uint32_t send one byte x4 or send 4 bytes x1

In the IRremote library, IR signals are decoded and held in results.value. My project uses the NEC protocol which is 32 bits, so the IR code will always be 4 bytes. uint32_t dCodedIR; // // code ...
-1
votes
1answer
121 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
0answers
125 views

Optimizing Teensy 3.6 for data sampling?

So, I have a very basic project where I cycle through 8 IR individual transmitters. After setting the individual transmitter high, I cycle through all 8 IR receivers and print their values, RX_CYCLES ...
0
votes
2answers
104 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 ...
0
votes
0answers
42 views

Combining sketches

I have two codes for my to sensors and they work separately. However, I need to combine them in one program please can you help? The pulse code /* PulseSensor Starter Project and Signal Tester * ...
1
vote
0answers
123 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 ...
0
votes
3answers
100 views

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

N00b question, Is there a better way for readability / elegance / DRY etc to check various sensor values for high/low record value? This code works, but looks like the long way round. void ...
1
vote
0answers
87 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 ...
-1
votes
1answer
202 views

how to code LED turning signals on smart car [closed]

this question is regarding how to add turn led signals on arduino powered smart car. I have 4 leds to give turn indications on my smart car(line follower, obstacle avoider, Bluetooth mobile controlled ...
1
vote
2answers
632 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 ...
0
votes
2answers
53 views

Merging of two functions

This is my Arduino code that checks the water Level of two different water reservoirs via 2 water Level Sensors A and B: #define Water_Level_A 5; #define Water_Level_B 6; boolean Water_Level_Check_A(...
-1
votes
1answer
139 views

Need help optimizing snake game code for Arduino Nano

Here's the code: https://pastebin.com/ypWe4NZw This is the output when I compile: Sketch uses 13086 bytes (42%) of program storage space. Maximum is 30720 bytes. Global variables use 1456 bytes (71%...
1
vote
0answers
1k views

Sending data from webserver to Arduino

Hello Arduino enthusiasts! I've been working on a keypad lock system for school lately and I need some advice.Basically, my code checks if the entered passcode is the same than a predefined passcode ...
0
votes
3answers
405 views

Switch case does not work after booting system

int value1; int value2; int runs1 = 0; int runs2 = 0; #include <Wire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x3F, 16, 2); int inPin = 6; int val = 0; int push_count = 0; ...
2
votes
3answers
131 views

Conditional randomization gets stuck

First-time poster here... I have the following code to randomize note values and store them in an array loop1[i], where i is a specific step in the loop: nextNote = random(-2, 3); note = note + ...
1
vote
1answer
100 views

LED Programme where it delays the amount written in the Serial Monitor

I have written a simple code to delay the blinking of LED 13, the delay time is set by us.I have incurred a problem when I enter a 2 digit value in the serial monitor.There is some problem with the ...
7
votes
2answers
542 views

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 ...
2
votes
3answers
602 views

Reducing Memory Usage lots of Floats

Im using an Arduino Uno - All code at github.com/robbrad/AirQuality Current sketch usage: Sketch uses 23186 bytes (71%) of program storage space. Maximum is 32256 bytes. Global variables use 1428 ...
-2
votes
2answers
3k views

Counting number of people inside a room [closed]

I want to count the number of people in a room using a microcontroller (Arduino Uno). I have 2 ultrasonic sensors at a doorway about a 1.5m apart from each other. I want to increment the number when ...
1
vote
2answers
1k views

Const data optimisation for Arduino

I'm taking a course on Arduino Uno programming and on today's talk I heard that the const data is optimized by Arduino, so that it occupies less space than the actual data type (namely, a const int ...
1
vote
4answers
123 views

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

Could I realistically be expecting some 25% - 50% code size reduction if I abandoned Arduino IDE's framework and moved to something more rudimentary such as AVR Studio ? I am using the EEPROM, Timer1 ...
0
votes
3answers
233 views

Breaking up for loop with ISR

I am curious if the following scenario is possible. EICRB |= (0<<ISC60)|(0<<ISC61); EIMSK |= (1<<INT6); ISR(INT6_vect) { myISR(); } void myISR() { digitalWrite(led_off, ...
0
votes
2answers
3k views

Controlling the Serial Monitor for 10 seconds

I am an amateur with Arduino and coding and I am learning in my lab class. My project consists of using a photoresistor to measure the brightness of a white LED. I have the following circuit built. ...
1
vote
1answer
1k views

Super-fast USB communication; how is it possible?

On Arduino forums, there's a post where someone improved the USB communication and made it super-fast. I don't understand how he did this, and I'm trying to recreate this, but failing. My test code ...
1
vote
1answer
2k views

Optimizing Arduino File Selection from SD card

the following code will display the files on an SD card in an Arduino and allow the user to open a file of their choosing. Here's the code with a walkthrough of what it does. In the Init state, I ...
0
votes
2answers
348 views

Correct use of interrupt vs monitoring switch

Background: I have a uni assignment which requires an autonomous robot to do a number of tasks and then finish in a set spot after being triggered to start by an outside physical interaction. I've ...
12
votes
5answers
4k views

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 ...
2
votes
1answer
492 views

Error in IR receiver project

I'm trying to receive remote information with an IR receiver and this is my code: #include <IRremote.h> int RECV_PIN = 11; IRrecv irrecv(RECV_PIN); decode_results results; void setup() { ...
-3
votes
1answer
55 views

Create an a message from two inputs[Programming Help] [closed]

I'm a bit new to this and I have the following function that I'm having trouble getting it to compile. The intent is to create a message to write out to a software serial port. Inputs are two int ...
1
vote
1answer
59 views

Array Addressing

Is it possible to use a name instead of a number to address an array? I was reading about enum lists and thought it might be possible. ie int array[3] = {something, somethingElse, somethingMore] ...
0
votes
1answer
398 views

Switch Statement Alternative

I am working on a project where I've mapped an IR remote control to certain functions. I am currently using a massive switch statement to control the program based on the IR remote button pressed. Is ...
2
votes
1answer
188 views

Is setting clock divider worth changing on delay() to save power?

Along all the "advanced" methods described in this article, does simple method as downscaling processor while delay makes a difference on power consumption? How much time does the clock alternation ...
0
votes
2answers
385 views

code optimazation 6x6 Matrix

I planed a 6x6 matrix with a Arduino Nano as controller. Its only possible to let one LED in the matrix lighten up. Any idea how I get the Code smaller? (Im a C Noobie ^^) ~Nico Circuit diagram: ...
1
vote
2answers
1k views

Low Power Library 4 seconds ON, 10 minutes OFF

Could someone please demonstrate how to use a counter with the Arduino 'low power' library to wait for 10 minutes then digitalWrite 4000, HIGH and loop. (I don't mean the simple 'blink' sketch). I'm ...
0
votes
3answers
2k views

Arduino Blink two LEDs without Delay(amount of repetitions)

Arduino community. I have had experience with Arduino for 3 years now and have finally come to the conclusion to get rid of the delay function entirely. Below is the code to blink two LEDs a ...
0
votes
2answers
332 views

Is this example for playing music without delay correct?

I've followed the directions from this answer, to try and play music without delay. This is my code so far: #include "pitches.h" int melody[] = { NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, ...
1
vote
1answer
496 views

Optimization Teensy 3.6 Arduino IDE fast I/O Multiplexing Led Matirx

I'm currently working on a 10x10 LED Matrix which is controlled by 5 Shift registers using multiplexing. I've the problem that the Teensy 3.6 is too fast/slow. One part of my code is the Shiftout ...
7
votes
3answers
1k views

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 ...
0
votes
1answer
967 views

Multiple if statements - stuck

I have a robot that uses two motors to skid steer. The robot gets input from three ultrasonic sensors (left, middle, and right) and a passive infrared sensor. If the robot detects a person in front of ...
-1
votes
1answer
770 views

Why is integer-to-string not working in this sketch?

I am using a Pro Mini to read analog values and to send them via serial. Goal of the sketch is to stream these values to Serial as fast as possible, to obtain a steady stream of at least 1000 ...
0
votes
1answer
92 views

Arduino Mega prototype analog timer interrupts: newbie question

I am currently using an Arduino Mega with a fast vibration sensor to trigger the components operation (force sensor, temperature sensor) and also toggle sleep mode. I am very new at this and I have ...
0
votes
3answers
56 views

Merging strings and constants causing scope errors

I'm getting a few errors when merging strings with constants. Here's the pertinent code... #define STATION_ID ABC123 #define STATION_PASS XYZ987 void loop(){ String path = "/weatherstation/...
2
votes
0answers
431 views

Faster output of Serial.print() data coming from TSL1402R sensor [closed]

I am reading a TSL1402R with an Arduino Mega2560. The code is based on the sketch from the arduino playground here:http://playground.arduino.cc/Main/TSL1402R The application is a digital caliper for ...
3
votes
1answer
74 views

Read time digits from DS1307 and run code based on return

I am currently reading a DS1307 adafruit breakout board and I need to drive two nixie tubes from a shift register. The shift register is running two 74141 IC chips. I have code that loops through all ...
2
votes
1answer
376 views

PCF8547 Wire.write explanations

I am using an ESP8266-12E with a PCF8547. I have managed to turn on and turn off LEDs using these two things. I am using these three commands to do it. Wire.begin(SDA_PIN,CLK_PIN); Wire....
2
votes
1answer
332 views

Sim800L's library can not compile on Arduino Due

Sim800L's library can not compile on Arduino Due. Is there any way to create a library for Arduino Due? #include <Sim800l.h> #include <SoftwareSerial.h> Sim800l Sim800l; char* text; char*...