Tic249 serial command get_position returns byte shifted results

In the example code (https://www.pololu.com/docs/0J71/12.7), if I call the get_position function multiple times (with a 1 second delay between calls) I get vastly different results from each call, even if the motor hasn’t moved.
I printed the result from the get_variables function, and it shows the byte array changes on each call. The result shifts one byte to the right with each subsequent call:

Read result b'P\x07\x00\x00'.
Current position is 1872.
Read result b'\x01P\x07\x00'.
Current position is 479233.
Read result b'\x00\x01P\x07'.
Current position is 122683648.

I have uploaded the source code, it’s just a minor variant of the example.Serial-test.py (3.2 KB)

Hello, corgitronics.

I am sorry you are having more trouble with the Tic.

It sounds like you were able to resolve the problem you were having earlier where the Tic always reported a position of -1. Please respond to Brandon in your previous thread and say how you got past that problem if you can remember, since it might be helpful to other users of the Tic. Here is a link to your previous thread:

As for your current problem, I suspect that your computer is receiving 5 bytes on its serial port every time you send the command to get the position, even though it should only receive 4. Since your program only reads 4 bytes, one of the bytes is left over in the buffer and gets read later, when the program tries to read the result from the next command.

Please check your Tic’s serial settings and make sure the “Enable CRC for responses” box and the “Enable 7-bit responses” box are not checked. Please let me know if that solves the problem.


I switched rom i2c to serial to try and make progress. Yes, it was set to “enable 7-bit responses”. I cleared that and now it’s working nicely! Thank you, that might help someone debug future issues as well.

I would prefer to use i2c, so I will rewire for that protocol and get some screen shots of the scope and post the code. I’ll do that on the other thread.

Thank you again!