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
24 views

Making a PID Controller for BAR 30 pressure sensor

I am having issues with my PID controller for a BAR 30 depth sensor. The issue that I have is my ESC have two initial start up { 1500 - 1900} is min - max respectively clockwise and { 1500-1900} is ...
0
votes
0answers
76 views

Having problem in coding Arduino Uno

I'm making a timer program which takes the Time Duration as input from the user by two button switches (one for 'up' and one for 'down'), and after pressing an another button switch ('start'), the ...
0
votes
0answers
41 views

Using the YS-IRTM with an Arduino Uno

Picked up a YS-IRTM IR Transmitter/Receiver module to do some testing for a project. There's not a lot of details on it but eventually came across two very important sources: Translated Module ...
1
vote
3answers
51 views

How to Specify Array Length during Object Construction within Arduino IDE?

I'm working on a group project to involving the creation of an in-house library using the Arduino IDE. As the Arduino IDE uses C++, the library must be a class. One of the classfields is an array of ...
1
vote
1answer
39 views

Order of Evaluation for #define Macros

EDIT: I think this fits better in the C++ Stack Overflow, so I'm going to re-post this there. I am working on a menu system with #define macros (inspired by the Marlin firmware on my 3D printer) I am ...
0
votes
0answers
18 views

Fingerprint sensor Arduino IDE code errors (Arduino Uno)

This code is for a fingerprint sensor. I keep getting the "function definition is not allowed before '{' token" error on the Arduino IDE. Any further corrections would also be immensely appreciated. #...
0
votes
1answer
60 views

Is this the right way to blink a character on LCD?

The code is this: #include <Wire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 16, 2); unsigned long blinkTime = 0; int ValueA = 22; String placeHolder = " "; void ...
0
votes
0answers
41 views

What does using [i] consecutive in a function means?

I read a code but i could not understand it! for (int i = 0; i < msg->length(); i++) { uart_->send(msg->data()[i]); } In above code what does this line means? data()[i]
-1
votes
1answer
32 views

expected unidentified id before 'if" [closed]

#include <iostream> using namespace std; char board[3][3]={{'1','2','3'},{'4','5','6'},{'7','8','9'}}; char turn='X'; int draw=0; int row,column; void display_board() { system("cls"); ...
2
votes
2answers
83 views

how does c++ understand which function must to use? [closed]

in this code: void AdptSendReply(const char* str) { string s(strlen(str) + 2); s = str; AdptSendReply(s); } void AdptSendReply(const string& str) { string s(str.length() + 2);...
1
vote
1answer
51 views

Problem with passing string pointer from child to parent

I am trying to pass a pointer to a const char * from a child to its parent, but I am clearly not understanding how to do this correctly. Here is the code which contains three classes: 1) parent 2) ...
0
votes
1answer
38 views

How to utilize SPI Serial bus on a ATSAMD21G18?

Like the title suggests, I have a ATSAMD21G18 microcontroller that I want to interface with a LTC6803-4 chip, but I'm not sure how to set up the SPI bus on the microcontroller, and the datasheet ...
1
vote
3answers
51 views

class enum was not declared in this scope

