My question is really not about any code, but about the exact arduino functions.
in Arduino Reference:
about Serial.read(): its return value seems integer; Shown as below quotes:
"the first byte of incoming serial data available (or -1 if no data is available) - int"
if I am correctly understand Serial.read() return properties, any float numbers send to serial port and received by arduino by using Serial. read() would be converted to integer.
I am wondering how do I send a float number to be received by arduino as it is?
In general idea arduino is all about ints... Everything it's actually doing is in INTs.. The question is how to convert or expression the needed int in different variable HEX or DEC or watever... So ... think.
Thanks BulldogLowell. I just test your method and it did work.
The only issue is : in matlab, I should convert num into string. and In arduino, parsefloat will work.
Im saying that the arduino does any operations and math in INTs everything you know any character inside the arduino is actually int...it's like a base for everything. So if you sending to sereal 0.3 as a char and for you it's like one didgit. But for arduino it actualy 3 ints. one = 0 two=- three = [3].. a nd they look like one =-48 in ints second and so on... So also if sending 0.3 Serial.read will read 1 by 1 you need then put in to the array if you want get int as o.3 or use Strings... So man read more
how to convert the return of Serial.read() into float format directly and get the accurate inputs?
The serial port sends/receives bytes without regard as to what they are supposed to represent. You need to capture the bytes sent to the serial port, then apply some function that turns the bytes sent into what you want the bytes represent. 0.3 is just three ascii characters just as the word the is three ascii characters. You need to convert the bytes into what you expect them to represent.
mouse123:
Thanks BulldogLowell. I just test your method and it did work.
The only issue is : in matlab, I should convert num into string. and In arduino, parsefloat will work.
great.
as discussed, arduino sees bytes coming in... it is up to you to parse the data into an int, float, string, String, etc...
Serial.parseInt and Serial.parseFloat are easy to use but not that flexible, if you want to do a lot with Serial.