Announcement

Collapse
No announcement yet.

Arduino - Stepper Motor Controller

Collapse
X
Collapse

  • Arduino - Stepper Motor Controller

    PES-2605 is an easy-to-use stepper motor controller for Arduino Uno and Mega, which uses micro-stepping method to precisely control stepper motor.
    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



    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.






    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);
    Where expansionId is address of expansion board that are set via DIP switch on expansion board. By using the different expansionId, we can stack multiple expansion board on a single Arduino Uno or Mega.
    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);
      These functions are optional and used for advanced setting. Refer to PHPoC Shield Expansion Library Reference for more information about these functions.
    • 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)
    In the second run of loop() function
    • 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)
    This process is repeated in the next loops.




    See Also


    References
      Posting comments is disabled.

    Categories

    Collapse

    Latest Articles

    Collapse

    • Arduino - RS-485 Expansion Board
      support
      PES-2607 is an easy-to-use RS422/RS485 Expansion Board for Arduino Uno and Mega, which allows Arduino to exchange data with serial device via RS422 or RS485.
      Especially, Arduino does NOT use UART pins to communicate with RS422/RS485 expansion board. Therefore, users can use Arduino UART pins for other purposes.
      Moreover, A single Arduino Uno/Mega can communicate with multiple RS422/RS485 expansion boards (up to 14) without using Arduino UART pins.

      Library and examples for...
      11-13-2018, 03:45 PM
    • Arduino - RS-422 Expansion Board
      support
      PES-2607 is an easy-to-use RS422/RS485 Expansion Board for Arduino Uno and Mega, which allows Arduino to exchange data with serial device via RS422 or RS485.
      Especially, Arduino does NOT use UART pins to communicate with RS422/RS485 expansion board. Therefore, users can use Arduino UART pins for other purposes.
      Moreover, A single Arduino Uno/Mega can communicate with multiple RS422/RS485 expansion boards (up to 14) without using Arduino UART pins.

      Library and examples for...
      11-13-2018, 03:44 PM
    • Arduino - RS-232 Expansion Board
      support
      PES-2606 is an easy-to-use RS-232 Expansion Board for Arduino Uno and Mega, which allows Arduino to exchange data with serial device via RS-232.
      Especially, Arduino does NOT use UART pins to communicate with RS-232 expansion board. Therefore, users can use Arduino UART pins for other purposes.
      Moreover, A single Arduino Uno/Mega can communicate with multiple RS-232 expansion boards (up to 14) without using Arduino UART pins.

      Library and example for the RS-232 expansion board...
      11-13-2018, 03:43 PM
    • Arduino - Stepper Motor Controller
      support
      PES-2605 is an easy-to-use stepper motor controller for Arduino Uno and Mega, which uses micro-stepping method to precisely control stepper motor.
      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...
      11-13-2018, 03:41 PM
    • Arduino - DC Motor Controller
      support
      PES-2604 is an easy-to-use DC motor controller for Arduino Uno and Mega.
      Library and example for the DC motor controller are part of of PhpocExpansion library for Arduino. The library reference is available here.

      This tutorial shows how to use the DC motor controller with an example of PhpocExpansion library for Arduino.


      Hardware Required...
      11-13-2018, 03:40 PM
    • Arduino - Digital Input Board
      support
      PES-2602 is an easy-to-use 4-port Input Expansion Board for Arduino Uno and Mega, which allows Arduino to monitor state of DC electric device. In addition, it can monitor NPN, PNP and dry contact(relay).
      Library and example for the 4-port input expansion board are part of of PhpocExpansion library for Arduino. The library reference is available here.

      This tutorial shows how to use 4-port input expansion board with an example of PhpocExpansion library for Arduino.

      ...
      11-13-2018, 03:39 PM
    Working...
    X