Questions tagged [float]
A datatype in C/C++ which stores a single-precision floating point number.
82 questions
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 ...
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
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
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 ...
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 ...
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....
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, ...
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
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 ...
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 = ...
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 ...
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
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
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 ...
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 ...
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.
...
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
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 ...
-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 ...
0
votes
2
answers
4k
views
How to send float numbers from python3 with struct to arduino
I have searched several questions and through google but could not find a solution. I am simply trying to send a float number from python3 with struct to arduino or if there is any other ways other ...
1
vote
2
answers
9k
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 ...
0
votes
1
answer
471
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 ...
1
vote
3
answers
8k
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 ...
2
votes
4
answers
454
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 ...
0
votes
2
answers
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 ...
3
votes
2
answers
3k
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 ...
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 ...
1
vote
1
answer
2k
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 ...