Pleasr read this from Arduuino reference. Then You will know.
Serial.read()
Description
Reads incoming serial data.
Serial.read() inherits from the Stream utility class.
Syntax
Serial.read()
Parameters
Serial: serial port object. See the list of available serial ports for each board on the Serial main page.
Returns
The first byte of incoming serial data available (or -1 if no data is available). Data type: int.
I'm sorry but I'm not an expert. So I understood that with Serial.read I can only read 1byte, but my question remains, how can I send and read the float (4bytes)?
I do not have idea, i wouldn't had asked here.
You need to read 4 bytes, glue them together and do some kind if type casting, cheating the compiler to read those 4 bytes as a float. Easy to do in assembler but harder to make it pass the C-compiler.
You can use SerialTransfer.h to automatically packetize and parse your data for inter-Arduino communication without the headace (including floats!). The library is installable through the Arduino IDE and includes many examples.
Here are the library's features:
This library:
can be downloaded via the Arduino IDE's Libraries Manager (search "SerialTransfer.h")
works with "software-serial" libraries
is non blocking
uses packet delimiters
uses consistent overhead byte stuffing
uses CRC-8 (Polynomial 0x9B with lookup table)
allows the use of dynamically sized packets (packets can have payload lengths anywhere from 1 to 255 bytes)
can transfer bytes, ints, floats, and even structs!!
Riemanndiy:
I'm sorry but I'm not an expert. So I understood that with Serial.read I can only read 1byte, but my question remains, how can I send and read the float (4bytes)?
I do not have idea, i wouldn't had asked here.
A simple answer might be to just send/receive the numeric value as a string of characters that represents the numeric value, then convert the string of characters back into the numeric value after it has been received.
I am having issues sending data between Arduino and NodeMCU.
I am using the suggested "SerialTransfer.h" library. In the example sketch "softwareserial_rx/tx_multi_byte" a sruct with multiple fields is sent. When i try this script the char is transferred but the float is depicted as 0.00. When i add an additional integer the integer is also not received correctly. I tried sending only int or float or char and i works without any problem. I really dont understand what is happening since this library is mentioned in almost every post regarding serial communication between two devices and i cant get it to work properly. Would really appreciate some help. Since i am new to this Forum i am not sure if posting the used example code would be of any help in this scenario, if it does, please let me know.