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
1 vote
0 answers
24 views

LCD Wiki screen works on Mega. How to get it working on the Due?

I have this exact LCD shield: http://www.lcdwiki.com/2.8inch_Arduino_Display It works on an Arduino Mega 2560 using the old libraries the manufacturer (I assume) provides on the wiki page. I was ...
Daniel's user avatar
  • 11
1 vote
0 answers
27 views

Feather M0 RFM69 serial over radio IP over serial works for UDP packets but fails for TCP sessions

I'm trying to build a serial over radio transmitter module using two Feather M0 boards with RFM69HCW chips on board. As a test I'm trying to run a slip IP over serial session. This seems to work ...
Lukas's user avatar
  • 11
0 votes
0 answers
46 views

TowerPro MG995 cannot just rotate 90 Deg [closed]

I want to code a program that commands the servo motor only rotate 90 Deg but it keeps turning and not rotating 90 deg, this is my code #define Servo_PWM 6 Servo MG995_Servo; void setup() { ...
Tan Jun Jie's user avatar
2 votes
2 answers
1k views

Alternative to polling interrupt flag from main loop?

I am using an ISR, which is written to be as minimal as possible: volatile bool interrupt1{}; void ISR1() { interrupt1 = true; } The interrupt is handled by polling the interrupt1 variable in ...
Erik's user avatar
  • 261
1 vote
0 answers
46 views

Scrolling function for existing Arduino menu using 16x2 LCD [closed]

I am creating a menu system for my project. I have successfully finished my code to configure up to 2 menu items on my 16x2 LCD I2C. I would like to extend it and add up to 5 menu items in the code ...
neospice's user avatar
0 votes
0 answers
23 views

Arduino IDE: Delays in void loop() prevent counting number of switches

How can I count the number of prox switches and at the same time reference this value for conditionals within loop()? The delays make my loop counter stop adding. I need to know the total number of ...
remusconnor's user avatar
2 votes
2 answers
560 views

Using Adafruit RTClib without fragmenting the heap

