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
3 votes
0 answers
136 views

How to use C++20 in Arduino IDE?

I'm writing a program for esp32 using the Arduino IDE that needs to count the number of '1' bits in a byte. I found a post elsewhere that says there's a nice function in the standard library to do it: ...
Bitbang3r's user avatar
  • 541
1 vote
0 answers
75 views

LCD Wiki screen (ILI9341) 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 SKU: MAR2808 Driver IC: ILI9341 It works on an Arduino Mega 2560 using the old libraries the manufacturer (I assume) ...
Daniel's user avatar
  • 11
1 vote
0 answers
34 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
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
2 votes
2 answers
574 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
  • 541
1 vote
2 answers
107 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
316 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
98 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
63 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
52 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
350 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
68 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
355 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
112 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
  • 541
1 vote
0 answers
206 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
533 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
133 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 ...
user avatar
0 votes
2 answers
87 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
  • 541
2 votes
0 answers
132 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
114 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
4 votes
0 answers
305 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
  • 141
5 votes
1 answer
633 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
  • 165
1 vote
0 answers
60 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
103 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
91 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
166 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
185 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
155 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
109 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
491 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
751 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
268 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
492 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,395
-1 votes
1 answer
213 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
521 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
230 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
403 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
  • 235
1 vote
0 answers
417 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
606 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
104 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
336 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
76 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
85 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
222 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
191 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
251 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 votes
1 answer
55 views

Function call only works if called once

I have 3 LED chains which are all mapped to concentric rings. Each ring has a its own 2D array with the chain number & LED number. I have a function that is passed a ring array and then lights the ...
DrBwts's user avatar
  • 161
1 vote
0 answers
76 views

Need help with calling an API using an Arduino system

As stated in the title, I need help with calling an API. I'm trying to integrate make a call using the Verkada API but it seems to be using a cURL library that I'm not entirely certain I can get to ...
Tazbot815's user avatar

1
2 3 4 5
22