Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

Tic Velocity Using I2C

I successfully ran the position code shown in Section 12.9 https://www.pololu.com/docs/0J71/all#12.9 on a Tic T825 using I2C on a Raspberry Pi. Being a noob, can some one help me with setting up code to run motors in velocity mode? Yesterday I was able to run in velocity mode using a USB connection.

Chuck

A little more information, I cannot connect to the Tic through either ticcmd or ticgui. However, the code mentioned above still works just fine.

Tic pin connections
SCL connected to GPIO24
SDA connected to GPIO23
GRD connected to GRD

Chuck

Hello, Chuck.

It sounds like you have two separate issues: needing help with writing some code and getting the Tic software to work on your Raspberry Pi. Is that correct? If so, for now, we should focus on getting the Tic software working on your Raspberry Pi. Can you post the error messages you get when trying to install the Tic software for Linux (Raspberry Pi)? Please provide as much detail on what steps you did when trying to install the software, including any steps for troubleshooting, listed under the “Installing Linux software” section of the Tic user’s guide.

- Amanda

Amanda,

Thanks for replying. This is what I have done this morning:

  • Confirmed that the stepper motor will function using the code from Section 12.9 in the User Guide.
  • Confirmed that the command ticgui will launch the Tic User Interface, however it will not connect to the Tic T825.
  • Confirmed that the command ticcmd will not also connect the the T825 and gives the error message :Error No Device was found.

I’ve attached two screen shots that show the results of these three tests. Let me know if you need more information.

Chuck

I suspect there might be something wrong with your USB cable. Can you try a different USB cable (one that you know is working)? Some USB cables (e.g. cell phone charging cable) are power-only cables and do not have the data lines.

- Amanda

Amanda,

I may have confused you. There is no problem connecting the T825 via USB cable, as mentioned in the first post, I was able to run the motors in velocity mode while connected via USB cable.

Issues with I2C connection

  • Using the I2C code in Section 12.9 https://www.pololu.com/docs/0J71/all#12.9 , which is for position control works ok.

  • Neither ticcmd or ticgui work when the T825 is connected via I2C

  • I need help to program the T825 in velocity mode

Chuck

The Tic Control Center (ticgui) and command-line utility (ticcmd) only interface with the Tic through its USB interface. They cannot be used to configure or control the Tic over I2C.

There are no separate modes to be selected for position mode and velocity mode; to control velocity via I2C, you can use the “Set target velocity” command. You can find more details under the “Command reference” section of the Tic Stepper Motor Controller User’s Guide.

- Amanda

Amanda,

Is it just the matter of replacing the last line in the code with the Set target velocity command?

Chuck

# Uses the smbus2 library to send and receive data from a Tic.
# Works on Linux with either Python 2 or Python 3.
#
# NOTE: The Tic's control mode must be "Serial / I2C / USB".
# NOTE: For reliable operation on a Raspberry Pi, enable the i2c-gpio
#   overlay and use the I2C device it provides (usually /dev/i2c-3).
# NOTE: You might nee to change the 'SMBus(3)' line below to specify the
#   correct I2C device.
# NOTE: You might need to change the 'address = 11' line below to match
#   the device number of your Tic.
 
from smbus2 import SMBus, i2c_msg

class TicI2C(object):
  def __init__(self, bus, address):
    self.bus = bus
    self.address = address
 
  # Sends the "Exit safe start" command.
  def exit_safe_start(self):
    command = [0x83]
    write = i2c_msg.write(self.address, command)
    self.bus.i2c_rdwr(write)
 
  # Sets the target position.
  #
  # For more information about what this command does, see the
  # "Set target position" command in the "Command reference" section of the
  # Tic user's guide.
  def set_target_position(self, target):
    command = [0xE0,
      target >> 0 & 0xFF,
      target >> 8 & 0xFF,
      target >> 16 & 0xFF,
      target >> 24 & 0xFF]
    write = i2c_msg.write(self.address, command)
    self.bus.i2c_rdwr(write)
 
  # Gets one or more variables from the Tic.
  def get_variables(self, offset, length):
    write = i2c_msg.write(self.address, [0xA1, offset])
    read = i2c_msg.read(self.address, length)
    self.bus.i2c_rdwr(write, read)
    return list(read)
 
  # Gets the "Current position" variable from the Tic.
  def get_current_position(self):
    b = self.get_variables(0x22, 4)
    position = b[0] + (b[1] << 8) + (b[2] << 16) + (b[3] << 24)
    if position >= (1 << 31):
      position -= (1 << 32)
    return position
 
# Open a handle to "/dev/i2c-3", representing the I2C bus.
bus = SMBus(3)
 
# Select the I2C address of the Tic (the device number).
address = 14
 
tic = TicI2C(bus, address)
 
position = tic.get_current_position()
print("Current position is {}.".format(position))
 
new_target = -200 if position > 0 else 200
print("Setting target position to {}.".format(new_target));
tic.exit_safe_start()
tic.set_target_position(new_target)

No; you would need to create a function for set target velocity , and then call the function in place of tic.set_target_position(new_target) at the bottom of the script. You can copy the code from set_target_position and change 0xE0 to 0xE3, which is the Set Target Velocity command byte.

- Amanda