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

Pololu Forum

Tic 500 Homing

I need help getting the TIC 500 Stepper Motor Controller working correctly with an Arduino MKR WiFi 1010. I believe that the issues are with my coding as uploaded to the Arduino via the Arduino online editor, Arduino Create.

Scenario:
Now that my wife is in a wheelchair, we needed a way for her to open the bedroom door remotely. I have already had this setup working with another controller and a stepper that was too small to open the door against HVAC pressure in the bedroom. So I bought a new larger stepper and controller from Pololu.

Setup:
I am using the Pololu Tic Control Center and a Tic T500 both with the latest version of software and firmware.

I have mounted the stepper motor (#1472 (SY57STH56-1006A)) along with the Tic T500 controller to a small piece of plywood that I mounted to the door. I have mounted a typical limit switch (for home Forward) to the plywood for the open sensor and a hall effect sensor (for home Reverse) mounted to the plywood senses a rare earth magnet imbedded in the door frame for the close sensor. I will attach a picture or two to help visualize the setup.

When I saw that the T500 included limit switch homing, I hoped that I could use these built-in functions to open and close the door. I will attach the relevant code to this post but essentially the logic I used was to first ensure that the door opens in the case of power-up as in a house power outage so I put a ‘tic.goHomeForward();’ command in the void setup section.

Then the switch code in the void loop section relies on a ‘doitNow’ variable which can be manipulated with the Arduino IoT Cloud (code for Cloud left out for clarity) to open or close the door.

Symptoms:
Once all this is hooked up and programmed and I apply power to the system, the stepper makes a bump sound that seems like it had the power applied then no movement whatsoever after that sound. Also I can turn the motor freely with my fingers.

Observations:
While plugged into the Pololu Tic Control Center I can cause the motor to run forward and the limit switch stops it and the Control Center shows the Forward limit switch activated. I can also run the motor in reverse and activate the hall effect sensor and likewise the motor stops. If I release/deactivate either limit switch the motor resumes running in its original direction until the limit switch is activated again.

I think the problem is in my coding as this is the first time I have used a TIC controller. The only thing I can observe in actual observation during testing is that after uploading the code to the Arduino and starting up the system I can move my USB connection to the computer over to the T500 and the Control Center indicates a Safe Start error which I thought the ‘tic.exitSafeStart();’ command in void setup would have taken care of already.

Photos: Note the Door Mounted ones show the former, smaller stepper motor

! !
!

Screenshots:



Code:

// ....
// Tic - Version: Latest 
#include <Tic.h>

TicI2C tic;

// Define the current limit, in milliamps, to use while moving
// the motor.
const uint16_t currentLimitWhileMoving = 1000;

// Define the current limit, in milliamps, to use while stopped.
const uint16_t currentLimitWhileStopped = 0;

bool doitNow = true ;  // true is open it - false is close it

void setup() {

  // Specify what type of Tic we are talking to.  This affects
  // how the setCurrentLimit command works.
  // tic.setProduct(TicProduct::T825);
  // tic.setProduct(TicProduct::T834);
  tic.setProduct(TicProduct::T500);
  // tic.setProduct(TicProduct::T249);
  // tic.setProduct(TicProduct::Tic36v4);
  
  // 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();

  // open the door on power up
  tic.goHomeForward();

}  // for the void setup

void loop() {

  delayWhileResettingCommandTimeout(1000);
  
  switch (doitNow) {
    case true:
      // Set the current limit and wait a little bit for it to take effect.
      tic.setCurrentLimit(currentLimitWhileMoving);
      delay(10);
      tic.goHomeForward();
      tic.setCurrentLimit(currentLimitWhileStopped);
      delayWhileResettingCommandTimeout(1000);
      break;
    case false:
      tic.setCurrentLimit(currentLimitWhileMoving);
      delay(10);
      tic.goHomeReverse();
      tic.setCurrentLimit(currentLimitWhileStopped);
      delayWhileResettingCommandTimeout(1000);
      break;
    default:
    // Optional
    break;
  }  //  for the switch

} // for the void loop


// 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);
  
}

Hello, youngrh.

It is not entirely clear from your description what the problem might be, but I have a few suggestions for things to try. First, can you clarify if the red LED on the Tic is lighting up when you are trying to run the system (while not connected to USB)?

Could you try running one of our unmodified example programs from the Tic Arduino library, such as I2CPositionControl or I2CSpeedControl? You might want to remove the wheel from the stepper motor or remove the setup from the door so it does not have a chance to damage something (those examples don’t move the motor far, but just in case). Also, you can turn off the automatic homing feature in the “Advanced settings” tab while running this test; otherwise the Tic will need to run its homing procedure before doing the commanded movements.

As far as your code, the goHomeForward() and goHomeReverse() commands are not blocking, so the way your sketch is currently written, it will start trying to home, then the current limit will get set to 0, even though the forward limit switch has not been reached. You might try using getPositionUncertain() in a while loop to wait until the homing procedure has finished. Please note that since you have the command timeout feature enabled, you can call delayWhileResettingCommandTimeout() within the while loop to prevent the command timeout error, like this:

while(tic.getPositionUncertain())
{
    delayWhileResettingCommandTimeout(100);  
}

Could you also try calling exitSafeStart() before each time you start tying to move the motor?

It sounds like you are still in the testing phase, but the way your code is currently written, it will try to home again 1 second after it exits your switch statement. So, you might try using a separate variable for the forward and reverse homing, so you can set them to false after it is done and only do it again when it is triggered.

-Brandon

Thanks Brandon!

I have implemented the changes you suggested, but things aren’t quite right yet. So I have a few more questions:

  1. How can I tell which commands are blocking commands?

  2. If I have safe start and command timeout disabled, do I need to use exitsafestart or resetcommandtimeout commands at all or are these features recommended for some other reason?

  3. What is the recommended way to conserve battery power? With my previous setup with the smaller motor the 1200ah battery would last slightly less than 24 hours. Should I set current limits to zero or use deenergize after the door has been opened or closed?

TIA for your help.

  1. None of the commands from our Tic Arduino library are blocking, so if you want to have your sketch wait for an action to finish, you would have to implement your own method (such as the while loop I described before). Alternatively, you could do a simple delay() that waits long enough to make sure the action has completed.

  2. The safe start and command timeout errors will not happen if you have them disabled, you so you would not need to send the commands to clear them.

  3. De-energizing the stepper motor will probably use less power than setting the current limit to zero.

If you continue to have problems, you can post more information about what is happening compared to what you want to happen, along with an updated settings file and Arduino sketch, and I would be glad to look into it more.

-Brandon

A post was split to a new topic: Tic T500 Python3 homing problem