Arduino stops sending serial

Hi, i have an Issue with my Segway code. I am using an ADXL345 accelerometer and a LPY503AL gyroscope. I have a while-true loop that is ran every 20 ms and calculates the angle and outputs the data over serial to the PC. But when I hold the sensors steady, the output stops and i have to reset the Arduino. However, if I tilt the sensor board constantly everything seems to work...

Anyone have an idea?

Not without seeing your code we don't.

Of course, sorry! :slight_smile: here it is: http://pastie.org/private/fwyi5uy39cxgg87fvuog

What output did you get on the serial interface before it freezes? Are the last lines sent always the same or is it random where (or when) the freeze occurs?

It seems to be random, sometimes i don't even get a single character, but most times i get about 5 to 15 lines (loops) before it stops (if I don't move the sensors).

Post two samples of output you get.

Ok, i will do that later (don't have the stiff here right now)
If I hold it skew i get some outputs from the tiltstart routine, eg.

xaccdeg:[somevalue]
xaccdeg:[somevalue]
xaccdeg:[somevalue]
xaccdeg:[somevalue]
xaccdeg:[somevalue]
xa

and then it stops.

If I hold it straight i get some lines from the serialOut_timing function.
But I don't think it has something to do with the values, since it does not only crash on a.specific value.

Edit: I figured out it must be a problem with the accelerometer. I tried to commend the readAccel() function out and it works. However, if i run an example program for this library, everything works just fine.

The interesting thing is not the value but how far it gets. Was your output correct, that it stops in the middle of the xaccdeg: string output?

Most times it stops after writing the whole string, but sometimes it even stops in the middle.

Try adding some Serial.flush(); lines in there - specially after you print your xaccdeg value, and anything else printing inside a loop.

Ok, it works a lot longer now :slight_smile: - but unfortunately it still stops...

Edit: I even tried only printing out a single character after each loop and flushing immediately after - still stops...

Does it get as far as

  Serial.println("Starting...");

?

If I don't hold it skew at the beginning it does, and then it even runs through the main loop for some seconds...
I've just tried antother library - no change.

Seems linke I solved the problem now - Isimply made a new sensor board, so I guess there was some communication problem between the ADXL and the Arduino.
But now I have a new issue: If the arduino is connected to a pc and drains the power over USB, everything works. But if I try an external supply on any connector (V pin, Vin pin, Power jack, cut USB cable with 5V and ground connected) the motors stop until the tiltstart routine is over, but then run at the maximum allowed percentage??