Library and example for the stepper motor controller are part of of PhpocExpansion library for Arduino. The library reference is available here.
This tutorial shows how to use the step motor controller with an example of PhpocExpansion library for Arduino.
Hardware Required
- Arduino Uno or Mega
- USB Cable for Arduino.
- PHPoC Shield R2 or PHPoC WiFi Shield R2
- Stepper Motor Controller PES-2605
- A bipolar stepper motor or unipolar stepper motor
Wiring
- Stack PHPoC Shield or PHPoC WiFi Shield on Arduino
- Stack Stepper Motor Controller PES-2604 on PHPoC Shield or PHPoC WiFi Shield
- Connect stepper motor to terminal block of Stepper Motor Controller PES-2605
- Bipolar stepper motor
- Unipolar stepper motor: there are two ways to connect a unipolar stepper motor to terminal block of PES-2605. User can choose one of them.
- Bipolar stepper motor

Install Arduino IDE
If you have not install Arduino IDE yet, please download and install Arduino IDE .
Install Library
- Run Arduino IDE.
- Navigate to Sketch > Include Library > Manage Libraries
- Search "Phpoc Expansion" on search bar of the Library Manager.
- Select the PhpocExpansion library and press the [Install] button.
- Restart Arduino IDE for the next step.
Source Code
- Connect Arduino to PC via usb cable
- Open Arduino IDE
- Open "ExpansionStepperMotor" example
- Compiles the example code and uploads to Arduino by clicking "Upload" button on Arduino IDE
- Open "Serial Monitor" tool on Arduino IDE to see the output log:
Code Explanation
At the beginning
we need to create and stepper motor object:
Code:
ExpansionStepper step(expansionId);
You can change it and map it to the below to know the value.
Note that: Stepper Motor Controller is one of the expansion boards. List of expansion for arduino is available here
In setup() function
- Phpoc.begin() and Expansion.begin() functions must be used to initial PHPoC [WiFi] Shield and expansion board, repectively.
- Serial.println(step.getName()) function is used optionally to get name of expansion board and print it to serial.
- There are some functions has been commented.
Code://step.setVrefStop(2); //step.setVrefDrive(8); //step.setVrefLock(0); //step.setResonance(120, 250); //step.setPosition(2000);
- step.setMode(32), step.setSpeed(20000), and step.setAccel(50000, 50000) functions are used to set microstep resolution, speed, and acceleration and deceleration, respectively.
In loop() function
There are some functions are used.
- step.getState(): get state of step motor.
- step.getPosition(): to get the curent position of stepper motor
- step.stepMove(stepNum): to make motor move to a relative position, which is stepNum steps away from current position. This function is blocking
- step.stepGoto(stepNum): to make motor move to a absolute position, which is stepNum steps away from initial position. This function is non-blocking.
Since step.stepGoto(stepNum) is non-blocking function, this example used while(step.getState()) to wait until motor stops.
Note that: we can change the moving direction and position immediately by using step.stepGoto(stepNum), even motor has not stopped.
Result Explanation
Initial position of motor is zero. Unit of position is step.
In the first run of loop() function:
- step.stepMove(10000): this makes motor move 10000 steps in a direction. After this function, new position of motor = 0 + 10000 = 10000 (steps).
- step.stepMove(-5000): this make motor move 5000 steps in a reverse direction. After this function, new position of motor = 10000 + (-5000) = 5000 (steps)
- step.stepGoto(10000): his make motor move to absolute position, regardless current position. Therefore, new new position of motor = 10000 (steps)
- step.stepGoto(-10000): his make motor move to absolute position, regardless current position. Therefore, new new position of motor = -10000 (steps)
- step.stepMove(10000): this makes motor move 10000 steps in a direction. After this function, new position of motor = -10000 + 10000 = 0 (steps).
- step.stepMove(-5000): this make motor move 5000 steps in a reverse direction. After this function, new position of motor = 0+ (-5000) = -5000 (steps)
- step.stepGoto(10000): his make motor move to absolute position, regardless current position. Therefore, new new position of motor = 10000 (steps)
- step.stepGoto(-10000): his make motor move to absolute position, regardless current position. Therefore, new new position of motor = -10000 (steps)
See Also
- Arduino - Relay Expansion Board - PES-2601
- Arduino - Digital Input Expansion Board - PES-2602
- Arduino - DC Motor Controller - PES-2604
- Arduino - Stepper Motor Controller - PES-2605
- Arduino - RS-232 Expansion Board - PES-2606
- Arduino - RS-422 Expansion Board - PES-2607
- Arduino - RS-485 Expansion Board - PES-2607
References