Questions tagged [float]

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

Filter by
Sorted by
Tagged with
5
votes
1answer
1k 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
1answer
107 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
0answers
25 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 ...
0
votes
1answer
58 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
2answers
31 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
2answers
81 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
1answer
252 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
1answer
122 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
1answer
43 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
1answer
329 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
1answer
684 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
1answer
259 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
4answers
1k 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
2answers
91 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
1answer
173 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
0answers
39 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
1answer
1k 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
1answer
32 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
2answers
3k 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
663 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
302 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
3answers
491 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
1answer
212 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
0answers
219 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
1answer
2k 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
2answers
302 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
1answer
77 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
2answers
404 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
3answers
99 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
1answer
145 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
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 ...
-1
votes
1answer
131 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
1answer
3k 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
2answers
2k 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
2answers
5k 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
1answer
333 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
3answers
5k 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
4answers
330 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
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 ...
3
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 ...
1
vote
4answers
4k 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
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
253 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); } ...
6
votes
3answers
52k 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 ...
0
votes
2answers
780 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 ...
1
vote
4answers
532 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 ...
5
votes
4answers
2k 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; ...
2
votes
2answers
876 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("...
5
votes
6answers
15k 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
vote
2answers
710 views

Splitting a float into bytes for storage in FRAM (like EEPROM) [duplicate]

I'm trying to write floats to I2C FRAM (like I2C EEPROM) but without result. I tried with this function but I lose all number after the decimal. Thank's for replying. This for writing: float ...