I'm getting ready to add DS1307 support to my Arduino app, and was horrified when I looked at the sourcecode for the RTC_DS1307 class in Adafruit's RTClib library... DateTime RTC_DS1307::now() { ...
Bitbang3r's user avatar
  • 493
1 vote
2 answers
75 views

How do you use two piezos at the same time?

I'm trying to replicate a short music clip with two piezos, and I want them to play at the same time. While the right piezo is playing, I want the left one to still be looping. The problem is, I'm not ...
Harrisino's user avatar
4 votes
2 answers
309 views

"if" condition problem / question

I'm new to Arduino and my question is rather theoretical. I have an Arduino Nano board (Atmega168 processor), a button, a display. I have written a button handler that does not stop code execution. My ...
ONamaeWa's user avatar
0 votes
1 answer
76 views

How do I write efficient callback functions on a Teensy 4.0?

I am looking at refactoring my code by implementing callback functions in order to be able to reuse the abstract logic of other functions/classes. However, I feel I need to learn more about the limits ...
Erik's user avatar
  • 261
0 votes
1 answer
60 views

Why is char being "extended" to an int?

I know I'm missing something so simple here, but I can't figure it out. If I do char letter = 'A'; then letter = letter << 8, letter = 0, as one should expect, since we are shifting the bits &...
AJ_Smoothie's user avatar
-1 votes
1 answer
46 views

How to get recover numeric data sent by an Arduino in binary

I am a C# dev and these C++ data conversions are killing me. I have an Arduino sending binary data through LoRaWAN to AzureIOT. I am trying to decode my Temp/Humid/Bat payload that I am pulling out of ...
Terrence's user avatar
  • 103
-1 votes
1 answer
119 views

convert string representing a binary number to binary

I have a serial input "1111111" and I would like to convert this to a binary B1111111 that I can send to a led matrix. I tried to search, but, all the results were misleading, led to full ...
vilmarci's user avatar
  • 109
0 votes
0 answers
46 views

Respond to all WiFi probe requests with ESP8266?

I'm wondering if there's a way to program an ESP8266 such that it responds to all WiFi beacon probe requests. For example, if a device sends a probe request for a WiFi network name, e.g. "...
Blue Herring's user avatar
2 votes
1 answer
175 views

Read binary file on SD card

Why I can't read the last byte in the file when I use the Arduino ide code? The code in cpp is work without any mistakes. This is my code on Arduino ide: vector<unsigned char> text; unsigned ...
george's user avatar
  • 139
1 vote
2 answers
65 views

Overhead of using 'new' to create object in dynamic ram vs automatic to create on stack

Let's suppose I have a class named Foo, and sizeof(Foo) is 10 bytes. As I understand it, creating a Foo with 'automatic' scope (on the stack) has zero overhead. If the Object occupies 10 bytes, it ...
Bitbang3r's user avatar
  • 493
1 vote
0 answers
111 views

How to use multiple PN532 over i2c bus(es) and SPI?

I am working on a project that involves 3 PN532_modules to an ESP32, which sends the Tag_ID over BLE. Plan A was to use One module on i2c_1, second on I2C_2 and third over SPI. The SPI one works as ...
user91535's user avatar
4 votes
2 answers
245 views

Trying to resolve invalid conversion from 'byte' {aka 'unsigned char'} to

I'm trying to use an existing Arduino library on the Raspberry Pi Pico. The library is here: https://github.com/j-bellavance/EdgeDebounce/tree/master It's based on some interesting insight at Jack ...
Jeff Haas's user avatar
0 votes
2 answers
101 views

How much readable text can fit inside an ATTINY85? Feasibility of scrolling a booklet on a 0.91-inch OLED display

I'm a total beginner, so I've been talking with Chatgpt regarding the capabilities of the Attiny85 microcontroller. But the AI would hallucinate a lot and give only partially right answers (because it ...
Moises's user avatar
  • 9
0 votes
2 answers
68 views

Are variables declared in main.cpp static, instance, or...?

Let's suppose you've just created a new Arduino project using PlatformIO, or an IDE like Sloeber. You now have a file named "main.cpp" with two functions (methods?): void setup() void loop()...
Bitbang3r's user avatar
  • 493
2 votes
0 answers
107 views

Program crashes when calling external library code via function pointer

I've written a user library for the Pi Pico that uses the TaskScheduler library to abstract timing away from the user. The user provides a function in their sketch which the library calls periodically ...
Joe of Loath's user avatar
2 votes
1 answer
27 views

Seting up registers in Samd based arduino board

I'm trying to setup the BOD33 for Samd51 MCU in th .ino file as a first thing, even before the #include lines in the .ino // Define the base address for t_SUPC #define T_SUPC_BASE 0x40001800UL // ...
Dan Neb's user avatar
  • 21
4 votes
1 answer
93 views

How do you take the simplest continuous reading from a Garmin Lidar Lite V4 using I2C on a Particle Boron v4.1.0?

Hey there Stack community. I'm working with the Particle Boron v4.1.0. I'm connecting a Garmin Lidar Lite V4 on I2C. I'm using the LIDARLite_v4LED.h header file found in the library given for this ...
Katie Neeley's user avatar
3 votes
0 answers
205 views

Problem with reading data from ELM327

The idea was to create a bluetooth device on the arduino to read data from the machine (ELM327 v2.1) using the HC-05 bluetooth module. In this code the bluetooth module is switched to MASTER mode and ...
gfd2's user avatar
  • 131
4 votes
1 answer
394 views

ESP32 SocketIO Client is not connecting to Flask-SocketIO Server

I'm trying to connect a ESP32 client using SocketIO with a Flask-SocketIO server and it's not getting connected. The server uses SSL. The local server address is https://192.168.1.137:3000.Is the ...
Shyam3089's user avatar
  • 153
1 vote
0 answers
51 views

Arduino sketch doesn't work when uploaded to arduino nano and OLED display shows npothing (possible issue: lack of memory)

I need some hand here. I wrote some code for a small arduino console-like device that has five pushbuttons, 128x64 I2C OLED display and arduino nano. And it doesn't work when uploaded to arduino nano -...
Demko's user avatar
  • 19
1 vote
1 answer
84 views

Good practice to assign shift-register pins at the same time?

I'm new to bit register manipulation and am trying to set input and output values of some pins. The code sample I have on hand does it this way:: DDRD |= (1 << 2); DDRD |= (1 &...
Letshin's user avatar
  • 121
1 vote
0 answers
75 views

how to config size USB mass storage arduino nano ble 33?

I see that they arduino nano ble 33 support USB 2.0. Is there a way for us to create a USB mass storage of about 200kb for convenient storage of configuration files and history files? I see example ...
Nguyễn Thuận Hải's user avatar
1 vote
0 answers
120 views

Pool pump man-in-the-middle SDA/SCL with ESP32

Hey all I have found some code on GitHub that works with my pool pump but it seems my model is a little newer than the one they used on on their GitHub. Most things seem to work but what doesn't is ...
StealthRT's user avatar
  • 257
0 votes
1 answer
148 views

if statement does not work with fraction, but works with decimal equivalent

I'm trying to trouble shoot a problem with my code and narrowed it down to my if statement not working with a fraction. The below code does not work and returns 0 for(float i=0; i <= 1; i += .0001){...
LB Burkhardt's user avatar
0 votes
2 answers
104 views

How to return a value from a non integer input between 0-5 from an output range of 0-320 in map() method

I am experimenting using the map() method in an ArduinoIDE sketch in an attempt to obtain a pixel position for a horizontal meter in the range 0-320 from an input value in the range 0-5. However, ...
John's user avatar
  • 49
2 votes
1 answer
106 views

Why is sensitivity (threshold) parameter ignored

Analog pontentiometer connected to an Arduino. simplest possible setup. The goal is to send a message over Serial whenever the value changes. I do not want to spam the Serial connection to much, so ...
David's user avatar
  • 125
3 votes
2 answers
473 views

Where does this sketch have Undefined Behavior?

Simple sketch and simple question: where does this sketch have undefined behavior? Note: I don't need a solution to fix the code. I already have code that works. I really need to understand where my ...
Thomas Weller's user avatar
0 votes
1 answer
558 views

integer overflow in expression of type 'int' results

i need to wake up my ESP every 60 min to read some data and post it to server, all process working fine when i use numbers of minute below 60 (converted in microsecond x 1000000) but when i use 60 min ...
Damiano Miazzi's user avatar
-1 votes
1 answer
149 views

6-pin BME280 not giving I2C signal

I'm creating a telemetry package for my my mom's model rocket with a MPU6050, a BME280, and a SD reader/writer. The code I found for the BME does not read any information. When I upload an I2C scanner,...
ModelRocketeer's user avatar
1 vote
1 answer
332 views

Setting pinmode() in header file

I am trying to have a header file to handle all my pin definitions and pinmodes. This is the header: #ifndef __HEADER_TESTER__ #define __HEADER_TESTER__ #include <SoftwareSerial.h> const byte ...
user1584421's user avatar
  • 1,385
-1 votes
1 answer
145 views

How to pass Strem object to my class

I'm trying to creaper class wraper to use an Streamobject but I've an error when I try to compile. My .hfile : #include <Arduino.h> class TestSerialListener { public: TestSerialListener(...
simon's user avatar
  • 133
-1 votes
1 answer
340 views

Carbon dioxide sensor MG 811

I am using MG811 carbon dioxide sensor with ESP8266 module. CO2 values is being read inside closed room. The value comes around 400 ppm. Using CO2 generator does not make increase in reading. Checked ...
Jashanjot Kaur's user avatar
1 vote
1 answer
158 views

Passing function as argument, with capture, what type to declare in function? [closed]

This probably has a simple resolution, but can't find the right combination. I'm trying to setup a function (setupScreen) to take as an argument a function to do the actual setup: void ScreenHelpers::...
Snappawapa's user avatar
0 votes
2 answers
283 views

How does Arduino handle passing this union?

I'm unsure how this will be handled by the Arduino compiler. If anyone can explain what and why, I'd appreciate it. This is obviously very simplified, but it does contain the actual issue. At the ...
Jim Mack's user avatar
  • 237
1 vote
0 answers
311 views

object of "ESPAsyncWebServer" causing conflict

I have been trying to develop multi cpp project in platformio and whenever I define ESPAsyncWebServer class object with the extern in defines.h and declare it in main.cpp I am getting scarry looking ...
Shubham's user avatar
  • 11
3 votes
1 answer
539 views

how to transfer json to string?

I am getting a json object from aws iot MQTT. Assuming that json from aws is {status:opened}. Here is my code. #include <ArduinoJson.h> void messageHandler(char *topic, byte *payload, unsigned ...
Jess's user avatar
  • 53
-2 votes
1 answer
93 views

Arduino code giving error while compiling [closed]

I am a beginner, and I'm trying to make code to control a servo using two ultrasonic sensors. I've tried to make the code, but when I tried to compile it using my simulation app, it gives this error: ...
Joseph Afodu's user avatar
0 votes
3 answers
230 views

How to abort compilation based on a "wrong" value in a variable

I looking for some code that can generate a compile time error when a variable contains a wrong value. I once started with this code in a c program: #define FIFO_BUFFER_SIZE 8 #define ...
hennep's user avatar
  • 121
-1 votes
2 answers
74 views

A few Bitshifting questions!

So int in Arduino is 2 bytes, which could technically hold up to a value of 65535. However, the MSB is used as a sign bit, so now we have -32,768 to 32,767. So it's a signed integer, easy stuff. While ...
AJ_Smoothie's user avatar
0 votes
0 answers
69 views

ESP32-WROOM-32 Wifisecureclient read() result in gibberish data

We are testing our own library with ESP32-wroom-32. In the .cpp file we have: void HttpDownstreamClient::tokenCreate(char* URL, char* Subname, char* Suber, int expiretime) { Serial.print("The ...
YIL's user avatar
  • 1
-1 votes
1 answer
188 views

How to write arduino code in a c/c++ script

I'm pretty new to arduino. But I have some knowledge about programming in c/c++. I know that arduino is written in c. But it can't be used as normal c/c++ code. for example , instead of including some ...
Alien5516788's user avatar
1 vote
2 answers
183 views

Array of Functions

I'm new to C++. How to make a menu without if() {} else {} & switch() case? I made a menu on an array, but for some reason it doesn't compile. How to correct it? typedef void (*cbd)(uint8_t, ...
Andre's user avatar
  • 27
1 vote
2 answers
1k views

Call functions of one class from another class - Callback

I am new to C++ & I need to call functions of one class from another class. And so that the classes do not know anything about each other. How to do it in Arduino environment? class Encoder { ...
Andre's user avatar
  • 27
-2 votes
1 answer
219 views

1Hz & 32Hz from 32.768 kHz on ATmega328P at 8MHz & DS3231 32K

I have a 32.768 kHz signal at the ATmega328P input. I need to get 2 signals from this signal: 1Hz and 32Hz. How well will it work? How to do this with a ATmega328P Timer/Counter? What gain will the ...
Andre's user avatar
  • 27

1
2 3 4 5
22