Questions tagged [c++]

C++ is the standard language used to program the Arduino IDE. However, the Arduino IDE does have lots of libraries built in, so functions such as "main" are not called directly in the sketch code. Most Arduino code online is written in this language.

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

Value keeps incrementing even though loop has terminated, why?

I use a double called delta and use that to turn off an LCD if delta is larger than the timeout threshold. Once that happens, delta is supposed to set to 0 and then other parts of the program run. ...
1
vote
0answers
19 views

Can't send Twilio SMS using Nodemcu esp8266

I am using Twilio for sending SMS in my project. I am measuring temperatures and if the temperature is too high, an SMS is sent. In my code I also have a read and a push to Firebase Realtime Database. ...
1
vote
1answer
27 views

cant read json data esp 32 “parseObject() failed”

hello I am just trying to make Youtube Subscribe Counter with led matrix 32*8 and esp 32 and I had this problem when I trying to get subscribers to count so what is the problem and how I can fix it? `...
1
vote
1answer
32 views

L293D motor shield

I have the L293D motor shield on top of my Arduino UNO. The L293D has a servo attached of 5 volt and a motor of 12 volt there is an external power supply. If I remove the jumper of the board and power ...
1
vote
1answer
230 views

How do i improve this Code? (or how to pass a Char String into a Function to behave like a Variable)

Sorry i am a beginner and amateur when it comes to coding, can somebody help me to make the code inside the loop() less "monkey-like" by using a proper function? I have tried a lot and at ...
1
vote
0answers
40 views

unexpected output

I wrote some arduino code but since I don't have access to an arduino, ran it on a tinkercad circuit, the code is supposed to set all the buttons values to 1 and all the password values to 0 and the ...
0
votes
1answer
40 views

How do I use lambda functions in Arduino?

I want to pass a lambda function as an argument to a method. Example: T reduce(const T initial, const std::function<T(T, T)> acc) { T value = initial; for (size_t i = 0; i < S; ++i) { ...
4
votes
1answer
158 views

why is “if” slow?

I am new to the Arduino world and I hope I can find a solution here. The code below functionally works ok. The problem I have is, at line 45 I've inserted an if statement to change dac_value. It is ...
0
votes
1answer
37 views

Arduino + Codeblocks C++

I'm writing the code for my Arduino board using Code::Blocks editor. When I create a new project, there is AVR Project and Arduino Project under Projects category. Which one do I select?
0
votes
1answer
39 views

I get an error saying, “exit status 1 expected initializer before 'void'.”

I will be wiring a switch to the Arduino that controls the voltage. When the I turn the switch it can adjust the voltage from 0 to 5. The overall task is to print the output voltage. The print is to ...
1
vote
1answer
72 views

Cannot successfully implement singleton

I have spent the better part of today trying to figure out why I can't get this to work... I have this project where, because of previous design considerations, have implemented a singleton class that ...
0
votes
0answers
60 views

Send only one packet from one ESP32 to another ESP32 without acknowledgment

I have a network consisting 10 slaves and one master. I am using ESP-NOW to send the messages between the nodes. All of the nodes are within close proximity. I do NOT need a mesh network to reach all ...
3
votes
1answer
279 views

What is the logic behind Arduino inlining `HardwareSerial::_rx_complete_irq()` for receiving serial data (but NOT `_tx_udr_empty_irq()`)?

Q: What is the logic behind Arduino inlining HardwareSerial::_rx_complete_irq() for receiving serial data (but NOT _tx_udr_empty_irq()), and when is it advisable? From the bottom of the HardwareSerial ...
1
vote
2answers
104 views

Counter program

I'm an absolute beginner, and lately I had some problem with this program I was trying to do. Basically I wanted with the Arduino to count 3 pulses from an oscillator and store the time of these 3 ...
0
votes
3answers
57 views

What's the most direct way to assign Serial.read() bytes to an array?

I'm trying to send NMEA 0183 sentences through LoRa. Every dinstict NMEA message looks like several char arrays (sentences) followed by '\n'. In the below picture we see one NMEA distinct message: ...
0
votes
1answer
43 views

Best strategy to parse 5 byte arrays to find a pattern

Ok here it goes, my first ever question posted to stackexchange! Please be gentle on me! I am using an Arduino UNO (at the moment, will move to a faster micro later - but still use an Arduino sketch) ...
0
votes
1answer
64 views

Animation of led strip with ESP32 does not work when WiFi is in use

I am using the ESP32 for a simple project. I know how to animate an led strip using atmega328p with arduino but when I animate it on the ESP32 it does not work that great. It will be nice if I can use ...
0
votes
1answer
56 views

ESP32 send data to another ESP32 without establishing a wifi connection

Originally I was creating a project consisting of the Atmega328P and NRF24L01 to create multiple arduinos that could talk to each other. Basically I was creating something like this: As the network ...
0
votes
0answers
51 views

Using NRF24L01 as transmitter and receiver (transceiver)

I am using the NRF24L01 module to communicate between multiple Arduinos. For this example I will have a master transmiter (tx) Arduino and a salve receiver (rx) Arduino to illustrative better my ...
0
votes
0answers
35 views

Arduino SD card module failure

I am recieving SD card failuer and I did everything I could. I use the correct SPI pins; CS > 10 MOSI > 11 MISO > 12 SCK > 13 VCC > 5v GND > GND I did format my SD card to FAT32 I ...
0
votes
1answer
23 views

DS2413 One Wire IC read and store the addresses of individual IC's

Hy, Here I using 10 DS2413 to control gpios, it works very well with arduino ,I read the 10 ic address and store it in a 2D array, I want to control the individual IC using their address .Here all ...
1
vote
1answer
45 views

More effecient datalogging code

Background: I am using a Teensy 3.6 to data log over a dozen sensors. I am printing to Serial1 for local Serial access, Serial3 for remote access (via xbee, same data is on Serial1 as on Serail3, just ...
1
vote
1answer
35 views

Please , explain about MAX30100 using for Arduino to read ADC in format (0-1023) [closed]

can anyone help me..? I am using MAX30100 with arduino, and my expectation is i can to process the ADC as usual (0-1023), but I do not understand the signal processing. Has anyone used the MAX30100 ...
0
votes
0answers
20 views

Ultrasonic sensors not working

The target of this is for the system to print "Done" when distance, measured by 2 ultrasonic sensor, is between 6-17 cm. This is my python code: import serial arduinoSerialData = serial....
0
votes
1answer
61 views

ARDUINO expected ';' before 'delay' [duplicate]

I want to shine LED in 64 of 255 duty cycles = level of brightness but it pops up this error (see picture). Can anybody tell me why and help me ? Thank you. void setup() { // put your setup code ...
0
votes
1answer
50 views

Code for 2 ultrasonic sensors

This is my code: int trigPin=13; //Sensor Trig pin connected to Arduino pin 13 int echoPin=11; //Sensor Echo pin connected to Arduino pin 11 float pingTime; //time for ping to travel from sensor to ...
0
votes
0answers
30 views

Integrating blinking light code and time on/off code

I'm trying to integrate code from one of my projects with another. One is code that blinks some Adafruit Neopixel LED strips at a specific rate and the other is a time on/off circuit here is the code ...
1
vote
2answers
83 views

Function declared in another file not recognized (undefined reference to)

I am making a multi-file arduino project, but the compiler can't recognize a function. I am using the arduino-cli version 0.10.0 This is the error I received undefined reference to pin_init() collect2....
0
votes
1answer
25 views

Weird RTC DS3231 Output only when saving the dates to variables

I am sorry to ask this question as I think it has more to do with my mediocre C++ programming skill than with the arduino. I do have a project where I want to use an RTC DS2131. I started out by using ...
0
votes
1answer
32 views

Use callbacks in Arduino with pointers to functions (will functions persist in memory?)

As I been learning Arduino (micro controllers, c++, etc) I have learned that memory is very limited. I already understand how memory works when it comes to variables. But I do not understand how ...
-2
votes
1answer
60 views

Question About The Error In This Code

Could someone point out what exactly I'm screwing up here and provide a specific solution. Here's the error message: Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno" sketch_jul24g:38:11: ...
11
votes
5answers
3k views

Why is it considered bad practice to use the 'new' keyword in Arduino?

I previously asked this question: Is it required to delete variables before going to sleep? On that question, @Delta_G posted this comment: ... Really on a microcontroller I would create the object ...
0
votes
1answer
168 views

Which Arduinos support ATOMIC_BLOCK?

Is there a definitive list of which Arduino architectures support the ATOMIC_BLOCK() macro, and a list of #defines for each architecture? I've tried searching through the Arduino cores on GitHub to ...
1
vote
2answers
47 views

Serial port usage in code

I want to write a function that defines a serial port based on a flag but I'm not sure it's possible. For example: void writeToSerial(bool useSerial1) { SerialPortClass serialPortObject; // Is ...
1
vote
1answer
120 views

Is it required to delete variables before going to sleep?

This tutorial shows how to put the arduino to sleep and use a watchdog to wake up at intervals: https://youtu.be/urLSDi7SD8M I been studding c++ and as I am getting better I am instantiating objects ...
1
vote
2answers
222 views

What exactly does the return type do in a function?

something I've never understood and still don't is, what does the return type do specifically? Everyone in tutorials just say that void returns nothing and int returns int, etc. But what does that ...
1
vote
1answer
81 views

How I can send data information without work WiFi to LCD?

Hi everyone I am beginning learn coding and the second language English. I have small project I use Arduino uno , esp8266 , dht11 , lcd I2C and use blynk app in my project I have the code and work ...
0
votes
1answer
57 views

How can I assign the value of a char array to a uint8_t array?

I have a char array variable that has a value. I need to send this value through LoRa. The library I use for the LoRa implementation accepts an array of uint8_t. How can I pass the value of a char[] ...
-3
votes
1answer
57 views

Any limitation on array size in Arduino Mega 2560?

I am writing an Arduino code with 3 arrays. Two of those are double and other one is int. Further first two arrays have nearly 420 elements for each. Now I noticed that with more that 89 elements on ...
0
votes
2answers
86 views

How to convert RGB values to Intensity

I made an arduino color sensor with tcs3200 and arduino uno. I have coded the arduino to find the RGB values when I place the color paper below the sensor. How can I derive the intensity using the RGB ...
2
votes
1answer
41 views

if I add a .cpp file, Serial becomes unusable

I am using the mega 2560. When I just use .ino and .h files, if I use Serial, it works fine, without even using: #include <SoftwareSerial.h> However, when I add a .cpp file I start getting 2 ...
0
votes
1answer
48 views

Getting enum name from enum instance [closed]

Hello Arduino Stack Exchange, I have an an enum instance called state: enum States { SLEEP, AWAKE, CRAZY } state; States state = SLEEP; I would like to convert the value of state to a String so ...
0
votes
2answers
40 views

Am not able to call C++ function pointers from inline assembly

Due to some curiosity, I was trying to use some assembly with my Arduino MEGA 2560. I am not able to invoke a function from a c++ function pointer array. When I uncomment the call function, func_a ...
1
vote
1answer
200 views

Int64_t aka long long acts as int32_t and overflows at 2^31

I have an int64_t variable. When I add another int64_t variable and convert it to a double to print it on the serial monitor, it acts as if it was a int32_t variable. This is the program: int64_t a =...
0
votes
1answer
49 views

Assigning an empty array row to reference [duplicate]

int colors[][3] = { { 255, 0, 0 }, { 0, 255, 0 }, { 0, 0, 255 }, { 253, 7, 210 } }; int (*EXCLUSIVE_COLOR)[3]; I have a two-dimensional array to store some color values. I have a 2nd ...
0
votes
1answer
30 views

Compile-time 'Undefined reference' error for functions defined in a .cpp source file that are called in my main project file

I'm currently working with the NodeMCU ESP12E and MPU6050 IMU using the Arduino IDE and wanted to create a project that has a .h file that declares the variables and functions. In the .cpp file, I ...
0
votes
1answer
49 views

Matrix and State Space Arduino Implementation

I wrote an Arduino Matrix class. Then I used this class to implement State Space on Arduino. During tests I stomped upon a problem. After starting the program it stops at some point. I have no idea ...
2
votes
1answer
113 views

Use ISRs inside a library more elegantly

At the moment I try to make a library which uses attachInterrupt(?,?,RISING) to read a sensor. The article of Nick Gammon on Calling an ISR from a class helped me a lot, but his "Glue routines" get ...
0
votes
0answers
27 views

conver UUID to string for mqtt publish

I am trying to publish jason to mqtt. Following is just a snippet of a code.When i try to add data["uuid"] to json data doesn't get published to MQTT, if I omit data["uuid"] everything works. UUID is ...
0
votes
1answer
47 views

Is it possible to count rising edges of a 4 MHz clock on an Arduino Due and trigger an interrupt like all 4'000'000 edges?

I am struggling with my Arduino Due and the Timer Counter functionallity. The following is what I am trying to achieve: I want to execute a function to a specific point of time or more precisley ...

1
2 3 4 5
18