Balancing robot for dummies

Hi bryanpearson
Welcome to this thread,
no doubt Patrik will soon jump in to answer your question

@Patrik

What do you think about that? And in your opinion what baud rate should we use if possible?

I will experiment and be back by the end of the week

I ran this (really ;)) striped down version of KasBot

int   STD_LOOP_TIME  = 9;             
int lastLoopTime = STD_LOOP_TIME;
int lastLoopUsefulTime = STD_LOOP_TIME;
unsigned long loopStartTime = 0;

void setup() {
  Serial.begin(XXXXX);
}

void loop() {
// ********************* print Debug info ********************************
  Serial.println("The quick brown fox jumps over the lazy dog");
  Serial.println("The lazy dog doesn't care and keep sleeping");
  Serial.print("Loop:");        Serial.print(lastLoopUsefulTime);
  Serial.print(",");            Serial.println(lastLoopTime);
  Serial.println();

// *********************** loop timing control **************************
  lastLoopUsefulTime = millis()-loopStartTime;
  if(lastLoopUsefulTime<STD_LOOP_TIME)         delay(STD_LOOP_TIME-lastLoopUsefulTime);
  lastLoopTime = millis() - loopStartTime;
  loopStartTime = millis();
}

The results (lastLoopUsefulTime) are, as expected, inversely proportional to the Serial data speed

9600 110 ms
19200 54 ms
38400 27 ms
57600 18 ms
115200 9 ms

Interestingly enough, 28800 bps doesn't work on my system
I used a Diecimila board powered by an ATmega168,
So try using 115200 bps, but YMMV.

Is it related with the lag observed by bryanpearson ??

@ GuzZzt

... It looks complicated...

It does :o :o