T'Rex Controller I2C status request from RaspberryPi master triggers Shutdown

I am currently working with the T'Rex controller via i2c with a RaspberryPi as the i2c master, and using the Python smbus module to send/receive data to/from the controller. What I have found is that when I send a motor command, everything works fine, but as soon as I do a status request from the controller it seems to raise an error which results in the controller executing the Shutdown command. Specifically, this block in the controller code seems to trip the Shutdown:

https://github.com/rhass/TREX_controller/blob/master/I2Ccommand.ino#L14-L18

I can hack arround it by commenting out the Shutdown, but this too has adverse effects; such as the status error byte always being a non-zero value, and when a status requests is not issued prior to a new command packet being issued the command packet is discarded.

I have googled around, and it *seems* like the issue wjere the status command is triggering the Shutdown function could be related to an an issue with the RPi hardware where is is unable to issue repeated i2c start transations:

https://www.raspberrypi.org/forums/viewtopic.php?t=15840&p=302378

Moreover, the python smbus module read_i2c_block_data function requres a command agrument to be passed with the read request:

https://github.com/bivab/smbus-cffi/blob/master/smbus/smbus.py#L241-L246 

This said, it doesn't seem to matter what the command packet contains so long as it is an integer - and the controller seems to handle any value I provide with the same behavior.

 

I was hoping I could simply add command byte binding to the onRequest call to fix the problem, but it seems the Arduino Wiring onRequest call does not support binding a command to the request packets, only a function to be called when an i2c request occurs. https://www.arduino.cc/en/Reference/WireOnRequest

I was hoping someone out there has encountered this issue before and come up with a more elegant fix than trying to issue commands repeatedly and ignoring the error byte in the status. Any help or suggestions would be appreciated.

Thanks!

One possible solution: use a
One possible solution: use a level shifter to do this because the RPi and the Odroid-C1 are 3v3 based boards,

This will only work if title is a power probem.

The t’rex controller has a

The t’rex controller has a level shifter for the I2C bus – I can receive and send data on the bus just fine, but not reliably.

Clock stretching ?

with my Rover5 Raspberry pi and Arduino. i2c was not at all reliable due to clock stretching on receiveing end (Pi). well I am using  for serial now. you can checkout clockstretching on pi. 

**Any Progress since last post? **

Hi, I’m trying to do something simillar to what you are trying to achieve. However, I can’t even get my T’rex to respond via the raspberry (through I2C). Would it be possible for you to give us a sneak peak at your Python code? How has yourprogress been since this post? I’m eager to know.  I’m sure my issue isn’t a hardware one as I can run stuff via another arduino (as an I2C master). I am hoping to make things alittle more complex using the RPi.

EDIT:

I stumbled upon this code … Might help someone else ?

https://github.com/steelsquid/steelsquid-kiss-os/blob/master/steelsquid_trex.py