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!