About Serial.read

The document show me that Serial.read returns the first byte of incoming serial data available .
ex: I send “hello” to arduino,it returns me ony “h”.
Is there any way to get more byte per one time?



If you look at Serial.read, it returns an int. The only reason it doesn't return a char is because if there is no data to read, it returns -1. It can't return more than one characer at a time.

Is that a problem for you?

Hint : you read it more than once........

thank u for reply! last question,i know it returns int,so how to change it to character in the arduino?

With a simple 'char' cast.

could you show me a example?

OK,I see now,thank u

Below is some simple test code that captures the serial input into a string and sends it back to the serial monitor.

// zoomkat 8-6-10 serial I/O string test
// type a string in serial monitor. then send or enter
// for IDE 0019 and later

String readString;

void setup() {
        Serial.println("serial test 0021"); // so I can keep track of what is loaded

void loop() {

        while (Serial.available()) {
          if (Serial.available() >0) {
        char c = Serial.read();
        readString += c;}
      if (readString.length() >0) {

int x; char y; y = char(x) ;

to convert from asci to char

char c;
c = Serial.read(); // assume it reads N
y = c -'0'; // or else it will be 78

does this help :-/?