TIC T249 Operation

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

I am moving a traverse left and right a small amount. The sketch has 4 statements within the loop(). The first two group together and the last two group together. I want to run the first two a certain number of times. I also want to run the last two a certain amount of times.

Can these two groups of statements be called something else so I can run a for loop statement on each group or do I have to make four separate for loop statements?

I hope that makes sense lol.

OK this is all working for me with this code:

```cpp

#include <Tic.h>

TicI2C tic;

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

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

   tic.exitSafeStart();
}


void resetCommandTimeout()
{
  tic.resetCommandTimeout();
}

void delayWhileResettingCommandTimeout(uint32_t ms)
{
  uint32_t start = millis();
  do
  {
    resetCommandTimeout();
  } while ((uint32_t)(millis() - start) <= ms);

    tic.goHomeForward();
}

void loop()
{
  // Move wire traverse left X steps per second for x seconds
  tic.setTargetVelocity(60000000);
  delayWhileResettingCommandTimeout(880);

    // Move wire traverse right X steps per second for x seconds.
  tic.setTargetVelocity(-60000000);
  delayWhileResettingCommandTimeout(870);

    // Move wire traverse left X steps per second for x seconds
  tic.setTargetVelocity(40000000);
  delayWhileResettingCommandTimeout(995);

  // Move wire traverse right X steps per second for x seconds..
  tic.setTargetVelocity(-40000000);
  delayWhileResettingCommandTimeout(980);
     
     
}

Hello.

I do not understand what you want to do. Could you try writing down a sequence of actions you want to take? Here is an example of what that could look like:

  1. Do action A one time
  2. Do action B two times
  3. Repeat lines 1 through 2 forever

- Patrick

Ok…

Action 1.

// Move wire traverse left X steps per second for x seconds
tic.setTargetVelocity(60000000);
delayWhileResettingCommandTimeout(880);

// Move wire traverse right X steps per second for x seconds.
tic.setTargetVelocity(-60000000);
delayWhileResettingCommandTimeout(870);

Action 2.

// Move wire traverse left X steps per second for x seconds
tic.setTargetVelocity(40000000);
delayWhileResettingCommandTimeout(995);

// Move wire traverse right X steps per second for x seconds…
tic.setTargetVelocity(-40000000);
delayWhileResettingCommandTimeout(980);

repeat action 1 and 2 forever

It seems like the program you posted should already be doing that sequence. If it is not, could you explain what it is doing instead?

Or, perhaps are you just trying to condense the code in your main loop by grouping the code listed under “Action 1” and the code under “Action 2” into functions? If so, then you could find some guidance for how to do that in this “Arduino Functions” tutorial.

- Patrick

Thanks, Patrick, I will give that a look and that may possibly be what I need to learn! :+1: