Page 2 of 2

Re: HCMotor Arduino library for driving DC and stepper motor

Posted: Mon Jan 29, 2018 10:23 am
by andrew
I'm afraid the HCMotor library doesn't have a clock (step) multiplier feature. Mainly as that's not what the library is intended for. Also a TB6560 can only divide down a clock. I believe you need to multiply up your clock by a factor of 8 (?). Depending on your maximum step frequency you'd probably be able to do it with something like an Uno but you'll need a clock multiplier / PLL sketch to do achieve this.

Re: HCMotor Arduino library for driving DC and stepper motor

Posted: Thu Mar 15, 2018 4:31 pm
by josht
Hi Andrew, I want to know how to use this code control 4 stepper motors? how to define more then one CLK_PIN in code?
Thanks :D

Re: HCMotor Arduino library for driving DC and stepper motor

Posted: Fri Mar 16, 2018 11:24 am
by andrew
You can use the HCMotor.attach() function to add more motors (default maximum is 4 motors) like this:

#define MOTOR_PIN0 7
#define MOTOR_PIN1 8
#define MOTOR_PIN2 9
#define MOTOR_PIN3 10

HCMotor.attach(0, STEPPER, MOTOR_PIN0);
HCMotor.attach(1, STEPPER, MOTOR_PIN1);
HCMotor.attach(2, STEPPER, MOTOR_PIN2);
HCMotor.attach(3, STEPPER, MOTOR_PIN3);

From then on when you use any other of the library functions just set the MotorNum parameter to a value of either 0, 1, 2, or 3 depending on which motor you want it to apply to. E.g.

HCMotor.Direction(2, FORWARD);

Sets motor number 2 to the forward direction.

Re: HCMotor Arduino library for driving DC and stepper motor

Posted: Fri Mar 16, 2018 10:00 pm
by josht
very helpful. Thanks Andrew!!

Re: HCMotor Arduino library for driving DC and stepper motor

Posted: Sat May 05, 2018 3:32 pm
by csaba85
Hello Andrew! I'm verry newbie, never programmed. Can you help me, how can I add end limit switches to the the code? Example: we have two end point, when one is reach, motor stop, and it can only operate in the opposite direction. I think it would be useful to others too.

Re: HCMotor Arduino library for driving DC and stepper motor

Posted: Sun May 06, 2018 7:46 am
by andrew
Assuming your endstops are just clean contact switches you can just connect them to a couple of the digital pins on your Arduino. So for example you could connect the common & normally open contacts of the forward endstop to digital pin 3 and ground, and the common & normally open of the reverse direction to digital pin 4 and ground. In either case when the endstop is reached the switch will close and pull the pin low (low = false).

You then need to tell your Arduino that these two pins will be will be 'inputs' by putting this somewhere in the setup() section of the sketch:

Code: Select all

pinMode(3, INPUT_PULLUP);
 pinMode(4, INPUT_PULLUP);

Then on each iteration of the main() loop you can read the state of the two pins by putting this towards the top of the loop:

Code: Select all

boolean Forward_endstop = digitalRead(3);
boolean Reverse_endstop = digitalRead(4);

Finally, in the sections of code that checks the position of the pot to determine which direction to turn the motor in you can add and extra condition that also checks the state of the appropriate endstop. So for the stepper motor example you would change this:

Code: Select all

if (Pot >= POT_REV_MIN && Pot <= POT_REV_MAX)
to this...

Code: Select all

if (Pot >= POT_REV_MIN && Pot <= POT_REV_MAX && Reverse_endstop != false)

and this...

Code: Select all

}else if (Pot >= POT_FWD_MIN && Pot <= POT_FWD_MAX)
to this

Code: Select all

}else if (Pot >= POT_FWD_MIN && Pot <= POT_FWD_MAX && Forward_endstop != false)

Re: HCMotor Arduino library for driving DC and stepper motors.

Posted: Mon Aug 20, 2018 7:04 am
by Mooslee
Hello all

#include <HCMotor.h>
HCMotor.Init();

Driving Lessons Lichfield