Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
0answers
33 views

Expected primary expression

Hi I am trying to compile the attached code to an arduino with Bluetooth but continually get the same error and can not see the issue. The IDE highlights line 298 but can not see an issue with it. >:(...
0
votes
0answers
27 views

String.format(“%i”,i) equivalent

How do I format an arduino String when I do not want to print it? I know that one can use printf() or other methods to print a formated string and unfortunately that's all I find with google. But that'...
0
votes
0answers
23 views

Tuning Ardunio self balancing robot’s PID parameters with Genetic Algorithm [closed]

First, I need to tell that I am the newbiest person in the universe about Ardunio. For my PhD thesis I developed an optimization algorithm for dynamic environments. Now I need to test my algorithm on ...
0
votes
0answers
17 views

Adafruit Feather nRF52832 as a SPI slave

Like the title says, I am trying to configure the Adafruit Feather nRF52 as a SPI slave, who will receive information from a MSP430 microcontroller. I have found a few code examples that provide ...
0
votes
0answers
27 views

passing a char array referance to a methode of a class

I want to set a class for a sensor. One of the attributes of the sensor is an int array that I'd like to pass to a methode to store values in the array. The methode sould be able to write over ...
1
vote
0answers
51 views

Using pointer to a Global function

I am trying to store and use a pointer to a global function. The function global_f returns a String and takes an object as parameter: String global_f(Request r){ // ... return "This is it"; } ...
0
votes
1answer
45 views

ATTiny85 I2C connection with Arduino Nano

I am trying to send and receive data using I2C between an Arduino Nano and an ATTiny85. The ATTiny is mounted on this board: Link I've tried to reach the slave with the simple I2C scanner, but I don'...
4
votes
3answers
968 views

Memory usage: #define vs. static const for uint8_t

I'm writing an Arduino library to communicate with an I2C device, and I'm wondering what the best way is to declare all the register addresses so as to save memory. Using #defines: #define ...
0
votes
1answer
44 views

if/else on digitalRead not executing on 'else' portion

I am a beginner with C++ but used to be good with BASIC (2 decades ago lol). I'm building a peristaltic metered doser that allows you to input desired mL on a 4x4 keypad and then when 'fill' button is ...
0
votes
0answers
21 views

Problems compiling with enum value PORT1-7

So I have this enum in a header file: enum class ServoPort {PORT1 = 1, PORT2, PORT3, PORT4, PORT5, PORT6}; The trouble is that when I try to use it in the primary file (by doing MyClass::ServoPort::...
0
votes
0answers
20 views

NRF240L01 code freeze on if statement

I have 2 arduino unos that are talking to each other with a couple NRF240L01 antennas. I have used these before and never had an issue but with this project two of my radio.write commands are causing ...
0
votes
0answers
34 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 * ...
0
votes
1answer
50 views

Weird behavior with char/uint8 arrays

So I'm trying to read an 8-byte character string from an I2C device and print it to the serial console. This raw 8-char array is not terminated when it comes from the device, so I'm pretty sure I need ...
1
vote
1answer
116 views

Error: Does not name a type [closed]

I have made a class called subjects and I have then made a subject called math. I am trying to set a classroom for math but it is giving me the error 'math' doesn't name a type. Code for the class ...
1
vote
1answer
45 views

When does a pre/post increment occur? [closed]

Editing here to clarify. The headline asks the question but the example given was not ideal. This was a more general Q than about the example code. Compilers have sequence points, places where you ...
3
votes
2answers
338 views

How to declare a global variable in the .h file?

I have a .h library file in which I want to declare a global variable that can be read in the program loop and in the library's .cpp file. The question is, is it possible to declare a variable in the ...
0
votes
1answer
58 views

Where are the implementations of the SdFat BlockDriver methods?

This is most probably more of a C++ question than an Arduino question; but since this is an Arduino library, I am asking here. I am using the SdFat library for my project. The library defines a ...
1
vote
0answers
35 views

Passing non-static member function using bind

I'm using the GxEPD2 library to communicate with an E-Paper display. I now wanted to use the drawPaged method of this library with an object display. I also have written my own class from which I ...
0
votes
1answer
145 views

'RtcDateTime' does not name a type

I've tested a code that compiles successfully. But after i merged it to another code, here it shown an error says RtcDateTime doesn't name a type. Used library : https://github.com/Makuna/Rtc Some ...
0
votes
1answer
69 views

Random number/sequence output

The program I'm trying to build is: Type in 1st name, hit enter, type in 2nd name and then hit enter again. Register those names from string input to char naming in student struct. Print out the ...
0
votes
1answer
28 views

What's going wrong with my EEPROM?

I've been chipping away at a project for a long time now and I've found a serious bug. Basically the user has an 8x8 grid, and each cell in this grid has a number of properties. I want to be able ...
0
votes
0answers
62 views

ESP32 MP3Decoding with VS1053/1003 not working

I want to build an webradio with my ESP32 and want to decode the mp3Stream with the Vs1053/1003. I´ve tried many libraries, but none of them worked, so I tried to understand the datasheet and I´ve ...
2
votes
0answers
84 views

TRIAC Pulse driver for Spot Welder (help needed with programming)

I have designed and built a transformer driver board for my spot welder. It is powered from mains electricity (230 V) and consists of the following segments: triac drive and protection, zero cross ...
0
votes
1answer
27 views

Issue with analog readings on Arduino atMega with YL-69 moisture sensors

I've connected four YL-69 sensors to my arduino at-mega2560 on analogs pins 0-3. This is combined with four DHT11 sensors that are in digital pins. The DHT work fine, and I can work one YL-69 ...
0
votes
0answers
48 views

Ethernet Shield - Not Working Properly Always

I'm working on a school project and using Arduino Uno. The basic working method for the project is as follows: Read temperature from LM-35. Read CO2 level in air using MH-Z14A. Upload data to server ...
0
votes
1answer
34 views

Dynamically modifying the call stack using pointers

In a C++ Arduino library, can we modify the call stack from inside a function by intentionally decrementing a pointer to a stack variable so that it's out of range? Like this: void FooBar() { char ...
1
vote
2answers
81 views

Need help with the syntax for a function that takes a closure [closed]

My C++ is very out-of-date. (20+ years, before C++ had closures). I'm a senior SW engineer, and I spent several hours yesterday trying to figure this out, but I could not work it out. The background:...
0
votes
3answers
110 views

Creating a library for arduino

I found a really nice 24 bit I2C adc which was fairly cheap as well (ADS1219) but as far as I could tell there are no libraries for it so I decided to make my own. I have managed to write functions ...
1
vote
2answers
46 views

Most efficent way to adjust value

I am working on a system that starts a process based of a set time value (startHour). The user sets the start hour and can only select values from 00-23. I have been asked to start the same process at ...
1
vote
3answers
462 views

Why to store a function parameter value in a class private variable?

I'm just curious, I'm going through a C++ library for the mcu2.4 TFT display. And this method I notice when I run through C++ libraries. Which is when a parameter is passed through a function, it's ...
1
vote
1answer
388 views

Get ESP32 Chip ID into a string variable (Arduino/C++ newbie here)

It's just a few days since I started using Arduino IDE ( programming an ESP32 ). As I learn, I am trying to write some snippets. I wanted to store the Chip ID of ESP32 into a variable (preferably ...
0
votes
1answer
26 views

How can I call the constructor of a Class after it called once? [closed]

I have a problem with Classes. I have a bunch of code, that code is uses Adafruit MQTT FONA library. I call the Class for make new Instance and Connect to specified server with this code; ...
0
votes
1answer
121 views

How to avoid Multiple definition of 'Blynk' error?

By including #include <BlynkSimpleEsp8266.h> Blynk library (https://github.com/blynkkk/blynk-library) from more than 1 module/cpp file, "Multiple definition of `Blynk’" error is thrown at ...
0
votes
1answer
82 views

How can I concatenate these two values as a string?

I've tried all the supposed solutions for the exact error, pasted into google, that I could find on every forum including this one and no matter the alleged solution I will either get the error about ...
0
votes
2answers
33 views

Transient buttons control non-transient behaviour of LEDs

Imagine a system where you have two transient non-exclusive buttons and two LEDs. When you press button 1, the LED 1 is HIGH and LED 2 is LOW (and stays that way). When you press button 2, the LED ...
0
votes
0answers
21 views

Arduino lcd game problems, endless runner code not working

i have a game i have downloaded and built, have a file here, (file is too large to put on here), i am posting the whole thing because i dot know why the code wont work. that file is the original (from ...
1
vote
1answer
40 views

How to combine time into a variable

I have an Arduino Uno project which is recording student attendance using fingerprint sensor. So when sensor found a match, the serial monitor will be printing out Student ID and current time like ...
0
votes
2answers
48 views

How to read sound sensor readings and light up sensor with water sensor if the readings is above threshold & when water is detected for 2 mins?

I am student that is new to Arduino and working on a project to trigger an alert if the sound level detected exceeds the threshold for a period of 2 mins. But I am stuck, would like to check how do I ...
-1
votes
1answer
287 views

ESP8266 WebServer not responding (connection time out)

My web server running on ESP8266, stop working after while. I cannot connect to it - browser shows connection time out error. No error, no crash... nothing. Have you any idea how to fix it? My code: ...
0
votes
2answers
121 views

Custom Classes - Redefinition of void error [closed]

I'm getting a redefinition error from my classes, but can't see what I did wrong. Error: Icon.cpp:3:6: error: redefinition of 'void Icon::setIcon(byte (*)[8])' Can any help me out on this? Thanks! ...
0
votes
1answer
50 views

Value assignment on Arduino

I have a thermocouple k. I want this thermocouple to select the first value OF TEMPERATURE that it read and assign it to a variable in an Arduino program. How should I do that?
1
vote
2answers
48 views

How to convert this sketch to keep only one if-else statement? [closed]

int ldrPin = A0; int rainPin = A1; int smokePin = A2; int greenLED = 6; int redLED = 7; // you can adjust the threshold value int thresholdValue = 500; int LightSensorThreshold = 500; int ...
0
votes
2answers
80 views

How do i fade a colorwipe from off to on in 1 color?

So I want to make the same effect as a colorwipe (like going around in a circle turning leds on till they all turn on) except that instead of going from off to 100% brightness immediately I need it to ...
1
vote
2answers
90 views

What exactly does the Arduino preprocessor do?

Arduino claims to be a "language," not just an "application framework," and Arduino files have their own extension, .ino. The language is obviously C++, but not quite. My understanding is that ...
0
votes
1answer
165 views

Read Multiple Sensors Data from a text file located in SD Card in Arduino/ESP32

I am working on a small home project 'glucose meter' via non invasive techniques. I am using four sensors like RGB color sensor, two multi-wavelength photo diodes (A & B) and temperature sensor (K-...
0
votes
1answer
175 views

No data sent over serial port in linux c++

TL;DR - I am attempting serial communication with Arduino with code that I found here and nothing gets sent over (Arduino programmed to respond, and I checked that it does with its serial monitor) Hi ...
0
votes
1answer
215 views

ESP8266 SPIFFS not saving correctly?

Hey all I am having some issues with the SPIFFS for this Wemos D1 mini ESP8266 controller. This is my Arduino sketch: #include <FS.h> #include <ArduinoJson.h> struct RGBLA { uint8_t R;...
2
votes
1answer
226 views

Arduino std::map returning random values

I'm working with an arduino UNO. I would like to be able to send it set and get commands over serial and have it update class data class members accordingly by key value pair. I spoke to users in the ...
0
votes
1answer
1k views

Arduino Convert std:string to String

I'm working on BLE project with espressif library. And It returns me founded BLE device. std::string getManufacturerData(); std::string getName(); int getRSSI(); BLEScan* getScan(); When ...
0
votes
2answers
44 views

What is the purpose of '&' while passing bool as a function parameter [closed]

If I use this function without & before change_x (in function parameter), change_x never changes to false and it keeps on printing forever. Why do I need &? void some_function(bool &...