I am programming an Arduino. In the same .ino file as setup() and loop() I have defined the following: void setup() { // setup code } enum class CYCLE { TypeA, TypeB }; String cycleToString (...
2
votes
1answer
90 views

How to repeat an IF statement

My LCD info is called from an IF statement but since it's clock and temperature info i don't want to just show the information but update the information constantly in real time. i don't want to use (...
2
votes
1answer
63 views

Connecting to MQTT causes DHT11 Sensor to stop working?

I have a project I am working on, based on an ESP32 from NodeMCU. I have a bunch of sensors connected to said ESP32 - they all work and the code itself "works" with a minor quirk. The issue in ...
0
votes
3answers
79 views

All floats feedback a rounded down integer

So I am very confused at the results I am getting. It seems that floats aren't working properly, and I don't understand why. I was trying to read a temp sensor and convert the reading to celsius. ...
0
votes
1answer
34 views

Unexpected results when creating 32-bit int from byte array

I'm having problems creating a 32-bit integer from a 4-byte array. In the following complete, minimal, and verifiable example, converting a byte array containing 0x00, 0x04, 0x04F, 0x45 results in ...
2
votes
1answer
66 views

Arduino wrap or subclass print() to work with multiple Serial

I am writing an Arduino program that uses Bluetooth on Serial1 to print text to a Bluetooth terninal on an Android phone and also normal Serial to print text to the serial monitor on a laptop. I would ...
0
votes
0answers
20 views

How to control motor in trapezoidal manner using arduino

I am Working on a project in that i have to control motor in a Trapezoidal motion profile. on Y-axis is the velocity and X- axis as a time. Velocity increases linearly for a certain time, then ...
1
vote
1answer
47 views

Problems with Serial.read()

void loop() { if (sensor.begin() == true) { Serial.print("Current Conversion Mode: "); Serial.println(sensor.getConversionMode()); Serial.println("Enter your mode of Conversion (number ...
0
votes
2answers
50 views

How can I rewrite Arduino Code using SPI library into C++?

The issue is that I have code using an Arduino library and need to convert it into C++ so I can use it with a raspberry pi on ROS (Robot operating system). Does anyone know the best way to change it ...
0
votes
1answer
67 views

Is it possible to do an OTA update using a GitHub link

I need to be able to download software updates through the internet without having my MKR1000 plugged in. Either that or have new code being pushed from my server (C++) to my MKR1000, and then ...
2
votes
2answers
707 views

Receiving garbled `char` array returned by a function

I return a char[300] array from a function. If I intialize a char* variable with it, the return is garbled, but not if I append it to a String. What gives? const char* post2 = uploadHourCsv(...
0
votes
0answers
31 views

Arduino IDE / C++ microsd card dump trash after 512 characters

Using sample code from Arduino IDE (DumpFile.ino) on a NodeMCU 1.0, I start getting trash (⸮) after 512 characters. Any reason pop to mind? Initializing SD card...card initialized. FGKCW4K2K&...
0
votes
1answer
39 views

Accelstepper - how to switch from fullstep to halfstep in loop?

I am using Accelstepper library to control a unipolar stepper motor. In my project, I would like to run the stepper in full-step mode when I need speed and in half-step mode when I need precision. As ...
0
votes
1answer
49 views

C++ trim char array

I have a char array of length 10. It gets filled with an unpredictable number of chars, usually up to 6. char charDummy[10] = ""; When i concatenate the char array with another, I get spaces, which ...
1
vote
1answer
53 views

ARDUINO IDE debug level for stack trace only (nodeMCU 1.0)

What is the minimum debug level (TOOLS tab) which will display the stack trace on crash? I would like to reduce information clutter in the serial monitor. I understand that debug port must point to ...
1
vote
1answer
95 views

Running Python on Arduino

I've been using Python for quite long, and I was wondering if it can be used as a programming language for Arduino, rather than C/C++. When I'm using the Arduino IDE, the sketch is compiled into a ...
1
vote
2answers
46 views

Arduino SD Card open file modes append / overwrite

Running Arduine IDE SD DataLogger Example, my data gets appended to a txt file. File dataFile = SD.open("datalog.txt", FILE_WRITE); if (dataFile) { dataFile.println(dataString); dataFile.close(); ...
0
votes
1answer
36 views

Arduino - Print file name

I need my sketch to print the name of the original INO file at the beginning of execution (during setup). Is it possible? If so, what is the resource which should be used?
0
votes
1answer
58 views

Arduino only works properly when I'm touching it

I'm working on a arduino proyect, but I encountered a problem that I dont know how to solve. The only thing I have done in the hardware part is connect the arduino nano to a power source (phone ...
0
votes
0answers
20 views

Only take certain characters from Arduino Serial Output [duplicate]

I am trying to create a ble scanner but only want the device address to be displayed The device address is the 12 characters before the :-0 in the outputs. In my code shown below I have tried to run ...
1
vote
1answer
49 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> #...
1
vote
1answer
74 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
140 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
41 views

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

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
137 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
24 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
45 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
18 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
578 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
29 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
44 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
48 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
52 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
49 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
36 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
39 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
24 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
39 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 ...