Arduino Forum upgrade scheduled for Monday, October 20th, 11am-4pm (CEST). Sorry for the inconvenience!
Pages: [1]   Go Down
Author Topic: Help me understand Serial & processing  (Read 585 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 8
Posts: 296
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I want to wrap my head around this and maybe you can give some insights...

From my arduino, I'm Serial.print(a) where a = (0 - 2000).
So serial send out one byte at a time so 2000 is not possible so it sends out 2 bytes?

What should I be listening to from processing, 2 bytes? And then reconstructing the bytes to a number value?

Or is it easier to read from the arduino as a string? So I need to end my string value with a 'T' (character) so processing would know that's the end of the string?

Thanks.


Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 671
Posts: 51669
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In the absence of any qualifiers (the 2nd argument to Serial.print(), the value is converted to a string, and sent one character at a time.

Since the value you want to send is larger than what fits in a byte, you would need to store the value in an int, and then use highByte() and lowByte() to extract the two bytes. Then, you would use Serial.write() to send the two bytes.

If you send strings (the default behavior), you can send them using println(), so that a carriage return/line feed is appended, and have Processing look for that combination as the terminator.

Quote
What should I be listening to from processing
Whatever the Arduino is sending.
« Last Edit: November 27, 2010, 03:28:48 pm by PaulS » Logged

0
Offline Offline
Sr. Member
****
Karma: 8
Posts: 296
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks, I think that answered my questions.
Logged

Pages: [1]   Go Up
Arduino Forum upgrade scheduled for Monday, October 20th, 11am-4pm (CEST). Sorry for the inconvenience!
Jump to: