We’re rewarding the question askers & reputations are being recalculated! Read more.

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.

Filter by
Sorted by
Tagged with
73
votes
4answers
53k views

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 ...
20
votes
3answers
6k 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 ...
87
votes
20answers
15k 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++...
19
votes
13answers
78k views

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 ...
9
votes
2answers
2k views

Can the 2nd MCU on the UNO R3 be used for keyboard emulation?

Following on from What's the 2nd ICSP header for in Arduino Uno R3? I was wondering how this could be hacked to our advantage. For example, could that firmware be rewritten to have the UNO ...
49
votes
8answers
76k views

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 ...
36
votes
8answers
131k views

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 ...
4
votes
1answer
91 views

How do you combine 2 different sketches together

(Before you down-vote this, note that it is a "ringer" to answer a FAQ, with a self-answer.) This question comes up all the time. How do you combine 2 different sketches together? Say I have a sample ...
0
votes
2answers
379 views

How to combine two different sensor sketches to one complete sketch?

How to combine two different sensor sketches to one complete sketch for a complete circuit that attaches to one Arduino Uno? Sharp Dust Sensor int measurePin = A0; // Connect dust sensor to Arduino ...
26
votes
3answers
46k 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 #...
1
vote
1answer
14k 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 ...
17
votes
2answers
23k views

What happens when I call exit() from my program?

In either of setup or loop, if I were to add an exit(0) call, where would control be passed to? What would the next state of the microcontroller be? Would it stop execution and power down? I am using ...
5
votes
4answers
20k views

How to add hysteresis to threshold values?

This code compares the analog input value against two thresholds, having three voltage regions. Then it will turn on an LED according to what region the read voltage is in. The problem is that when ...
3
votes
2answers
42k views

“stray '/302' in program error” when compiling

For some weird reason, the following code doesn't compile. I get a "stray '\302' in program" error around volatile unsigned int encoderPos = 0;, and I have no idea what the issue is. I've been trying ...
16
votes
5answers
65k views

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]
9
votes
2answers
6k 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 ...
12
votes
4answers
3k views

Getting a truly random number in Arduino

What is the best method to get a truly (as opposed to pseudo) random number in Arduino, or at least the best possible approximation? From my understanding, the function randomSeed(analogRead(x)) it's ...
4
votes
1answer
3k views

XBee+Arduino communication problem

I tried testing the system and I’m not sure if the problem is with the XBee’s, the transmitting code, or the receiving code. Before I post my code, I will explain what we are doing with the signals. ...
7
votes
3answers
1k views

Hiding WLAN password when pushing to GitHub

I have started to use GitHub to store Arduino code. However some of my code uses the SSID and password for my WLAN which I don’t want published. A common way of handling this in non-embedded ...
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 ...
9
votes
3answers
3k views

How to measure total energy usage of an arduino board

I have a project that I'm currently working on. We have built a green wall, wich consists of plants on a wall Now, we have a pump situated at the bottom that waters all the plants. There is an ...
4
votes
3answers
11k views

Error: 'SofwareSerial' does not name a type

I have trouble compiling this sketch. The error I get is 'SoftwareSerial' does not name a type Any ideas how could I fix it? #include SoftwareSerial.h SoftwareSerial mySerial(10, 11); // RX, TX ...
3
votes
2answers
1k 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 ...
3
votes
3answers
22k views

Resetting millis() and micros()

I want to know how much time has elapsed since a certain event, and I do not want to use any external timers. It seems logical to reset an internal timer whenever the event occurs (using an interrupt)....
2
votes
1answer
143 views

How to send UDP data packet between two access point?

I am new to arduino programming and nodeMcu boards.I have two ESP8266 bards as access points and one board get some data form WiFi stations and resend that data to other access point. but the problem ...
2
votes
1answer
6k views

pass class internal function as callback

I am trying to pass a class internal function as a callback function within the class. The error behavior is similar to this problem. Whatsoever, I was unable to construct working code based on that ...
0
votes
1answer
33 views

Split serial monitor output to only save part of the output

This is the output i get from the serial monitor from using a HM10 in . How could i go about splitting the data using arduino uno. I only want to save the last 12 digits before the :- (4CAA0DE091B7) ...
0
votes
2answers
104 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
1k views

Get the uploaded code from arduino by using arduino IDE 1.0.6 [duplicate]

