Go Down

Topic: Problem sending ACSII from MAX to Arduino for LED control (Read 1 time) previous topic - next topic



?I've been working on this project for some time now and I'm at a point where the thing works, but it is not always reliable.?I have MAX sending a string of ASCII representing RGB values to arduino. Arduino then unpacks this string and assigns the values to PWM pins 9, 10 and 11 to mix color using a high-powered RGB LED. I have been able to do this, but am noticing that every so often I get a color flicker in from the LED. It is almost as if every so often a value in the string is assigned to the wrong pin. It feels like a slip up in assigning values, 70% of the time things work quite well.

Attached are the MSP and Arduino files. Please let me know if you have any suggestions.?



Oooops.  The MAX file is attached here.


Code: [Select]

Why not just do
Code: [Select]

Code: [Select]
  while(inByte != '*') {
    inByte = Serial.read(); //read data and wait for an asterisk character

Doesn't matter that there is nothing to read, does it?

Code: [Select]
    char blackLed[4]; //create a string to hold the value for the red part of the string
Yeah, right. Store the red data in blackLed. Makes sense to me. Not!

Code: [Select]
    char redLed[4]; //create a string to hold the value for the red part of the string
No, wait, you're storing the red data in redLed.

Code: [Select]
    char greenLed[4]; //create a string to hold the value for the red part of the string
No, wait, you're storing the red data in greenLed.

If you are going to have useless comments, they should at least be correct.

The real problem, though, seems to be that you have a start byte but no end byte. Why not? Reading properly delimited data (and using strtok() to parse it) is much simpler than hoping all the data arrives in the correct order.
The art of getting good answers lies in asking good questions.


Thanks Paul,

I appreciate your input.  I am looking into strtok() for dealing with the string. 

I learnt that there is a certain percentage of error when sending data strings through serial and that the best way to handle that is to write a portion of code to ignore the faulty string.  What do you reckon?  I wish I could view serial data sent from Max MSP and received by Arduino at the same time. 

Thanks for pointing out that mix up in the comments.  I'm not sure why you think those comments are useless though.  I find them quite helpful, those ones specifically . . . .

I will post any updates when the breakthrough happens.

Go Up