TIC T249 Operation

The Tic only backs the motor away from the switch until the switch is no longer active, so it should be brief, but if you have a particularly noisy switch, it might be possible that the 20ms delay isn’t long enough, and the noise is interfering with the reading. You might try looking at your limit switch signal with an oscilloscope when it is triggered to see how it looks.

It might also be possible that however you are controlling the Tic is trying to command it beyond the limit switch, so immediately after homing, it is being driven into the switch. A video of your process showing how you are controlling the Tic, how you are initiating the homing procedure, and how the Tic responds would be really helpful. The forum does not allow users to post very large videos, but it does work well with videos linked from other sites (like YouTube or Vimeo).

Also, could you post a copy of your Tic settings file? You can save a copy of your settings file from the “File” drop-down menu of the Tic Control Center.

Brandon

The switch i am using is an optical switch and it stops the stepper like right now. If the TIC is reversing it is not doing it enough to release the switch. After it stops the stepper it is still showing the switch as active in the control center. "Do you want a video of the stepper moving into the limit switch zone or screen grabs of the TIC Control Center? I am moving the stepper with the “set position”. It stops the stepper but doesn’t reverse it.

Perhaps I do not have it set right. I just now noticed that in the TIC Control Center that it says;
Homing active: yes (this is yes when the stepper is running forward) but it will not reverse away from the forward switch after the switch stops it.

Here are my settings:

# Pololu Tic USB Stepper Controller settings file.
# https://www.pololu.com/docs/0J71
product: T249
control_mode: serial
never_sleep: false
disable_safe_start: false
ignore_err_line_high: false
auto_clear_driver_error: true
soft_error_response: decel_to_hold
soft_error_position: -5000
serial_baud_rate: 9600
serial_device_number: 14
serial_alt_device_number: 0
serial_enable_alt_device_number: false
serial_14bit_device_number: false
command_timeout: 1000
serial_crc_for_commands: false
serial_crc_for_responses: false
serial_7bit_responses: false
serial_response_delay: 0
vin_calibration: 0
input_averaging_enabled: false
input_hysteresis: 0
input_scaling_degree: linear
input_invert: false
input_min: 0
input_neutral_min: 2015
input_neutral_max: 2080
input_max: 4095
output_min: -5000
output_max: 2000
encoder_prescaler: 1
encoder_postscaler: 1
encoder_unlimited: false
scl_config: default
sda_config: default
tx_config: default
rx_config: default
rc_config: limit_switch_forward active_high
invert_motor_direction: true
max_speed: 50000000
starting_speed: 0
max_accel: 500000
max_decel: 0
step_mode: 4
current_limit: 160
current_limit_during_error: -1
auto_homing: true
auto_homing_forward: true
homing_speed_towards: 10000000
homing_speed_away: 10000000
agc_mode: off
agc_bottom_current_limit: 80
agc_current_boost_steps: 5
agc_frequency_limit: off

As an add on to my last post:

I think I may have figured out why this issue is happening. When the stepper gets to the optical switch it blocks the beam and stops the stepper…really fast…actually too fast. When the stepper stops, the beam is only partially blocked by the leading edge of a piece of plastic that I am using to block the beam. The input on the TIC sees 1.8 vdc at this point and stops the stepper. But, it stops the stepper so fast that the beam blocker doesn’t go far enough into the switch to make the switch go high with a 5 vdc signal to the TIC to make it reverse.

Upon further testing with a different stepper it still does it, except when I block the beam faster. Then it will reverse the stepper when the input to the TIC sees a full 5 vdc signal. The stepper is only one step away from making the switch go high.

I may end up running the switch into the Ardunio and put a short delay, then go into the TIC so the stepper can get one more step.

Crazy stuff lol!

Thank you for the additional information. Can you clarify what the actual problem is (e.g. can you control the stepper motor after the homing procedure runs)? Please note that since you are using a forward limit switch, the Tic will only be able to drive the stepper motor to negative position values after homing.

Also, are you able to look at the limit switch signal with an oscilloscope as I suggested before? If so, could you post screen captures of that signal?

Lastly, could you try using a different pin on the Tic, such as RX, for your limit switch and see if that changes the behavior at all?

Brandon

Ok, moving the limit switch to the RX pin did the trick! Now it stops and then reverses when it hits the limit switch.

The following is just for clarification in case someone else has a similar issue:

What it was doing is when the stepper reached the optical limit switch, the switch beam would see just the front edge of the stepper and it caused the optical switch to partially come on at just 1.8 volts. This was enough on the RC pin for it to stop the stepper but not reverse it.

