Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

Questions tagged [float]

A datatype in C/C++ which stores a single-precision floating point number.

Filter by
Sorted by
Tagged with
10
votes
2answers
44k 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
2answers
2k views

Is there a non-float alternative to pow()?

I've scoured the LANGUAGE REFERENCE in the Arduino web-site, and I can't find a non-Float equivalent to pow() I've got to be missing something big, but for the life of me, I'm stumped! I found pow() ...
6
votes
2answers
48k views

Sending and receiving different types of data via I2C in Arduino

I have found a few good tutorials on how to send and receive data via I2C in connected arduinos. My limitation is now how to transmit different types of data like for instance, long, float, etc. Right ...
5
votes
2answers
1k views

Store floats in and reading them from flash

How do I store floats in flash and how do I read them from there? (I need a look-up table for pairs of float values.) The storing part doesn't seem to be so difficult as this compiles: PROGMEM float ...
3
votes
4answers
1k views

Will an ATmega2560 board be faster than a Uno for hard real-time data logging?

I am designing a hard real-time data logger. The Uno is a bit marginal in processing speed. a) Would it be faster if I changed to an ATmega2560? b) On the datasheet, ATMEGA2560 has 135 instructions; ...
3
votes
6answers
11k views

When is it necessary to use “float” instead of “int”?

I'm very new to Arduino and I am making a code for a pedometer. I have a lot of variables and I have used "int" multiple times, but I just came across a code with "float". Now because my coding ...
3
votes
3answers
24k views

Only 2 decimal places in printed float

There was a similar thread before but it didn't solve my problem. I had an issue with sending GPS data, which is float, and I couldn't receive the float with the same amount of significant figures as ...
3
votes
1answer
20k 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 ...
2
votes
2answers
749 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
3answers
81 views

Is the strange problem I'm having to do with comparing floats?

I have a timer interrupt that controls a stepper motor, on an UNO board. In the interrupt handler it checks the speed of the motor and compares it to the target speed. This allows the motor to ...
2
votes
2answers
820 views

Floating-point without FPU

Since a Floating Point Unit (FPU) is not present in Arduino Uno, I wanted to know how float operations are performed. If it is simulated as integer operations, I want to know how exactly the ...
2
votes
2answers
3k views

Avoiding float math to speed up arduino

I read and heard that the floating point math is much slower than int math. And I saw a converting process in here floath math to integer math So I want to to convert my floating math calculations ...
2
votes
2answers
718 views

Assigning float to 10 decimal place for longitude,latitude

