Skip to main content

Questions tagged [float]

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

Filter by
Sorted by
Tagged with
1 vote
1 answer
169 views

How do I convert a structure to a char[] for use in Wire.h, or is there a better way?

I need to interface an ATTiny88 MCU configured as an I²C slave with a Raspberry Pi configured as an I²C master. I may be using the wrong approach, but I have a structure consisting of four different ...
3 votes
2 answers
5k 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 to ...
1 vote
1 answer
844 views

Can not receive data from Python code

I want to send 4 float numbers from 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
1 answer
302 views

float miscalculation when int32_t variable is divided by 10 [duplicate]

i want to ask, how to get correct float value from uint32_t or long variable is devided by 10?? long var3 = 1139399025; int a = 3; int b = 10; void setup() { Serial.begin(9600); Serial.println((...
1 vote
1 answer
270 views

Why does the data I send to the server get rounded off and how do I send the entire float instead?

#include <Arduino.h> #include <WiFi.h> #include "WiFiManager.H" #include <HTTPClient.H> #include "ESPAsyncWebServer.h" #include <AsyncTCP.h> float version =...
2 votes
1 answer
952 views

Enable full float-capable snprintf() library with PlatformIO

I want to use snprintf() to format floats to a string. I know the "normal" version of Arduino's avrlibc had all the float-formatting code removed to make it smaller. I also know that at some ...
-1 votes
1 answer
614 views

parseFloat() function [duplicate]

I have noticed that the parseFloat() function returns decimal numbers, but only up to 2 decimal places. Would it be possible for it to return the numbers with more decimal places? In case we need more ...
-2 votes
1 answer
716 views

how to save float with 3 decimal places [duplicate]

i am transmitting sensor data from my atmega328p to my esp8266. The Sensordata has 3 decimal places. The esp8266 sends this data to my pc and there I see only two digits. This is because the data is ...
0 votes
3 answers
1k views

Problem on Sending float number and multiple float numbers

Im having trouble in sending float number and multiple float numbers. Im currently working on project matlab and arduino mkr1000. The situation is that i want to send float number and multiple float ...
1 vote
1 answer
160 views

Float switch is not detected

Good day everyone, forgive me for the shabby drawing I am just panicking, why my float switches are suddenly undetected by my Arduino mega. I've tested all the float switches one by one to confirm if ...
3 votes
4 answers
3k 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 ...
1 vote
1 answer
261 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
1 answer
3k views

Convert float to int error

I am trying to convert 1.06 to 106 by multiplying by 100 but the answer comes 105, I do not know why. Variable ver can be any decimal in this format x.xx float ver = 1.06; int vers = ver * 100; vm[0] =...
5 votes
1 answer
2k views

Serial monitor can't display float and double values with absolute greater than 4294967040=2^32-2^8

I have the following sketch: void setup() {} void loop() { float af = 4294967040.0; float bf = 4294967240.0; double ad = 4294967040.0; double bd = 4294967040.00001; Serial.println(af); ...
2 votes
1 answer
930 views

Convert float to byte, from Arduino to Raspberry Pi i2c

I'm trying to send the temperature value from the DHT sensor to a raspberry pi through I2C. Which is the best way to do it?. The temp value is a float, and I think I have to convert it to byte and ...
1 vote
0 answers
53 views

Math on analog read wrong result

I'm trying to execute a math of analog read but I get some weird result.. I searched about int and floats but didn't understand.. My code is : #include <SevSeg.h> SevSeg sevSeg; int bitsChange ...
1 vote
1 answer
3k 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&...
0 votes
2 answers
203 views

How to use float data from a sensor with the Arduino mouse library

I'm using a gyroscope, which returns angular velocity in floats. I'm trying to use this data with the arduino mouse library. The move function requires a signed character. I'm not what the best way is ...
0 votes
2 answers
877 views

Float to int conversion not working right in method using varargs

I am trying to convert a floating point number to an integer, but it seems like the conversion is not working properly. I am using the math library to calculate the power of 10 based on the number of ...
1 vote
2 answers
7k 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 ...
2 votes
1 answer
898 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, ...
2 votes
1 answer
394 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....
7 votes
3 answers
68k 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 ...
0 votes
1 answer
1k 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
1 answer
5k views

Convert float to hexadecimal value

I am trying to convert a float value to a 4-byte hexadecimal value. For example my input is: 58.5. My expected output is: 426A0000 or like 0x42 0x6A 0x00 0x00. My program is: void setup() { ...
0 votes
1 answer
3k views

How to convert four uint16_t to double float IEEE754?

I am working in a Modbus project where I have to read modbus Holding and Input registers using ESP8266, I am using ModbusMaster232 library. I returns a response buffer array of uint16_t. I need to ...
9 votes
3 answers
86k 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 ...
2 votes
2 answers
220 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 ...
0 votes
1 answer
319 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 ...
1 vote
0 answers
104 views

How to compare an incoming byte from cool terminal as modbus hex value and compare it with a predefined value in set in the program?

My Input from Cool terminal is 05 03 00 01 00 02 94 4F I should be able to read this input 05 03 00 01 00 02 94 4F compare with the same(05 03 00 01 00 02 94 4F). If the incoming value(05 03 00 ...
0 votes
2 answers
8k views

Sending a floating point number from python to arduino

I am trying to send a floating point number from a python script to an Arduino. I am not sure how to do this, especially in a pythonic way. A little bit of research brought me to this very similar ...
0 votes
1 answer
34 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
1 answer
2k 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
4 answers
24k 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
1 answer
2k 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
1 answer
713 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 ...
1 vote
3 answers
1k 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
1 answer
408 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 ...
1 vote
0 answers
371 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. ...
0 votes
2 answers
416 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 ...
1 vote
1 answer
92 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
2 answers
845 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,...
2 votes
3 answers
314 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 ...
0 votes
1 answer
236 views

Can't display the two float values correctly from pyserial on Arduino's LCD

I transported two float values with pyserial to COM3 and Arduino accepted the values. But it displayed the first value correctly on LCD, the second value can't be read and showed "nan" on LCD. ...
2 votes
2 answers
2k 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 ...
5 votes
6 answers
19k 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 ...
-1 votes
1 answer
377 views

How to change the value within a variable using math? [closed]

I'm up to Lesson 11 in the TopTechBoy tutorial: https://www.youtube.com/watch?v=afurKLOqqSg Lesson 11 : http://www.toptechboy.com/arduino/lesson-11-arduino-circuit-to-dim-led-with-potentiometer/ I ...
0 votes
1 answer
4k 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 ...
1 vote
2 answers
660 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
4 answers
5k 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 ...