Go Down

Topic: Serial.readBytesUntil(); (Read 8056 times) previous topic - next topic

Shinyhero

I would like to kinow whar is the code to read the serial until the enter key is pressed
here is my code:
Code: [Select]

while(!Serial.available()); byte choix = Serial.readBytesUntil('\n');

but i've got an error

Alain46

Check Arduino documentation readBytesUntil(). This function returns an array not a byte
Un programme qui se compile sans erreur n'est pas forcément un programme qui fonctionne.

Shinyhero

Check Arduino documentation readBytesUntil(). This function returns an array not a byte
what should i had int the command
Code: [Select]

Serial.readBytesUntil(character, buffer, length)

hbachetti

You should read the documentation :
https://www.arduino.cc/en/Reference/StreamReadBytesUntil

Code: [Select]
void loop() {
 char buffer[16];
 while(!Serial.available());
 int size = Serial.readBytesUntil('\n', buffer, 16);
 for (int i = 0 ; i < size ; i++) {
   Serial.println(buffer[i], HEX);
 }
}

Hope it helps ...
Linux is like a wigwam: no Windows, no Gates, and an Apache inside ...

Robin2

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up