I'm quite a novice in arduino programming. I am doing a small home project and I am using sim808 to obtain GPS data. My question is quite simple but i can't find any solution online. Serial.print("...
2
votes
1answer
2k views

Read data from SD

I have logged some data in my sdcard/FAT32 (format). I can read and display them on the serial monitor but additionally I want to use these data as float. Here is my code: byte index = 0; ...
1
vote
4answers
810 views

Float arithmetic vs. int arithmetic - is there any power penalty?

It is widely known that float arithmetic takes longer (that is, eats more cycles) than fixed-point (or integer, or bitwise arithmetic), and that surely is something to consider for speed- and time-...
1
vote
2answers
17k views

float precision in arduino

I am reading a string which i have to convert into a float with a maximum of precision.I didn't want to use toFloat() function since it make a truncation so i made my own code. My problem is that the ...
1
vote
2answers
129 views

Two floating point values do not get added and printed on ESP-WROOM-32

I have a Olimex ESP32-PoE board which has a ESP-WROOM-32. I just found out a strange behaviour for printing floating point numbers on the board. Sketch void setup() { // put your setup code here,...
1
vote
4answers
282 views

Arduino not adding decimals correctly on double variable

I have encountered a strange behavior today. I can't understand why the sequence is altered after 26.1000. I get a number 0.0001 less than the desired value (26.2124 instead of 26.2125). I need ...
1
vote
1answer
55 views

Anomalous behaviour of ADC, digitalWrite and floating point operations

I'm trying to analyse mic (A0) input, calculate certain spectral lines with Goertzel algorithm to detect a number encoded by DTFM and display it with 8x8 matrix display (max7219 driver). The code ...
1
vote
1answer
390 views

How to speed up

I found that using more float variable in arduino uno(atmega328p) slows it down (very muck that i can get slow response) so, how to speed up it processing ? my data are euler's angle with 2 digits ...
1
vote
1answer
662 views

Assembling a float from an array of bytes

I would like to convert an array of bytes, received from serial, to a float. Let's consider this exemple. I'm sending 0.12 byte-wise from an Android application. The conversion from float to array of ...
1
vote
2answers
218 views

Is this assignment valid or needs casting?

I have this assignment and while i don't get any error not even warning from the compiler. uint16_t Buffer[40000]; for (int n=0; n<40000 ; n++){ Buffer[n] = (0.99 * cos(((2.0*PI)/40000)*n); } ...
1
vote
1answer
220 views

Help avoiding floating point math

I'm using a Texas Instruments DRV2605 haptic controller in my project to drive a LRA vibration motor. I would like to calculate the LRA rated voltage during run time using the formula below as ...
1
vote
1answer
778 views

Max double value or NAN as a sentinel value?

I am in need of a sentinel value to use to assign to a double variable initially. 0 or -1 won't work because these values are valid values in my computation and I need a value that will stand out. ...
1
vote
2answers
2k views

Sending Float values from Python to Arduino via serial communication

I want to Control the current flowing through a circuit using an Arduino. I have trained a PID controller for this purpose. I am using a current sensor to determine the error. It runs successful on my ...
1
vote
4answers
2k views

Send serial command and wait for reply

I am new to Arduino and have tried all kinds of code for attempting to achieve this. None with any luck, however. I feel that it should be a relatively easy task and therefore, figured that someone ...
1
vote
1answer
793 views

IEEE 754 for integer

Maybe is to easy to answer but i don't know it. I know IEEE-754 is for float values and double but i don't know if is exclusive for those type. I use this to convert float and works fine i have ...
1
vote
2answers
352 views

FastLED int + float problem

I'm working on a code based on PaletteCrossfade.ino example. But I found the motion speed too fast. It's stated in this: static uint8_t startIndex = 0; startIndex = startIndex + 1; /* motion ...
1
vote
0answers
25 views

Local variables scope anamoly

I have this simple function that produces 2 float values sum and product from which i calculate another varaible NodePrio. I had the value of NodePrio coming wrong so i decided to put in some console ...
0
votes
3answers
112 views

All floats feedback a rounded down integer

So I am very confused at the results I am getting. It seems that floats aren't working properly, and I don't understand why. I was trying to read a temp sensor and convert the reading to celsius. ...
0
votes
2answers
172 views

Make a float using integers [closed]

I want to make a floating point number that has only one decimal point. I have separate integers for both side. Ex: int n1 = 8; int n2 = 2; I want to make 8.2 as float value using separate ...
0
votes
3answers
3k views

How to use a coma as the decimal separator?

I have a LCD that displays a float variable. I would like to show a comma instead of a dot as the decimal separator. float temp = 23.50; lcd.setCursor(0, 0); lcd.print(temp); I want to show 23,50 ...
0
votes
1answer
30 views

Cannot understand why this code work but this not

I've done a simple aurduino sketch, I have this code, and this don't work: #define voltageInput A0 int qntR; float mr; float qr; float Distanza; void setup() { // put your setup code here, to run ...
0
votes
1answer
60 views

How to write a float value EEPROM

I'm using this library for my DS3231 which have a Atmel 24C32 on it. i have a float value which increases by 0.5, like: 27.50 28 28.50 ... the code is like this: float lowTemp= 10.5 float ...
0
votes
1answer
1k views

build fixed size strings from floats

This is likely a duplicate, but I couldn't find the original question. This is really basic, but just can't figure it out. I'm trying to combine a few char arrays together. This is what I've tried so ...
0
votes
4answers
14k views

How to cast float into four bytes?

I'm trying to save GPS coordinates to an EEPROM. In this example I feed it the latitude of 56060066 as the argument float x void writeFloat(unsigned int addr, float x) { byte seriesOfBytes[3]; *(...
0
votes
1answer
61 views

Specific formatting of floats and converting them to an array of chars

I have an oled display which can only display 4 digits + decimal point. I need a way to format the number into 4 significant figures; Then I need to convert that into an array of 5 chars (4 digits and ...
0
votes
2answers
1k views

Storing byte array from serial and converting to a floating point number

I have tried getting my Arduino to communicate with another device, to no avail. The command A, when sent via serial to the device, triggers it to respond with 8 binary bytes with the first 4 ...
0
votes
2answers
643 views

float not a float

I am trying to read a SDM220 meter on my solar setup. I've been reading it using Modbus SCADA, so know it all works ok. But I want to read it with my Arduino Mega 256. My problem is that when I run ...
0
votes
4answers
379 views

how to get precise value from float variable?

#include <NeoSWSerial.h> //#include <SoftwareSerial.h> #include <AltSoftSerial.h> #include <NMEAGPS.h> NeoSWSerial GSM(2, 3); // RX, TX: Connect TXD to RX & RXD to TX ...
0
votes
2answers
135 views

How to display float variables on oled display (0.96'')

I have a similar problem than the discussed here : How to display variables on 0.96" OLED with u8glib library? I'd like to know how can I show float variables in place of int variables. What ...
0
votes
1answer
62 views

Rounding float number

I want to enable user to change the duration of PWM from 0 to 255, the number should be in minute and increase/decrease with two push buttons. (X) x 255 / 60000 = minute In above example each time ...
0
votes
1answer
1k views

Arduino: load variables with values read from SD card

I am having a bit of trouble loading values stored on an SD card and assigning them to variables within my program. I can achieve this as one big block of data, but would much prefer them to be saved ...
0
votes
1answer
189 views

FastLED + structs + PROGMEM strange behavior

I'm afraid I have to post a lengthy bit of code, because I can't pinpoint what's causing my issues – in short, it appears repeatedly adding float position + float speed in a struct ends up borking the ...
0
votes
1answer
981 views

Storing latitude and longitude floats as chars with specified precision

I am receiving lat and long data from a GPS and want to store these numbers in the middle of a sequence of chars. E.g. lat = -23.123456 long = 135.123456 I am after something like "Your coordinates ...
0
votes
1answer
250 views

Can anyone help me spot where my buffer overflow might be occuring?

I'm using dtostrf() to transcribe a float into a string for my touchscreen. I'd leave it as a float, but my screen orientation library function only works with a string. So I have a char array, then ...
0
votes
1answer
2k views

DS18B20 Temperature Sensor return as float function returning null 50% of the time

I just got an DS18B20 Temperature sensor and am trying to modify the example code to use a function instead. Below is my getTemp function. It's working but returning results with a 0 value part of the ...
0
votes
1answer
58 views

Problem assign float to an embed class within the Linked-list libary

I have successfully implemented some code which uses a linked-list. Everything is working, except assigning a value to a float within the embeded class. When I run the code below, I get the expected ...
0
votes
1answer
179 views

Serial, Numbers sent as Floating Point and Characters are different at 1e-8 level

I have some code that generates random numbers on the Arduino, it then sends these random numbers firstly, using Serial.print(float data,int lenght) and as a floating point number using the following ...
0
votes
1answer
563 views

Saving data in a globally declared float array

I'm trying to send 60 float values via serial. Numbers are provided by an accelerometer and saved in a 240 bytes-long array. The array is sent to a function and these values are then copied in a ...