Questions tagged [programming]

The process of designing and writing source code as part of a program (or sketch) for Arduino. For questions about uploading code to an Arduino board, use the [uploading] tag instead.

Use this tag for questions regarding programming (writing code) for Arduino. This can include problems with code you've written for Arduino or questions about how/why Arduino code acts in specific ways.

Where a question relates to a particular language, you can also use language-specific tags, such as .

Programming questions that are not specific to Arduino (e.g. general questions about a programming language) should be asked on Stack Overflow instead.

Please use the tag for questions regarding uploading sketches to Arduino devices.

Note: With this tag, syntax highlighting will be enabled. For more information, see the syntax highlighting help section.

1679 questions
135
votes
4 answers

How can I handle the millis() rollover?

I need to read a sensor every five minutes, but since my sketch also has other tasks to do, I cannot just delay() between the readings. There is the Blink without delay tutorial suggesting I code along these lines: void loop() { unsigned long…
Edgar Bonet
  • 45,094
  • 4
  • 42
  • 81
94
votes
22 answers

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++ and improve on these aspects?
DLJ
  • 1,149
  • 1
  • 10
  • 10
63
votes
7 answers

Is using malloc() and free() a really bad idea on Arduino?

The use of malloc() and free() seems pretty rare in the Arduino world. It is used in pure AVR C much more often, but still with caution. Is it a really bad idea to use malloc() and free() with Arduino?
Cybergibbons
  • 5,420
  • 7
  • 34
  • 51
41
votes
10 answers

Arduino Nano uploading gives error: avrdude: stk500_recv(): programmer is not responding

I have a Arduino Nano (Sainsmart) that I'm trying to upload a sketch to. Under the Arduino IDE, the device selected was Arduino Nano w/ ATmega328. However uploading the sketch gives me the error avrdude: stk500_recv(): programmer is not…
Nyxynyx
  • 1,419
  • 4
  • 23
  • 25
41
votes
10 answers

Programming an Arduino using Python, rather than C/C++

I am not very skilled with the C Language and I was wondering if there is a way in which python could be used to program an Arduino. This would most likely require a different IDE in order to be able to debug the scripts them self.
JVarhol
  • 1,903
  • 2
  • 17
  • 22
32
votes
4 answers

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 #defines for constants. There are a number of reasons…
Cybergibbons
  • 5,420
  • 7
  • 34
  • 51
24
votes
3 answers

Asynchronous function calls in Arduino sketch

In an Arduino sketch, is there a way to make asynchronous function calls within the loop? Like listening to requests through http server and process them in a non-blocking way.
Jacer Omri
  • 341
  • 1
  • 2
  • 6
22
votes
5 answers

What overheads and other considerations are there when using a struct vs a class?

C on embedded systems has traditionally use structs to hold structured data. Arduino brings C++ to the table, so we can use classes instead. Lets say we have two different data structures which could be considered very similar: typedef struct { …
Cybergibbons
  • 5,420
  • 7
  • 34
  • 51
22
votes
5 answers

How much can I recurse? How much can I recurse? How much ca!@#QFSD@$RFW

The Arduino Uno board has limited RAM which means it has a limited call stack available. Sometimes, recursion is the only quick option to implement a certain algorithm. So, given that the call stack is severely limited, what would be a way to find…
asheeshr
  • 3,847
  • 3
  • 26
  • 61
22
votes
2 answers

Why can't I declare a class in another tab in Arduino IDE?

I wanted to move some of my code out into a second tab in the Arduino IDE, to keep things better organised. At first, I only tried moving a function, and it seemed to work fine. I could call the function from the setup() function in my main tab, and…
Peter Bloomfield
  • 10,982
  • 9
  • 48
  • 87
21
votes
2 answers

Would an infinite loop inside loop() perform faster?

When you're writing a typical sketch, you usually rely on loop() being called repeatedly for as long as the Arduino is running. Moving in and out of the loop() function must introduce a small overhead though. To avoid that, you could presumably…
Peter Bloomfield
  • 10,982
  • 9
  • 48
  • 87
21
votes
3 answers

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 limitations, but I really would like to have an…
heltonbiker
  • 503
  • 7
  • 21
19
votes
5 answers

How can I declare an array of variable size (Globally)

I'd like to make three arrays of the same length. According to the documentation, Arrays must be defined as int myArray[10]; where 10 can be substituted for a known length (another integer), or filled with an array {2, 3, 5, 6, 7}. However, when I…
user3.1415927
  • 293
  • 1
  • 2
  • 5
19
votes
5 answers

deprecated conversion from string constant to 'char*'

What does this error means? I can't solve it in any way. warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
Facorazza
  • 439
  • 2
  • 6
  • 17
18
votes
6 answers

How can Arduino source code be tested automatically (continuous integration)?

I'd like manage my Arduino source code (projects and libraries) under source control with continuous testing. How can I automatically compile the code with continuous integration tools, to make sure each version compiles cleanly? In the best case…
Jakob
  • 283
  • 2
  • 7
1
2 3
99 100