Go Down

Topic: Serial - Midi Trouble reading incoming serial data. (Read 466 times) previous topic - next topic


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.


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: [Select]

  if(Serial.available() < 3)return;




Go Up