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
1answer
22 views

Display not showing output - Arduino Wattmeter

I have been playing with this code for some time now, I am able to show the results in an 16X2 LCD display, but I am not able to do it in an OLED. here is the code #include <SPI.h> #...
0
votes
1answer
30 views

Cannot seem to use C++11 things in my code with platformio and visual studio [closed]

I am struggling with an issue where I am trying to convert an integer to a string, among other things, and I keep getting errors like: namespace "std" has no member "to_string" The line causing this ...
1
vote
1answer
68 views

Unexplainable int behavior in encoder/LED project

I am trying to use a rotary encoder to cycle through the brightest versions of R, G & B. And it works! Red goes to blue just fine. Then G happens. For some reason, the int for green goes ...
1
vote
1answer
124 views

declared variable inside void setup is forgotten in void loop

if i declare a var in void setup() and try to do something with it in void loop(), it just says that the variable is undeclared. here is the code: #include "Servo.h" void setup() { Servo servo1; ...
0
votes
1answer
37 views

I've gotten an error telling me, “expected initializer before 'digitalWrite'” [on hold]

I should mention that I didn't write this code but got it from HERE. #include<Servo.h> Servo myservo; // create a servo object int redled=13; // declare the pins int greenled=12; int servopin=...
0
votes
2answers
48 views

Convert byte* to int in Arduino

I am trying to convert byte* value to int here is how I have it. void mqttCallback(char* topic, byte* payload, unsigned int length) { String topicStr = topic; int* payload_value; int ...
1
vote
1answer
21 views

Is new.cpp programmed improperly? Arduino 1.8.9

I'm having trouble with my code and I'm not sure if it's a memory allocation issue. So I look at the new, delete to see if it throws errors, and finding the source code I find outrageously simple ...
0
votes
0answers
27 views

Controlling keyboard LEDs with USB Host Shield

I've got a USB keyboard connected to my Arduino Uno with a USB Host Shield. I'm reading keystrokes using this example from the USB Host Shield library. I need to toggle the LEDs in the keyboard (that ...
0
votes
1answer
16 views

Random without parameters

During a programming contest, I used the following line of code: symbols[i] = random() & 0b11; After the contest, when I looked into the Arduino reference, I found out random takes one or two ...
1
vote
1answer
450 views

'Var' does not name a type!

I don't have much experience in C++ programming. I'm getting this error 'z' does not name a type!!! which I have't seen in MATLAB or python... What's wrong??? It is so simple!!! float x=10; float ...
0
votes
1answer
22 views

I have a problem with my nano arduino and the nrf24l01 as receiver

Hello I have a problem with my nano arduino and the nrf24l01 as receiver . I'm trying to upload my code to my board, but it say that my code have this mistake: Receiver:45:10: error: void value not ...
0
votes
1answer
42 views

Class help - Same Object types seem to mix values with each other

I'm having issues with two objects of the same class type. I have a LED class, which has functions to fade in and out, a LED. In my code, I create two objects of this class, and on the board, I fade ...
1
vote
1answer
47 views

Need help with wire connections and code

I am currently working on a keypad door lock mechanism (Similar to this project, Keypad door lock). The issues with the code I have is that the keypad attached to my board does not allow me to type ...
-1
votes
1answer
39 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 ...
1
vote
1answer
45 views

Is it possible to have two serialEvent() in Arduino code?

I am developing a code on Arduino and need to implement a condition that if data is available form "serial2" then only get the input for "Serial" terminal of Arduino. I have tried with below code, ...
-1
votes
1answer
29 views

Brushed ESC won't move slowly [closed]

I'm trying to control the brushed motor in a Traxxas Slash RC car with the built-in XL5 ESC using the Servo library on Arduino. I previously had success controlling this car with a Pololu Micro ...
0
votes
0answers
37 views

Arduino serial read data conversion, getting garbage values

I am developing code on Arduino to read 9 bytes of data from other controller. I am getting same arrya elements which is transmitted from controller, but when I convert the same it gives me garbage ...
0
votes
1answer
21 views

need to get values from a function with structure pointer argument and print on serial terminal

I am developing a code in which I need to print value of structure pointer on serial terminal. Below is my code snippet: typedef struct { uint8_t AB; ///< Address byte (Start byte) uint8_t ...
0
votes
1answer
32 views

Parsing array of an object in a library constructor

I am trying to develop an Arduino library that consists out of two classes. I want 'WayPointStack' to store an array of 'WPCommand', but I can't get it to work. WayPointStack.h #ifndef ...
0
votes
1answer
81 views

Multiple definitions of “xxxx” [duplicate]

I really need your help. I use VisualStudio and PlatformIo I still get this error: Linking .pioenvs\esp12e\firmware.elf .pioenvs\esp12e\src\main.cpp.o:(.data.DebugX+0x0): multiple definition of `...
0
votes
0answers
39 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. >:(...
1
vote
0answers
92 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
38 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
57 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
55 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
1k 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
53 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
24 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
23 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
36 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
96 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
186 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 ...
0
votes
1answer
47 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
512 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
63 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
91 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
464 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
72 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
35 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
101 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
129 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
42 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
99 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
40 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
85 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
165 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
47 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
501 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
914 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 ...