Go Down

Topic: readBytesUntil What am I missing? (Read 8 times) previous topic - next topic

westek

Jul 12, 2012, 09:54 pm Last Edit: Jul 12, 2012, 09:58 pm by westek Reason: 1
Greetings,
I am using the Arduino IDE 1.0 on a Mac running OSX 10.7.4

The hardware I'm programming is a Arduino Uno Rev 3.

I'm trying to read an unknown length string of ASCII characters terminated with a line feed from the UART on the Arduino from an external source. Lets just say from the Serial monitor in the Arduino IDE. I assumed readBytesUntil would be the simplest way but I keep getting the error: no matching function for call to 'HardwareSerial::readBytesUntil(int&, String&)'

I have done my due diligence trying to understand the error, but I'm just not getting it. So here is my simple code.

Code: [Select]
// Library Code To Include.
#include <OneWire.h>
#include <LiquidCrystal.h>

// Compiler/Library Initialization.

// Tell Library What Pins The LCD Is Connected To.
LiquidCrystal lcd(12,11,5,4,3,2); // RS,Enable,D4,D5,D6,D7

//Initialization/Setup Code Begins Here

void setup() {
  Serial.begin(9600);   // Start The Serial UART at 9600 Baud. Test Code Comment Out.
  lcd.begin(16,2);      // Tell Library How Many Columns And Rows The LCD Has.
}

void loop() {
  String serialdata = "0";
  int lf = 10;
 
 
  Serial.readBytesUntil(lf, serialdata);
 
  lcd.setCursor(0,0);
  lcd.print(serialdata);
 
}


Can anyone point me in the right direction or am I not understanding the usage of readBytesUntil. There is no example usage on the Arduino website. Thank you in advance for any help or direction.


westek


http://arduino.cc/en/Serial/ReadBytesUntil


Thanks but that was the first place I checked... There is no example there. No explanation of the error I'm getting on that page. Please don't take this the wrong way, but that really wasn't helpful.

WizenedEE

Quote
buffer: the buffer to store the bytes in (char[] or byte[])


The function expects either a char[] or a byte[]. String is neither of those.

abrookfield

#4
Jul 12, 2012, 10:21 pm Last Edit: Jul 12, 2012, 10:23 pm by abrookfield Reason: 1
String serialdata = "0";
char serialdata[80];

// Serial.readBytesUntil() returns the number of characters read into the buffer. A 0 means no valid data was found
nchars=Serial.readBytesUntil(lf, serialdata, 80);

Go Up