Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [c]

C is a procedural programming language which is widely used in embedded systems. PLEASE NOTE: Arduino is typically programmed in C++, not C.

13
votes
5answers
59k 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]
11
votes
5answers
6k views

Arduino: How to get the board type in code

I want to write a sketch that can be compiled on different Arduino boards. I want to display on the PC which board is currently connected. This means that the user connects the PC via USB cable to ...
11
votes
4answers
7k views

Writing C Program outside of Arduino IDE?

I like the idea of using the Arduino IDE for simple projects and for getting started with Arduino, but the consensus I've gotten so far is that it is for those who are new to Arduino and/or ...
9
votes
3answers
13k views

SAM3X8E (Arduino Due) Pin IO registers

How do the IO registers of Arduino Due work? On Arduino Uno just set DDRx, then PINx to read, PORTx to write, I'd like to do the same thing with an Arduino Due, but it has many more registers, such as ...
8
votes
2answers
3k views

Arduino interruption (on pin change)

I use the interrupt function to fill an array with values received from digitalRead(). void setup() { Serial.begin(115200); attachInterrupt(0, test_func, CHANGE); } void ...
8
votes
3answers
11k views

How to call C functions from Arduino sketch?

I would like to know if there is a way to call functions that are contained within C files using an Arduino sketch? My C file declares and defines a function. To save putting the messy function ...
7
votes
2answers
34k views

How do I convert a float into char*?

Asked this question on Electrical Engineering Stack Exchange and was directed here: Pretty self explanatory; how would I go about converting a float into a char*? I have code in which the float '...
7
votes
2answers
8k views

Basic makefile for avr-gcc

I would like to make a makefile for compiling c programs for the arduino. I am somewhat familiar with make but have never used it with avr-gcc. What is the simplest way I could put the commands below ...
6
votes
2answers
2k views

Arduino DC motor causes disturbance. What can cause it?

I tried to fix this problem the whole weekend but, after no success I decided to post it here. I would really appreciate any help. The problem The Wi-Fi module activates the DC motor and lets it run ...
5
votes
4answers
6k views

ATtiny85 minimum setup to blink led

What would be the (very) minimum schematic to make a ATtiny85 blink a led? Restrictions are: There must be a C program compiled and uploaded to it, just like an Arduino board would have. The code ...
5
votes
2answers
838 views

Why doesn't my code work in a function, yet works inline?

I'm trying to write a faster shiftOut function, which does not use the slow digitalWrite. In my code I have the original shiftOut, the new shiftOutFast, and the same as shiftOutFast, but inline. The ...
5
votes
5answers
7k views

how fast does loop() run in Arduino

Hi I am using Arduino Nano to gamify my experience on Unity3D. I know that Update() in Unity3D runs every frame per second but I because I'm not an electronics guy I don't know how loop() function ...
5
votes
2answers
487 views

Arduino's digitalWrite, precautions for direct port manipulation?

I stumbled upon this piece in digitalWrite. I'm unsure why clearing interrupts and setting/resetting SREG is neccesary here. Can anyone shed a light on this? uint8_t oldSREG = SREG; cli(); if (val =...
5
votes
2answers
4k views

Problem importing a library in .h file

I have following code: MyApp.ino: #include "DfRobotLcdShield.h" void setup() { } void loop() { } DfRobotLcdShield.h: #include <LiquidCrystal.h> When I try to compile, I'm getting the ...
4
votes
3answers
3k views

How to calculate phase shift between two square waveforms with Arduino DUE

I have two square wave signals with the same frequency. I want to measure the phase shift between these two signals. There will be a small phase difference between two signals. (0-90 degree) and the ...
4
votes
1answer
299 views

Chain of, or one big if sentence

(This might be more of a common C question) I want to test several conditions in an IF-sentence if(variable) { // fastest check if(register) { // a bit slower if(...
4
votes
2answers
2k views

Properly using separate tabs with Arduino IDE

I'm trying to split up a large project of mine into separate tabs in the Arduino IDE and I'm having more than a few troubles with it. My main trouble is finding a way to have routines in extra tabs ...
4
votes
2answers
146 views

How to move my robot in the right direction?

After all there is more question poping up then answers i decide to upload the pdf where is everything writen, like the wire, motor type and what we can and can't use. Here is the link pdf format of ...
4
votes
1answer
222 views

Understanding how methods and pointers inside a function work

After this question i starteted going deep with the theory, and started studyng step-by-step with the "Beginning C, for Arduino " Jack Purdum. I finished to study the functions chapter, but i still ...
4
votes
2answers
3k views

“EVERY_N_MILLISECONDS”

One of the FastLED examples that I've seen was using code that looks like this: EVERY_N_MILLISECONDS( 300 ) { transition_step(); } I've copied it and successfully used it in the same context - but ...
4
votes
1answer
2k views

Combine bits from two ports into a single byte

I'm attempting to read the values of 8 pins at a time into a byte. The obvious answer to this seems to be the Port registers, however with the way the Arduino is wired, I'd have to split my read ...
3
votes
3answers
595 views

Arduino port relocation (PORTD to PORTB)

So I'm trying to connect the chip with an 8-bit data bus. All works good, but... Arduino Uno uses D0 and D1 for serial TX/RX (USB connection with PC). When I try to open a serial connection (on ...
3
votes
3answers
707 views

Binary message formatter

I am currently developing an IoT device with arduino and i want to minimise the data payload. First i used json which is not very efficent in fixed messages (the format will always be the same). Then ...
3
votes
2answers
809 views

Function pointer or abstract class? [closed]

I need to implement callback in my C++ library. The "proper" C++ way of doing it would be to create an interface (or pure abstract class) and pass it to interested party. I'm wondering though, would ...
3
votes
1answer
679 views

Port manipulation using C code

I'm trying to manipulate the ports of Arduino using C code. I have attached an LED to pin 8 and a tact switch to pin 13 (with a pull down resistor). The code works fine, and the results are printed on ...
3
votes
1answer
267 views

Knowing the Arduino memory capacity

I am using Arduino uno. My data is storing into EEPROM whenever i run my program, it will store multiple data depend on the loop. For my program it calculate 10 sample in 0.1 sec, so 100 sample in 1 ...
3
votes
2answers
627 views

What is the Arduino compiler's version of `__unused` for function parameters?

When I first started with the Arduino environment I noticed that it had File | Preferences | Compiler Warnings set to None, so I set it to All - and there were many, many warnings in the supplied ...
3
votes
1answer
2k views

Reading a .csv file element wise

I'm fairly new to arduino programming and C/C++. I would like to read a .csv file element wise, and send each element via. a nRF24L01 tranceiver to a raspberry pi. Right now I'm able to read the .csv ...
3
votes
1answer
9k views

How to use C Libraries for Arduino code

I have a code in Visual studio that I want to implement in Arduino. But there is a problem. Many libraries usable in Visual Studio aren't usable in the Arduino IDE. How can I use them in my Arduino ...
3
votes
1answer
349 views

ctc mode on atmega 328

I'm trying to use CTC mode on Arduino 1 but I have the following problem. I need to generate an interrupt on threshold B and A and I have set the prescaler to 1 since I want to generate interrupt A at ...
3
votes
2answers
373 views

Problem with using pure C code to program default UART (UART0) in Arduino Mega

Can I code default serial port in Arduino Mega (USART0, I assume) in pure C? I mean to set up it and configure directly by ATmega's registers? I'm asking because I'm trying to do it and I have a ...
3
votes
1answer
191 views

Making an automated watering system with Arduino

I am trying to make an automated watering system using an Arduino. Here is my wiring diagram: And here is my circuit wired up: Here is the code that I'm using with Arduino. The code seems alright ...
3
votes
1answer
2k views

How to Implement Simple, Quick HMAC on Arduino

Hi I am a research student working on securing the communications in Controlled Area Networks (CANs), and I am using Arduinos to simulate one of these CANs. My goal is to use HMAC to implement ...
3
votes
1answer
199 views

How does Arduino IDE for mac deal with functions in other files

I'm a longtime C programmer. I've also done a little C++, a little Java, and a LOT of Objective-C, but am fairly new to the Arduino platform and it's IDE. So far all my sketches have had a single ...
3
votes
4answers
2k views

What are the tools that I need to program the Arduino in C?

The Arduino IDE by default is oriented towards C++. The linker for example requires .cpp files and not .c files, otherwise it leads to errors during the linking process. See name mangling if you want ...
3
votes
2answers
967 views

Formula for decision making when in contact with an obstacle using Arduino

I am currently working on an obstacle avoidance robot project and I have seen numerous algorithms for obstacle avoidance a very good example is this Obstacle avoidance algorithm [Editor's note: by ...
3
votes
1answer
783 views

Using map for DC motor instead of servo

I am trying to use map command which is used to power servo 180 degrees as the potentiometer moves... in fact what i want to do is just when i adjust my potentiometer to zero; stop the dc motor then ...
3
votes
1answer
13k views

How to append float value of into a string ?

I have a float variable lng = 33.785469 and lat = 78.126548. Now can I convert them to String and append in a String variable "my_location" as "your location is \nlng = 33.785469 \nlat = 78.126548". I ...
3
votes
3answers
6k views

AES Simplified for Arduino - Having hard time achieving desired result

Okay, here's the story. I'm not very familiar with how Arduino works but learning. I have a project that requires AES encryption on the Arduino Uno. As per a previous question we managed to figure out ...
3
votes
1answer
936 views

Cannot read from 2 I2C slaves consecutively

I am currently trying to communicate between 3 Arduinos using I2C. One of them acts as a master, while the rest act as slaves. I can request data correctly from the master. But if I were to do 2 ...
3
votes
1answer
70 views

Informations lost in a string

At first, I sorry if I make some English faults but I'm French. So, I'm making a connection between a client and an Arduino Uno. I receive all data that I need but when I send a response to my ...
3
votes
1answer
855 views

Arduino throwing error while using modbus RS485 code

I have been trying to make a communication with my industrial drive. All I want to do is read a few values of drive, like current, voltage etc. For that I am using a library: I don't understand why ...
3
votes
0answers
870 views

Send custom 802.11 data frame with ESP8266 [closed]

I would like to send raw 802.11 data frames in order to transmit pictures with the ESP8266. I have the Espressif SDK 1.3 and so far I have tried to construct a packet and send it with ...
2
votes
2answers
1k views

Is Arduino IDE enough to program with C or C++?

I am using Arduino IDE to program my ATmegas with bootloaders. I can directly manipulate ports, use timers, interrupts, PWM pins and timers, etc. Everything is working. But this question arises: Does ...
2
votes
4answers
653 views

How to get elapsed seconds since Jan 1, 1970?

I am building a time-critical system using Arduino. Is there any way to get the elapsed seconds like time.h of C in Arduino? I tried time(NULL) but it returns 0. Then moved forward to use now() in ...
2
votes
2answers
277 views

Millisecond timestamp (13 digits) in Arduino

How can I store a 13 digits int in Arduino? For example, current timestamp is: 1500666822235 An uint32_t can only hold 10 digits max. 64 bits integer does not seem to be supported on RFduino.
2
votes
4answers
14k views

New to Arduino: Should I learn C, C++ or both (C & C++)?

From what i've researched here is my thoughts on both C++ I heard that you can create libraries using C++ in arduino. And you can use the Arduino IDE to do that stuff. Here is the proof http://...
2
votes
2answers
537 views

Print with round towards zero instead of round to nearest

When printing with one decimal place, Arduino's Serial.println() rounds numbers like 123.89 to “123.9”. Is there any way to change the rounding mode? For some reasons I want the value to be rounded ...
2
votes
2answers
1k views

The most effective way to format numbers on Arduino

I made a big search about how to Format Numbers with the Arduino. I want to format unsigned Longs into a String in this format: "23,854,972". The most of the snippets I found work only with the ...
2
votes
2answers
5k views

Where can I see the output of printf?

I would like to know where I can see the output when I use the command printf. I am programming using the Arduino interface. Update I'll add a few lines of code for better understanding: #include &...