[SOLVED] no serial output with too long sentence

Hi everyone,

I'm trying to use an arduino with the servo driver ssc32. I'm using an arduino mega 2560 and the serial speed is 115200.
I have to send sentences that desribe each motor index and value then the speed that this group movement will take. A sentence to tell the motors 2 and 7 to go to position 2000 (uS) in 1 second will be:
"#2 P2000 #7 P2000 T1000\r"
It would work fine with this example but not when I use 18 motors : the frame length is about 150 chars.
I think it is the the arduino's fault (or mine I hope) because sending the sentence to a computer does the same thing : not even a truncated data is sent.
Here is my code :

char _seq[100];
//ssc32 is an alias for Serial (print on the computer) or Serial1 (where the ssc32 is plugged)
int Motors::motorToSeq(int motor, int value)
{
   ssc32.print('#');
   ssc32.print(((motor/10)%10));//low level stuff because I thought that the sprintf did not work
   ssc32.print((motor)%10);
   ssc32.print('P');
   ssc32.print((value/1000)%10);
   ssc32.print((value/100)%10);
   ssc32.print((value/10)%10);
   ssc32.print((value)%10);
   //delay(10);
}
   
void Motors::write()
{
   for(int i = 0; i<9; i++)//works with 6, not with 9
   {
      motorToSeq(i,(int)(motors[i]._next_value));//the second parameter is between 1000 and 2000
   }
   sprintf(_seq, "T%d\r", _speed);
   ssc32.print(_seq);
}

It did not work with the commented delay and I prefer to avoid any delay (only if possible). Using flush() did not arranged anything.
Any idea or work around ?
Thank you.

A sentence to tell the motors 2 and 7 to go to position 2000 (uS) in 1 second will be:
"#2 P2000 #7 P2000 T1000\r"
It would work fine with this example but not when I use 18 motors : the frame length is about 150 chars.

It appears that nothing happens until the receiver gets the \r. That indicates, to me, that the problem is on the receiver end - the serial buffer there is too small.

Thank you for your reply.
I forgot to notice that when I send data to the computer, I use println which will add a \n and a \r after each part of sentence. Moreover, if I want the arduino to output something like "I'm not on mute" elsewhere in the code with println, it will be sent when the sentence is short but not when it is long. This is true even if the long sentence is sent over Serial1 and "I'm not on mute" is sent over Serial.

You may find this interesting:

http://www.hobbytronics.co.uk/arduino-serial-buffer-size

mickael86:
Thank you for your reply.
I forgot to notice that when I send data to the computer, I use println which will add a \n and a \r after each part of sentence. Moreover, if I want the arduino to output something like "I'm not on mute" elsewhere in the code with println, it will be sent when the sentence is short but not when it is long. This is true even if the long sentence is sent over Serial1 and "I'm not on mute" is sent over Serial.

Seeing only snippets it is hard to say, but if you turn interrupts off this could happen.

Thank you, I forgot that I disabled interrupts when initializing the motors then enabled them because I was not using the SSC32 previously. Removing this stuff solved the problem. The second solution may be useful too but I did not test it. On linux, I think the file to edit is /usr/share/arduino/hardware/arduino/boards.txt if someone has the same issue.
Thank you again, I did not think it could be so simple.