Which is why I asked the question. I'm sorry....are questions not allowed?
You, sir, are the reason people hate forums. Why don't you take a second to get down off your high horse and realize that people make mistakes. If I did, I apologize. But there is no reason to be a complete jerk.
I don't see any interrogative there.
I see a statement of fact, however tenuously one defines "fact".
1. Here is a short tutorial based on Fig-1 to offer you a basic understanding of the Serial Communication between the Arduino IDE's Serial Monitor and UNO Board.
Figure-1:
(1) You enter A in the InputBox of Serial Monitor and click on the Send Button, the 8-bit character code 0x41 is transmitted towards UNO using 10-bit asynchronous frame.
(2) UNO receives the frame, discards the START/STOP bits and then saves the 8-bit character code (0x41) of A into the FIFO-type Serial Buffer.
(3) If you choose Newline option for the "Line ending Box" and then enter A in the InputBox and then click on the Send Button, the UNO will receive/save character code of A (0x41) first in Serial Buffer and then will save character code of Newline (0x0A = '\n').
(4) If sending 12.34 with Newline option from the InputBox of the Serial Monitor, then the UNO will receive/save the character codes of '1', '2', '.', '3', '4', and '\n' into Serial Buffer.
2. You can upload the following sketch to extract the numerical value of the original float number (12.34) and save it in variable float y.
char myData[10] = {0};
void setup()
{
Serial.begin(9600);
}
void loop()
{
byte n = Serial.available();
if (n != 0)
{
byte m = Serial.readBytesUntil('\n', myData, 10); //myData[] holds all characters except '\n'.
myData[m] = '\0'; //insert null charcater
float y = atof(myData);
Serial.println(y, 2); //shows: 12.34
}
}
3. Output
12.34
45.89
12.57
4. Serial.parseFloat() method is faster compare to Serial.readBytesUntil() method.
float y;
void setup()
{
Serial.begin(9600);
}
void loop()
{
byte n = Serial.available();
if (n != 0)
{
y = Serial.parseFloat();
Serial.println(y, 2);
while(Serial.available() != 0)
{
(void)Serial.read(); //clearing the Serial Buffer
}
}
}
Are you sure abou that?
Do you suggest to add the pre-amble (synchronization pattern) and then the checksum and then the terminating character in the sending message?
No, I'm talking about writing beyond the end of an array.
(It's not a trick question - I genuinely don't know because I never use functions like this)
Then we can use the following form of the function:
byte m = Serial.readytesUntil('\n', myData, sizeof myData-1);
Really? Did you not read:
Or are you blind?
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