Recently bought a arduino device which already have program, it is model AR-293D and I have already connect it with my PC(windows 7) through usb when I open the IDE , It seems there is no function ...
0
votes
2answers
62 views

Easy bipolar motor control?

Is here some easy way to control bipolar motor without using any other external devices, drivers or shields? I have small motor from CD-ROM so I expect it's low voltage. By control I mean just ...
0
votes
2answers
1k views

How to automatically reset the nrf24l01+ with code?

I have two separate nrf24l01+ connected to two different Arduino UNOs, one as TX and the other as RX. The problem is the connection stops after a while between them. On the Arduino COM screen I have ...
-1
votes
3answers
7k views

I keep on getting a stray '\302' in program error.How do I fix it.This is in arduino uno

#include <LiquidCrystal.h> int trigPin = 13; //sensor's trigger pin connected to pin 13 int echoPin = 7; //sensor's echo pin connected to pin 11 float pingTime; //time for the ping to hit ...
-1
votes
1answer
33 views

Code and wire a LCD and button [closed]

I need to code and wire: “Button is pressed.” to an LCD screen when a button is pressed. When the button is released, the LCD should display, “Button is released.” NEED HELP!!!
-2
votes
2answers
235 views

I am trying to combine an automatic door lock with an RFID MFRC522 with a IR REMOTE program

I am getting this error. Arduino: 1.8.2 Hourly Build 2017/02/17 11:33 (Windows 8.1), Board: "Arduino/Genuino Uno" Tone.cpp.o (symbol from plugin): In function `timer0_pin_port': (.text+0x0): ...
14
votes
2answers
23k views

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.
18
votes
4answers
128k views

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

What is the best way to unit test my code without controller? [duplicate]

I want to unit test my Arduino code. Ideally, I want to execute and test my code without uploading it to the board. What tools or libraries can help me with this? There is an Arduino emulator in ...
9
votes
3answers
836 views

Programming many Arduinos simultaneously with a wireless broadcast

I will have many microcontroller-based devices which will be independent from each other, but all will run the same program. I would like to upload a program to all of them at the same time with a ...
12
votes
6answers
34k views

Code for one-time execution in Arduino

Question: Where do I put code if I want it to execute only once per Arduino startup? Background: I tend to use my Arduino to perform tasks that should be executed once per power cycle. (For example, ...
9
votes
4answers
7k views

How to really shrink a sketch

I want to make a sketch that is as small as possible, for test purposes. The problem is, when i compile the BareMinimum sketch (with an empty setup and loop), i get 466 bytes for the Uno and a ...
8
votes
3answers
5k views

Manchester Library Won't Compile for Attiny85

I am creating a wireless sensor using an Attiny85. I want to send the data to an arduino uno, so I purchased the 315mhz rf link kit from spark fun. Since the Attiny85 does not have a TX I decided to ...
6
votes
1answer
2k 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
2answers
953 views

Need help with 2X3 matrix for braille

I'm an intermediate Arduino progammer, and I'm making an electronic braille display for my friend. You can think of this display as an array of 28x3 LEDs(one braille character contains a maximum of ...
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 ...
1
vote
2answers
10k views

Send multiple int values from Python to Arduino using pySerial

I'm trying to send 3 ints in the range of 0-180 from Python to the Arduino Uno device using pySerial (py3K). I have managed to send 1 int by using python's struct lib (not sure if it's the best or ...
19
votes
5answers
6k views

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 ...
11
votes
3answers
38k 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
3answers
73k views

Why is my LCD 16*2 is not displaying any characters, although all the wiring is correct?

Recently I have linked up a typical 16*2 LCD (Liquid Crystal Display) display to my Arduino Uno and have linked all the pins up. Here is my connection:(LCD pin first) 1=GND, 2=+5v, 4=11, 6=12, 11=5, ...
8
votes
2answers
4k views

OOP vs Inline with Arduino

I have been programming for quite a while now but I am new to Arduino and AVR Programming. The main question I have about programming these Micro-controllers is are there major differences in ...
6
votes
1answer
3k views

strange behaviour of dtostrf()

I'm trying to program a little bit in Arduino, but I'm stuck with probably something trivial. This is what I have: char ang[3], lat[9]; dtostrf(GPS.angle, 3, 0, ang); dtostrf(GPS.latitude, 9,5, ...