Romi-Rasberry Pi 3 I2C Encoder Issues

Hi All,

I’m having some issues transferring my encoder values from my Romi to my Raspberry Pi 3 using the a_star.py library.

I get “data” but the issue manifests as unstable values and odd discontinuities as I roll the wheels. For example, the following is a trace of the encoder values read out from my_astar.read_encoders() as I push the robot forwards.

encoder: l: 0, r: 0
encoder: l: 1, r: 32627
encoder: l: 32552, r: 32537

I would expect the encoder to go from 0 to -1 in this case, or to go from 0 to 65535 if I were using unsigned 16-bit arithmetic, but 32xxx suggests something weirder.

The Romi side seems fine. I dumped the getCounts and buffer values to Serial on the Romi side just to confirm:

slave.buffer 0x0x2ce
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 f 0 0 0 a0 ff 8f ff
l: -96, r: -113

Looking at the a_star.py read_unpack, I dumped out print(bytes(byte_list)) as follows:

b’\x18\x7f\x15\x7f’
b’\x18\x7f\x15\x7f’
encoder: l: 32536, r: 32533

Can anyone point me at any ideas for what to debug next? I’m almost to the point of putting a logic analyzer on the I2C bus (though I suspect the data is fine on the wire). My guess is that I’m causing/encountering a signing error somewhere that is causing the bytes to lose their high bits.

Hello, TinyManticore.

Just for added clarification, are you running the RomiRPiSlaveDemo example in the Raspberry Pi slave library for Arduino on the Romi 32U4 Control Board? Can you post the entire code you have running on the Raspberry Pi?

- Amanda

Hi Amanda,

Thank you for your reply. I can confirm that I am observing the same behavior with the stock raspberry pi slave library slave.py program on the room 32u4 control board and the arduino RomiRPiSlaveDemo from same GitHub repo. My raspberry pi is a version 3 model running Ubuntu MATE 16.04.

Peter

Ah ha! I tried increasing the PololuRPiSlave delay template parameter to 20 from 5. The numbers now go negative from zero as expected (at least on the server.py example).

PololuRPiSlave<struct Data,20> slave;
I will report back as I find out more.

Robot ran reliably for a few hours last night with the increased delay parameter. I’m calling it fixed. Thanks for your response!

1 Like

Hi, Peter.

I’m glad the issue is resolved; thank you for letting us know.

I suspect you might have not set the clock frequency for the I2C on the Raspberry Pi to work with the original RomiRPiSlaveDemo code. If you do not already know and for others following this thread, there is a known bug with the Raspberry Pi’s I2C implementation, which is mentioned in the Summary section of the README.md file on the library’s GitHub Page as well as in the comments at the top of PololuRPiSlave.h.

- Amanda