Questions tagged [float]

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

Filter by
Sorted by
Tagged with
12
votes
2answers
61k 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
3k 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() ...
7
votes
3answers
54k 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 ...
4
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; ...
4
votes
3answers
39k 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 ...
4
votes
1answer
27k 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
6answers
13k 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 ...
2
votes
2answers
1k 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
91 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
1answer
54 views

Converting from Float to Int yielding weird results. What am I doing wrong?

So I am trying to take GPS data with a Neo 6M gpsmodule (that is what is covered up by the square for privacy sake) and process it by adding/multiplying to get large integers representing the GPS data....
2
votes
2answers
1k 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
4k 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
800 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; ...
2
votes
1answer
52 views

Float mulitplication Returns ovf or -0.0 for small whole float numbers

I wrote a simple multiplication function for matrices. Originally my matrices are stored in a single array in format (row, column): (row0, col0), (row0, col1), (row0, colN), (row1, col0), ... (rowN, ...
1
vote
4answers
898 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
18k 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
278 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
308 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
66 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
430 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
743 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
1answer
1k 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
242 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
255 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
852 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
1answer
31 views

.toFloat() giving incorrect anwsers

I am broadcasting a fixed value float over a HC-12 radio which is then received by another HC-12 radio. I am then trying to convert that String to a Float which requires 6 decimal places. However, ...
1
vote
2answers
3k 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
3k 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
2answers
427 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
1answer
82 views

Can not receive data from python code

I want to send 4 float numbers from a python code to an Arduino, I was trying to send it via serial and i have some problems here is my python code: import time import serial import struct data = ...
1
vote
2answers
56 views

Code help in Arduino ( Serial data)

I Need a help in this code I am trying to assign the serial.write(OutData[i]) to byte data[]. Can anyone help me assign it. Here is my code #define ECHOPIN 11// Pin to receive echo pulse #define ...
1
vote
0answers
168 views

How to store an array of doubles? As array of doubles, Strings or const char *? Then convert back to use?

This seems like an old, solved problem, but I can't find any simple answers. I'm reading latitude and longitude data as Strings from a file (about 50 points), but they are really double float numbers. ...
1
vote
0answers
1k views

How to transmit Float sensor values via NRF24L01 module?

I'm trying to figure out a way to transmit four sensor values: Voltage, Current, Power and consumption but I'm unable to do that. Yet, my syntax is correct... what am I missing? #include <SPI.h&...
1
vote
0answers
26 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
311 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
235 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
4k 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
31 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
162 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
2k 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
18k 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
151 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
2k 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
735 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
474 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
1answer
46 views

I am tying to split a float variable into bytes and then re combine to the original float

Here is the code I am currently using, there have been many and various alternatives I have tried all so far without success, this being the latest incarnation sitting within my main program loop (...
0
votes
4answers
427 views

String to float on Arduino

I'm trying to convert a String to a float but I'm running into issues with precision, even with the Arduino's own String example I'm getting bad results. Example 0: Input string: 1.234567 After ...
0
votes
1answer
65 views

hexadecimal 1 to float 1 - Compare the float 1 with a predefined float 2 - If the float 1 and float 2 are the same - Print hexadecimal 2

I want to input a hexadecimal data from cool terminal say like (05 00 02 03 00 04 00 E5) And convert the data to a float value say 45.3. Now that I have to preassign a float value say 45.3 in my ...