Skip to main content

Hercules Motor Controller Library Reference Guide (Controlling the DC Motors)


This guide is not intended to be a tutorial on how to setup the Hercules Motor Controller (HMC) and install its library. If you need help with that, please visit the following link: CLICK HERE (^_^)

First, we will need to include the Hercules Motor Controller library so we can use its functions to control the DC motors connected to the HMC, please add
#include <Hercules.h>
to the top of your source code like in the picture below:



To control the motors, we will be using a function called 'MOTOR' followed by an action:


To Initialize the DC Motors, we write:
MOTOR.begin();


To run them:
MOTOR.setRun1();
MOTOR.setRun2();

where setRun1 will run the motor(s) connected to the terminal M1 and setRun2 will run the motor(s) connected to the terminal M2


To stop them:
MOTOR.setStop1();
MOTOR.setStop2();

where setStop1 will stop the motor(s) connected to the terminal M1 and setStop2 will stop the motor(s) connected to the terminal M2


To set the speed of the motors:
MOTOR.setSpeed1(int ispeed);
MOTOR.setSpeed2(int ispeed);

where setSpeed1 will set the speed of the motor(s) connected to the terminal M1 and setSpeed2 will set the speed of the motor(s) connected to the terminal M2.

int ispeed is the PWM speed, it ranges from 0 to 100%
For example: we want to set the speed of M1 at 20% PWM, we will write:
MOTOR.setSpeed1(20);



To set the direction of the motors:

MOTOR.setDir1(unsigned char dir);
MOTOR.setDir2(unsigned char dir);

where setDir1 will set the direction of the motor(s) connected to the terminal M1 and setDir2 will set the direction of the motor(s) connected to the terminal M2.

with  DIRF for going forward
    and  DIRR for going in reverse


For example: we want to set the direction of M1 forward we will write:
MOTOR.setDir1(DIRF);

To set both the direction and speed of motors in one syntax line:

MOTOR.setSpeedDir(int ispeed, unsigned char dir);
MOTOR.setSpeedDir1(int ispeed, unsigned char dir);
MOTOR.setSpeedDir2(int ispeed, unsigned char dir);

where setSpeedDir will set the same speed and direction for the motor(s) connected to both M1 and M2. While setSpeedDir1 will set the speed and direction only for the motor(s) connected to M1, and setSpeedDir2 will set the speed and direction only for the motor(s) connected to M2.

For example: we want to set the speed of M1 at 20% PWM and have it go forward, we will write:
MOTOR.setSpeedDir1(20, DIRF);

That's it. This is all you need to know in order to control DC motors using the Hercules Motor Controller board and its library.



Popular posts from this blog

Logic Gate Truth Tables - Reference Guide (Cheat Sheet)

A logic gate is the implementation of a Boolean function. It performs a logic operation on one or more binary input. By binary I mean that the input can either be 1 or 0, nothing else. This guide is intended to be quick guide\reference, I will dive into more details about each gate on transistor\diode level in other posts. The guide cover gates with 2 inputs, meaning that each truth table will have 4 cases (2^2 = 4) AND Gate: Boolean Logic Operator: Q = A  •  B  Input Output A B Q 0 0 0 0 1 0 1 0 0 1 1 1 Summary: in order to achieve 1 on the output, both inputs A AND B must be 1 OR Gate: Boolean Logic Operator: Q = A  +  B  Input Output A B Q 0 0 0 0 1 1 1 0 1 1 1 1 Summary: in order to ...

How Does an Inverter (NOT) Gate Work - NOT Gate Explained

For a video version of this tutorial, please refer to this link . An inverter gate, or NOR gate for short, is one of the essential logic gates used constructed digital circuits. As implied by its name, the NOT gate works by taking an input, inverting it, then outputting the inverted value. The NOT gate schematic symbol looks like a triangle with clown nose on the Output side (as shown in the Figure above). In logic circuits, inputs and outputs are binary, which means their value can either be 0 or 1. So: If NOT receives a 0 at the input, it will output 1 . If NOT receives 1 at the input, it will output 0 . To sum it up, the truth table for the NOT gate will be as the following: Input Output X F 0 1 1 0 The NOT gate can be algebraically represented as the following:  F = X' (or you can have a bar above the X) where :     F is the output and X is the input

How to Connect the Hercules Dual 15A 6-20V Motor Controller, Load its Library and Program it

The Hercules Motor Controller Board First, if you don't have the Arduino Integrated Development Environment (IDE) installed, please download and install it from this following link: https://www.arduino.cc/en/Main/Software Once you go to the link above, scroll down to the following section: If you are using a  Windows PC, click on Windows Installer link  for fast and easy installation process.  If you are using  a Raspberry Pi , click on the Linux ARM link. For other Linux distros (Ubuntu, etc...) use either Linux 64 or Linux 32 depending on what operating system you have installed. Second, download the software library provided by the manufacturer. Don't use the link on the official website of the product as the library there doesn't work. Instead, use the one on github. Here is the link:  https://github.com/Seeed-Studio/Hercules_Motor_Driver Once you open the link above, click on 'clone or download' then 'Download Z...