Go Down

Topic: Serial - Midi Trouble reading incoming serial data. (Read 473 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

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131