Thanks for the help as it solved my issue!

For some reason I cannot get the stepper to get the same speed in my Ardunio/TIC code as it does in the IDE. In the IDE it will go really fast, but much slower with the code when the targetVelocity is set the same. Or at least I think it is the same lol.

Here is the code I am using:

// This example shows how to send I2C commands to the Tic
// Stepper Motor Controller to control the speed of a Stepper
// Motor.
//
// The Tic's control mode must be set to "Serial/I2C/USB".  The
// serial device number must be set to its default value of 14.
//
// If you have sent a De-energize command to the Tic, for example
// by clicking "De-energize" in the Tic Control Center, you will
// need to undo that by clicking "Resume" or power-cycling the
// Tic.
//
// Please see https://github.com/pololu/tic-arduino for details
// on how to make the connections between the Arduino and the
// Tic.

#include <Tic.h>

TicI2C tic;

void setup()
{
  // Set up I2C.
  Wire.begin();

  // Give the Tic some time to start up.
  delay(20);

  // Tells the Tic that it is OK to start driving the motor.  The
  // Tic's safe-start feature helps avoid unexpected, accidental
  // movement of the motor: if an error happens, the Tic will not
  // drive the motor again until it receives the Exit Safe Start
  // command.  The safe-start feature can be disbled in the Tic
  // Control Center.
  tic.exitSafeStart();

  }

// Sends a "Reset command timeout" command to the Tic.  We must
// call this at least once per second, or else a command timeout
// error will happen.  The Tic's default command timeout period
// is 1000 ms, but it can be changed or disabled in the Tic
// Control Center.
void resetCommandTimeout()
{
  tic.resetCommandTimeout();
}

// Delays for the specified number of milliseconds while
// resetting the Tic's command timeout so that its movement does
// not get interrupted by errors.
void delayWhileResettingCommandTimeout(uint32_t ms)
{
  uint32_t start = millis();
  do
  {
    resetCommandTimeout();
  } while ((uint32_t)(millis() - start) <= ms);
   
   tic.goHomeForward();
   
    }
    
void loop()
{
    
      // Move forward at X steps per second for X seconds.
  tic.setTargetVelocity(30000000);
  delayWhileResettingCommandTimeout(1000);

  // Decelerate to a stop.
  tic.setTargetVelocity(0);
  delayWhileResettingCommandTimeout(500);

  // Move in reverse at -X steps per second for X seconds.
  tic.setTargetVelocity(-30000000);
  delayWhileResettingCommandTimeout(1000);

  // Decelerate to a stop.
  tic.setTargetVelocity(0);
  delayWhileResettingCommandTimeout(500);
}

How fast are you stepping it when you set the velocity in the Tic Control Center? You should see an indication of the target velocity in pulses per second under the slider (or inside of the “Operation” parameters box while it is running).

For reference, it looks like your Arduino program is setting the velocity to ±30000000, which is at ±3000 pulses per second, and the maximum speed in the settings file you posted was 5000 pulses per second. Also, please note that each pulse moves the stepper motor 1 micro-step, so different microstepping resolutions will result in different speeds.

Brandon

I set it both directions at ±3000 pulses per second in The Control Center and it moves very fast, much faster than the same speed setting in the code.

I am running the stepper at 1/4 step and I can even up the pulses per second to the max but it doesn’t change speed. It almost seems like something is throttling it.

EDIT: OK, I got some speed out of it! For some reason unknown to me, the stepper will not go the same speed with the code as it does with the Control Center. So, I went ahead and upped the speed in the code (10000 pulses/s)and got the speed I was looking for.

It is not clear to me why you are getting that behavior; it definitely is not normal. You should expect the same target velocity to give you the same result regardless of the interface used to set it.

It sounds like you might be happy with just setting the value higher, but if you want to troubleshoot that odd behavior further, please let me know, and I can suggest some tests to try.

Brandon

Yes I would like to find out why it is operating this way. The stepper works fine with the Control Center. What my plan was; get the speed and other settings sorted out with the TIC Control Center then it would be a simple matter of putting the same settings in the Ardunio code with the TIC library.

I had it originally programed with the Step/Dir pins on the TIC and I could not get higher speed with a pot to control the speed. So, I went with I2C to let the TIC control the pulses as it didn’t seem to be working with Step/Dir.

So using two different control formats, and getting same results, it seems to me that the Elegoo Uno R3 is where the issue is. Or me.

I mean, I am using one switch as an input at this point so it should not be complete rocket science.

Can you run the program you posted on your Arduino while the Tic is connected to the Tic Control Center and post details about what happens with the “Target velocity” and “Current velocity” values in the “Operation” box of the “Status” tab? It might help you see what is going on if you increase the delay in your code from 1 second to something like 10 seconds (if your system can handle that mechanically).

The “Target velocity” should match the value you are sending in your code with setTargetVelocity().

The “Current velocity” value should approach the target value and reach it at some point.

Brandon

Ok, ran it like you said and on the TIC Control Center the “Target and Current” were equal with what ever I entered on the program code.

Example:
Ardunio Code: tic.setTargetVelocity 30000000
Tic Control Center Target Velocity 30000000
Tic Control Center Current Velocity 30000000

I changed the Ardunio code To 300000000 and the TIC Control Center gave me the same reading; so now it seems to be working as the stepper speeds up like it is supposed to.

Maybe I had a zero left out? There are a lot of zero’s to contend with and on the Control Center they are small.

Now I can see what happens when I use a pot to control speed. I will move my Ardunio and TIC connections from Ic2 to serial so I can use SCL and SDA pins for my pot?

Thank You! :+1:

1 Like

I have a strange issue. I want to run serial on Ardunio Uno R3 to TIC. When I make the connections the Ardunio does not like being connected to the TIC as I cannot get it to load the program into Ardunio when connected serial.

I can run it in I2C fine.
I am trying to run the example code:

// This example shows how to send serial commands to the Tic
// Stepper Motor Controller to control the position of a Stepper
// Motor.
//
// The Tic's control mode must be set to "Serial/I2C/USB".  The
// baud rate should be set to 9600 and CRC should not be enabled.
// This example uses the compact protocol, so the Tic's device
// number is not used, and can be set to anything.
//
// If you have sent a De-energize command to the Tic, for example
// by clicking "De-energize" in the Tic Control Center, you will
// need to undo that by clicking "Resume" or power-cycling the
// Tic.
//
// Please see https://github.com/pololu/tic-arduino for details
// on how to make the connections between the Arduino and the
// Tic.

#include <Tic.h>

// On boards with a hardware serial port available for use, use
// that port to communicate with the Tic. For other boards,
// create a SoftwareSerial object using pin 10 to receive (RX)
// and pin 11 to transmit (TX).
#ifdef SERIAL_PORT_HARDWARE_OPEN
#define ticSerial SERIAL_PORT_HARDWARE_OPEN
#else
#include <SoftwareSerial.h>
SoftwareSerial ticSerial(10, 11);
#endif

TicSerial tic(ticSerial);

void setup()
{
  // Set the baud rate.
  ticSerial.begin(9600);

  // Give the Tic some time to start up.
  delay(20);

  // Set the Tic's current position to 0, so that when we command
  // it to move later, it will move a predictable amount.
  tic.haltAndSetPosition(0);

  // Tells the Tic that it is OK to start driving the motor.  The
  // Tic's safe-start feature helps avoid unexpected, accidental
  // movement of the motor: if an error happens, the Tic will not
  // drive the motor again until it receives the Exit Safe Start
  // command.  The safe-start feature can be disbled in the Tic
  // Control Center.
  tic.exitSafeStart();
}

// Sends a "Reset command timeout" command to the Tic.  We must
// call this at least once per second, or else a command timeout
// error will happen.  The Tic's default command timeout period
// is 1000 ms, but it can be changed or disabled in the Tic
// Control Center.
void resetCommandTimeout()
{
  tic.resetCommandTimeout();
}

// Delays for the specified number of milliseconds while
// resetting the Tic's command timeout so that its movement does
// not get interrupted by errors.
void delayWhileResettingCommandTimeout(uint32_t ms)
{
  uint32_t start = millis();
  do
  {
    resetCommandTimeout();
  } while ((uint32_t)(millis() - start) <= ms);
}

// Polls the Tic, waiting for it to reach the specified target
// position.  Note that if the Tic detects an error, the Tic will
// probably go into safe-start mode and never reach its target
// position, so this function will loop infinitely.  If that
// happens, you will need to reset your Arduino.
void waitForPosition(int32_t targetPosition)
{
  do
  {
    resetCommandTimeout();
  } while (tic.getCurrentPosition() != targetPosition);
}

void loop()
{
  // Tell the Tic to move to position 100, and wait until it gets
  // there.
  tic.setTargetPosition(100);
  waitForPosition(100);

  // Tell the Tic to move to position -100, and delay for 3000 ms
  // to give it time to get there.
  tic.setTargetPosition(-100);
  delayWhileResettingCommandTimeout(3000);
}

