0

I'm using Serial.readString() to get the data sent from mobile over Bluetooth. It works fine when I send data with a bit delay between sending times. But when I send the data continuosly in a bit faster delay then the buffer will store all as a long string and then return that long string to Serial.readString().

Ex: Sending

10

20

30

40

Receiving

10203040

I want to receive seperate values corresponding to the multiple sending times. Event it's really fast.

10

20

30

40

If that can not be achived, how can I get the latest value only (override all previous values in the buffer). In this case is 40

Community
  • 1
  • 1
Hieu Nguyen
  • 263
  • 2
  • 10
  • Possible duplicate of [Arduino readString(); code runs slow](https://stackoverflow.com/questions/42863973/arduino-readstring-code-runs-slow) – gre_gor Aug 17 '18 at 17:32
  • Why do you use readString ? With read you get the data byte by byte, therefore value by value. – rantan pan Aug 17 '18 at 18:17
  • I used readString as it's convenient and is a built-in solution. We don't need to write another loop to fetch single characters. – Hieu Nguyen Aug 18 '18 at 00:39

1 Answers1

0
Command = Serial.readStringUntil('\n');

Note that \n could be replaced with any character that indicates you want the readString to stop reading. For more info, check the Arduino Docs.

jamesfdearborn
  • 769
  • 1
  • 10
  • 26