Pololu Tic, Python and I2C -Set Target Position

Hi,

I recently bought a Pololu tic 248 which I would like to connect to my Raspberry Pi over I2C (unless you can recommend me anything else except USB). Having a look at the example code I did not really understand how the set position function works. Specifically this bit here:

command = [0xE0,
target >> 0 & 0xFF,
target >> 8 & 0xFF,
target >> 16 & 0xFF,
target >> 24 & 0xFF]

Best wishes,
Tobia

Hello, Tobia.

The set_target_position function in the I2C example code for Linux in Python in the Tic Stepper Motor Controller User’s Guide formats the target value into a 32-bit write command, stores it in the command byte array variable, and sends it to the Tic via I2C. In that segment you copied, it breaks down the 32-bit target value into bytes using the arithmetic right shift operator (>>) and the bitwise AND operator (&) to mask off 8 bits at a time, then combines those bytes into an array. I suggest doing an Internet search for bitwise operations to thoroughly understand how the operation works.

I also suggest looking at the “I2C command encoding” section in the user’s guide for more details on command formatting and the “Set target position” command under the “Command reference” section (if you have not already done so).

- Amanda