Pages: [1]   Go Down
Author Topic: Serial - Midi Trouble reading incoming serial data.  (Read 378 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset



The above shows the code used to examine the 3 bytes of data that will turn the led on or off (off = 0, on = 127 or other) I'm having trouble getting the system to find the 146 byte being sent to the arduino.

I'm not to familiar with Serial communication or any communication at that matter as I am a novice programmer.
Logged

Offline Offline
Edison Member
*
Karma: 49
Posts: 1670
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your problem is that when SerialEvent is called you are only guaranteed that there is at least one character in the buffer. Your program is assuming that there are three. The function Serial.available will tell you how many characters are in the buffer. One way to fix your routine is to return until there are at least three chars to read. Add this line right after "int bytes[3];"
Code:
  if(Serial.available() < 3)return;

Pete
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks a lot, that's the one smiley-grin
Logged

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

Code:
int bytes[3];
Are the values ints or bytes?
Logged

Pages: [1]   Go Up
Jump to: