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.

Filter by
Sorted by
Tagged with
14
votes
5answers
62k 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
2answers
38k 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 '...
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
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
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
8k 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
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
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
4k 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
2answers
492 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 =...
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
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
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 ...
3
votes
3answers
691 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
782 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
844 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
2answers
208 views

Using an external header file

I have a project that is part of a larger repository, and shares header files with non-Arduino C programs. I know that it's possible to use these headers by copying them to the libraries folder, or ...
3
votes
2answers
3k 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 ...
3
votes
1answer
683 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
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
352 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
1answer
208 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
1answer
226 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 ...
3
votes
2answers
1k 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
16k 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
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
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
937 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
906 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
1k 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
728 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
312 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
15k 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
626 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 &...
2
votes
4answers
168 views

How to compare a string

How to compare a string coming from serial monitor with some predefined text stored as a local variable? If I say: int led = 2; String a = " abcds"; void setup(){ Serial.begin(9600); } void loop(...
2
votes
1answer
5k views

Arduino server to read from multiple clients

Socket programming question here. My interface comprises of an Android device(client), A wireless module hosting an access point, and an Arduino Uno(server). My Android client class works when 1 ...
2
votes
2answers
455 views

Digital Band pass filter arduino 1100-1300 Hz

For a project I need to design an digital band pass filter. I started of with this in Matlab: wch=1100*2*pi; wcl=1300*2*pi; sys=tf([1/wch 0],[1/(wch*wcl) 1/wch+1/wcl 1]) sysd=c2d(sys,9615,'tustin') ...
2
votes
1answer
540 views

Arduino can't multiply?

I have a value I'm taking from a sensor module, which is 2500 when the sensor is facing a light source. This reads to my code and can be saved perfectly fine. When I try to find the weighted average ...
2
votes
2answers
1k views

Arduino Interrupt Debouncing

I have an issue with debouncing. I am using a MCP23017 as an I/O-extender with an Arduino. This uses I2C to communicate with each other. A variable amount of switches is connected to the MCP23017 (0-...