Are you connecting the Tic to the hardware serial pins on the Arduino Uno (pins 0 and 1)? Those pins are shared with the serial connection with the computer that’s used to program it. When using an Arduino Uno with our unmodified example program, you should be using software serial on pins 10 and 11 instead.

Brandon

Yup, that is it! I suppose it helps if I was to read and pay attention to the:

#include <SoftwareSerial.h>

SoftwareSerial ticSerial(10, 11);

sometimes this stuff does not sink in! LOL

Also: where is the best place to put the command - goHomeForward

I am glad that fixed the problem; thank you for letting us know.

I am not sure I understand your question. You can use the goHomeForward command any time you want the Tic to do its homing procedure (in the forward direction). So, the “best” place in your code to put it will depend on your application and what you are trying to do.

Brandon

I have been trying to use it with a momentary button but have not had any luck. I am not sure how to make a momentary button trigger a command like that in the loop.

It is hard to give any nuanced advice without more insight into what you are trying to do. Are you trying to add button handling to one of the example sketches from the library, or are you working with a different program now? If you post a copy of your sketch that has your attempt at adding the button handling, I might be able to give you some suggestions.

Brandon

Yes, I am using, at least for now, one of the example sketches. What I just tried is; I put the goHomeForward command at the end of the setup right before the loop. When I power up the system it goes into forward homing as I want so that is probably where it should be. The more I thought about it this morning, I do not think a button will work as well.

So this is how I will implement it as I want the stepper to home each time I start the system up.

This is how I added homing to the example:

// This example shows how to send serial commands to the Tic
// Stepper Motor Controller to control the speed of a Stepper
// Motor.
//
// The Tic's control mode must be set to "Serial/I2C/USB".  The
// baud rate should be set to 9600 and CRC should not be enabled.
// This example uses the Compact Protocol, so the Tic's device
// number is not used, and can be set to anything.
//
// If you have sent a De-energize command to the Tic, for example
// by clicking "De-energize" in the Tic Control Center, you will
// need to undo that by clicking "Resume" or power-cycling the
// Tic.
//
// Please see https://github.com/pololu/tic-arduino for details
// on how to make the connections between the Arduino and the
// Tic.

#include <Tic.h>

// On boards with a hardware serial port available for use, use
// that port to communicate with the Tic. For other boards,
// create a SoftwareSerial object using pin 10 to receive (RX)
// and pin 11 to transmit (TX).
#ifdef SERIAL_PORT_HARDWARE_OPEN
#define ticSerial SERIAL_PORT_HARDWARE_OPEN
#else
#include <SoftwareSerial.h>
SoftwareSerial ticSerial(10, 11);
#endif

TicSerial tic(ticSerial);

void setup()
{
  // Set the baud rate.
  ticSerial.begin(9600);

  // Give the Tic some time to start up.
  delay(20);

  // Tells the Tic that it is OK to start driving the motor.  The
  // Tic's safe-start feature helps avoid unexpected, accidental
  // movement of the motor: if an error happens, the Tic will not
  // drive the motor again until it receives the Exit Safe Start
  // command.  The safe-start feature can be disbled in the Tic
  // Control Center.
  tic.exitSafeStart();
}

// Sends a "Reset command timeout" command to the Tic.  We must
// call this at least once per second, or else a command timeout
// error will happen.  The Tic's default command timeout period
// is 1000 ms, but it can be changed or disabled in the Tic
// Control Center.
void resetCommandTimeout()
{
  tic.resetCommandTimeout();
}

// Delays for the specified number of milliseconds while
// resetting the Tic's command timeout so that its movement does
// not get interrupted.
void delayWhileResettingCommandTimeout(uint32_t ms)
{
  uint32_t start = millis();
  do
  {
    resetCommandTimeout();
  } while ((uint32_t)(millis() - start) <= ms);

  tic.goHomeForward();

}

void loop()
{
  // Move forward at 200 steps per second for 2 seconds.
  tic.setTargetVelocity(200000000);
  delayWhileResettingCommandTimeout(600);

  // Decelerate to a stop.
  tic.setTargetVelocity(0);
  delayWhileResettingCommandTimeout(600);

  // Move in reverse at 100 steps per second for 1 second.
  tic.setTargetVelocity(-200000000);
  delayWhileResettingCommandTimeout(600);

  // Decelerate to a stop.
  tic.setTargetVelocity(0);
  delayWhileResettingCommandTimeout(600);
}

Thank You for all the help, as I am very new to this, and any and all suggestions are greatly appreciated and needed!

1 Like