0
Offline
Newbie
Karma: 0
Posts: 23
Arduino rocks
|
 |
« on: January 22, 2011, 11:13:56 am » |
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? thanks.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Online
Brattain Member
Karma: 137
Posts: 19017
I don't think you connected the grounds, Dave.
|
 |
« Reply #1 on: January 22, 2011, 11:14:14 am » |
No.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 23
Arduino rocks
|
 |
« Reply #2 on: January 22, 2011, 11:18:48 am » |
:o
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Online
Brattain Member
Karma: 137
Posts: 19017
I don't think you connected the grounds, Dave.
|
 |
« Reply #3 on: January 22, 2011, 11:26:53 am » |
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?
|
|
|
|
« Last Edit: January 22, 2011, 11:32:18 am by AWOL »
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Lancashire, UK
Offline
Edison Member
Karma: 8
Posts: 1988
|
 |
« Reply #4 on: January 22, 2011, 11:31:04 am » |
Hint : you read it more than once........
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 23
Arduino rocks
|
 |
« Reply #5 on: January 22, 2011, 11:34:18 am » |
thank u for reply! last question,i know it returns int,so how to change it to character in the arduino?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Online
Brattain Member
Karma: 137
Posts: 19017
I don't think you connected the grounds, Dave.
|
 |
« Reply #6 on: January 22, 2011, 11:42:49 am » |
With a simple 'char' cast.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 23
Arduino rocks
|
 |
« Reply #7 on: January 22, 2011, 11:48:17 am » |
could you show me a example?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 23
Arduino rocks
|
 |
« Reply #8 on: January 22, 2011, 11:50:29 am » |
OK,I see now,thank u
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Tesla Member
Karma: 50
Posts: 6540
Arduino rocks
|
 |
« Reply #9 on: January 22, 2011, 12:00:32 pm » |
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.begin(9600); Serial.println("serial test 0021"); // so I can keep track of what is loaded }
void loop() {
while (Serial.available()) { delay(10); if (Serial.available() >0) { char c = Serial.read(); readString += c;} } if (readString.length() >0) { Serial.println(readString); readString=""; } }
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 16
Arduino rocks
|
 |
« Reply #10 on: January 23, 2011, 06:25:54 am » |
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 :-/?
|
|
|
|
|
Logged
|
|
|
|
|
|