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
21
votes
3answers
7k views

Classes and objects: how many and which file types do I actually need to use them?

I have no previous experience with C++ or C, but know how to program C# and am learning Arduino. I just want to organize my sketches and am quite comfortable with the Arduino language even with its ...
61
votes
1answer
211k views

How do you use SPI on an Arduino?

With reference to the Arduino Uno, Mega2560, Leonardo and similar boards: How does SPI work? How fast is SPI? How do I connect between a master and a slave? How do I make an SPI slave? Please note: ...
90
votes
22answers
18k views

What are the other IDEs for Arduino?

The basic Arduino IDE lacks a lot of the sophistication present in other IDEs such as code completion, code collapsing, folder organisation, etc. Are there other IDEs that allow programming in C or C++...
15
votes
1answer
22k views

How do interrupts work on the Arduino Uno and similar boards?

Please explain how interrupts work on the Arduino Uno and related boards using the ATmega328P processor. Boards such as the: Uno Mini Nano Pro Mini Lilypad In particular please discuss: What to use ...
3
votes
3answers
2k 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 (...
93
votes
9answers
237k views

C++ vs. The Arduino Language?

What are the advantages of each language when using the Arduino? I'm thinking this is a good general question, but I'll add a bit about why I'm asking if anyone wants to give me a tip. I'm ...
1
vote
1answer
16k views

Use object of other class within class

I am writing a class for a project which will take care of handling any LCD updates for my project. The way I want to handle this is to initialize the LCD object in my main file, and then pass the LCD ...
15
votes
1answer
9k views

How does serial communications work on the Arduino?

With reference to the Arduino Uno, Mega2560, Leonardo and similar boards: How does serial communications work? How fast is serial? How do I connect between a sender and receiver? Please note: This ...
30
votes
4answers
54k views

Is it better to use #define or const int for constants?

Arduino is an odd hybrid, where some C++ functionality is used in the embedded world—traditionally a C environment. Indeed, a lot of Arduino code is very C like though. C has traditionally used #...
0
votes
2answers
10k views

Pass a member function pointer to a method of a foreign class (EDB Lib)

I'm currently working on my own arduino library and I'm becoming exasperated with the following problem: I want to store data with the extended database library (https://code.google.com/p/arduino-edb/)...
5
votes
2answers
387 views

Basic Serial Transmission Protocol

I have a small piece of code here that I hope to run on Arduino. Basically what this code is doing is, it takes a nibble from the user, appends a startbit to it, and transmits the code through a ...
6
votes
1answer
2k views

Why do I need to include libraries used in other libraries?

I have a simple library which uses another library. Here is the header: #ifndef __DERIVEDCLASS_H__ #define __DERIVEDCLASS_H__ #include <HardwareSerial.h> class DerivedClass { private: ...
12
votes
2answers
9k views

Will a .ino Arduino Sketch compile directly on GCC-AVR?

Okay, we all have seen those questions all over the web such as Arduino v.s. C++, or other similar questions. And a vast majority of the answers do not even touch compilation differences other than ...
3
votes
1answer
6k views

How to convert a String number Into a int value?

I want to convert a string into a int value. in my real code, I receive a string "Slider 255" the number after slider changes from 0 to 255, so I want a int value to be equal to that number. This is a ...
0
votes
1answer
260 views

Unable to tell if error is from receiving or transmitting end

so I am having trouble sending data using software serial's write function. TX Code: #include <SoftwareSerial.h> SoftwareSerial TX(2,3); void setup() { // put your setup code here, to ...
13
votes
4answers
7k views

Is setup and loop provided for convenience?

Arduino sketches usually feature a setup and loop function. Are these functions only provided for convenience or do they actually have special purposes? (e.g.: are some operations disallowed or ...
7
votes
3answers
1k views

Multiple SPI device

I want to connect Ethernet board (W5100 HR911105A) to Arduino Leonardo with SPI and I also want to connect SD reader. When I test these boards separately everything working. But when I connect them ...
5
votes
4answers
10k views

Timer2 does not work as it should

I am currently playing with Arduino timers (on UNO currently) and I am building a library that has a function that must be called every millisecond. There is plenty of code samples on Internet so I ...
5
votes
2answers
4k 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 ...
4
votes
2answers
5k views

How to increment and decrement an output voltage by using two buttons?

I'm trying to create a code using an Arduino Uno board to increment and decrement the output voltage of the Arduino Uno which is 5 volts and I need to step it up to 10 volts which I have done below. ...
3
votes
1answer
158 views

How does if(serial) work, a c++ question

The Arduino documentation says if(Serial) always returns 1, except for the case where Leonardo USB serial connection delays becoming ready. (Leonardo has two USB IDs, and switches between them for ...
3
votes
2answers
2k views

What is the memory expense of creating a String from a char array?

I'm writing a little API for processing email messages in Arduinos. Obviously, I need to keep memory use down, but I also want to allow the end user to use the String functions (like indexOf) to ...
1
vote
1answer
5k views

How to pass non-static class member to callback?

I am using the arduinoWebSockets library in my own Arduino library. I'm having trouble with trying to assign a class member as the websocket library onEvent callback function. MyClass.cpp: #include &...
1
vote
1answer
241 views

Accessing Values From Array Within a Library

There are many great examples of how to access information from an array on the net. I ran into a specific case that has me confused. I am using a library for attiny 85 TinyPpmReader.h. This is a ...
0
votes
2answers
116 views

What is the opposite of this data operation?

If I store in an array a double-value in this format, in which format I should be able to read the same double out? double myDouble = 12.123456; byte myArray[] = {0x00, 0x00, 0x00, 0x00}; myArray[0] ...
0
votes
1answer
623 views

Mapping PPM Signals to Servo Values

This question is an extension of this question. Accessing Values From Array Within a Library The answer provided by Mark showed me how to read and print a single value from a particular array by ...
0
votes
1answer
432 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
2answers
363 views

keypad storing problem (void value not ignored as it ought to be) [closed]

I am trying to input 11 numbers only by the use of keypad but the problem is whenever i use this code. It gave me this error. Here's my code. Help please. #include <SoftwareSerial.h> #include &...
7
votes
2answers
16k views

Why the need to use the volatile keyword on global variables when handling interrupts in Arduino?

I am familiar with the keyword Volatile being used to declare variables that are shared among multiple threads on a software application (basically on a multithreaded application). But why do I need ...
12
votes
4answers
5k views

Why is it considered bad practice to use the 'new' keyword in Arduino?

I previously asked this question: Is it required to delete variables before going to sleep? On that question, @Delta_G posted this comment: ... Really on a microcontroller I would create the object ...
3
votes
3answers
5k views

How to define a SoftwareSerial object inside a class?

I have a header file called Rhino.h with class Rhino. I want to pass RX and TX pin numbers to this object class, and with this, define a SoftwareSerial object to be used inside the Rhino class. The ...
5
votes
6answers
10k views

Using / calibrating pH sensor module

I've bought this sensor module board to link to an Arduino nano: http://www.ebay.com/itm/For-Arduino-Liquid-PH-Value-Detection-detect-Sensor-Module-Monitoring-Controller/321764233326 I assumed the ...
4
votes
1answer
10k views

How to convert Arduino example sketch to a complete c++ project?

I'm experimenting something new with my Arduino Leonardo. I removed its original bootloader and flashed it with LUFA mass storage example with added functionalities(now its a firmware). I'm trying to ...
7
votes
2answers
1k views

Arduino Yun C++ environment? Bridge + Cross-Compiler

I'm creating an XMPP chatbot for the Arduino Yun. However, I'm not too confident in the Python performance on such a low performance device and I'm much more comfortable with C++. Is there a C++ ...
6
votes
1answer
3k views

What are the benfits of global variables over static class members?

On an embedded system we use global variables often to keep dynamic memory consumption on heap and stack low. But global variables are also considered bad programming practice if they aren't used in a ...
3
votes
3answers
1k views

Is this function subject to memory fragmentation?

I'm trying to understand if the following bit of code is subject to memory fragmentation. Let's say I incrementally build a string within a function and I don't know how large the string should be. ...
1
vote
1answer
6k views

Implementing DES or AES Encryption with DateTime Synchronization on Uno

We are trying to implement AES or DES encryption using an Arduino Uno. We have a keypad module attached that will be used to input integers. A String should be generated based on the entered data and ...
12
votes
3answers
48k views

Functions with string parameters

Inside my main loop there is this string: String string1; I have a function that will take string1 as parameter, and use it to send this string as SMS. sendSMS(string1); This is the sendSMS() ...
9
votes
1answer
6k views

Writing First Library - Serial Stream Object

I have done quite a few projects with Arduino, but have never done more than a "Hello World" in C. I am writing my first library, and a lot of the object oriented stuff is going over my head. Anyway, ...
5
votes
3answers
5k views

esp8266 garbage out only when using SoftwareSerial

I'm trying to operate the esp8266. When I connect RX+TX pins to pins 1+2 on the Arduino, everything works fine. but when I'm trying to use software serial all hell breaks loose and the recieved data ...
5
votes
1answer
4k views

Basic C++ programming, how to pass constructor argument into class?

I'm having some programming problems. So here's what's happening: In my .ino file, I have a tft variable which holds the connection to a LCD. I want to make a class which can either automatically ...
3
votes
1answer
7k views

>> << and -> Syntax in arduino

I was trying to follow this tutorial and came across >>. What exactly does this do?
3
votes
1answer
5k views

Arduino with WS2812 using Adafruit NeoPixel library fade in/out different patterns

Hey all I have been trying to figure out a way to random set patterns for my fade in/ out code below: int PIN = 3; int totalLEDs = 11; int ledFadeTime = 5; Adafruit_NeoPixel strip = ...
1
vote
1answer
206 views

Is it required to delete variables before going to sleep?

This tutorial shows how to put the arduino to sleep and use a watchdog to wake up at intervals: https://youtu.be/urLSDi7SD8M I been studding c++ and as I am getting better I am instantiating objects ...
1
vote
2answers
7k views

Dynamicly sized array as a class member

I want to create a dynamic sized array of chars as a member in a class. This is being done inside a library that I've created. I have the .h and the .cpp files created. I'm not sure how to declare ...
1
vote
1answer
584 views

pushing accelerometer data in packets from an arduino due to the pc and unto processing

I'm quite a newbie to this and I've been struggling for sometime now with my school project, trying to find a way to send accelerometer data from my MMA7361 in data packets, I understand that I have ...
1
vote
2answers
4k views

Obstacle avoidance algorithm

TARGET The task I have taken as a challenge is to make a GPS-guided robot incorporated with features like Arduino for programming, ultrasonic sensors for obstacle avoidance and a GPS module to ...
13
votes
3answers
37k views

Returning an int array from a function

I have a function that needs to return 3 int values. I currently use an array declared in the global scope and I ask the function to write into them. Is there a way to make a function return an array? ...
6
votes
4answers
4k views

Multithreading with Arduino

Well I've just started learning the concept of multithreading with C++ and immediately a bunch of questions came to mind about the possibility of using multithreading with microcontrollers in general ...
3
votes
2answers
4k views

Connect Arduino to MySQL database online problem

I'm trying to connect Arduino with MySQL database on my online server. I manage my project to work on WampServer locally on localhost, but when I try to move everything online I have problem... on ...