Control Stepper Motor Using a NEXTION Display and Arduino

by RonFrtek in Circuits > Arduino

1994 Views, 7 Favorites, 0 Comments

Control Stepper Motor Using a NEXTION Display and Arduino

Control Stepper Motor Using a NEXTION Display and Arduino

In this tutorial we will use stepper driver A4988, NEMA17 stepper motor, Arduino Uno and Visuino to run a stepper motor for a certain amount of steps.

Watch the video!

What You Will Need

nextion-display.jpg
A4988.png
NEMA17.jpg
A4988 expansion board drv 8825 stepper motor.jpeg
VisuinoAdvrtisemenESPNowESP32C3-1.jpg
2022-02-22_18-01-07.jpg
jt-rd6006_dc-power-supply.png
FMT2X9VKEY93G5P.jpg
drv8825m.jpg
  • Arduino UNO (Or any other Arduino)
  • Nextion Editor: Download Nextion Editor
  • Nextion Display
  • Stepper motor NEMA 17
  • A4988 Stepper Motor Driver or (DRV8825)
  • Optional DRV8825/A4988 Stepper Driver Expansion Module
  • Jumper wires
  • Power Supply 12V
  • Visuino program: Download Visuino

The Circuit

2023-04-16_16-57-56.jpg
2023-04-16_16-46-23.jpg
  • Arduino Digital Pin 2 will be used for Steps
  • Arduino Digital Pin 3 will be used for Motor Direction

If using a Stepper Motor Driver Shield:

  • Connect Motor Shield GND pin to Arduino negative pin [GND]
  • Connect Motor Shield [5V] pin to Arduino positive pin [5V]
  • Connect Motor Shield GND pin to Power Supply negative pin [GND]
  • Connect Motor Shield [9V] pin to Power Supply positive pin [+]
  • Connect Motor Shield pin[S] to Arduino digital pin [2]
  • Connect Motor Shield pin[D] to Arduino digital pin [3]
  • Connect stepper motor as shown on the picture.


If using a Stepper Motor Driver 8825:

  • Connect DRV8825 GND pin to Arduino negative pin [GND]
  • Connect DRV8825 DIR pin to Arduino digital pin [3]
  • Connect DRV8825 STEP pin to Arduino digital pin [2]
  • Connect Power Supply for the motor to DRV8825 VMOT and GND
  • Connect Capacitor across VMOT and GND
  • Connect stepper motor as shown on the picture.


  • Connect Nextion Display VCC red wire to Arduino 5V pin
  • Connect Nextion Display GND black wire to Arduino GND pin
  • Connect Nextion Display Yellow wire (RX) wire to Arduino TX pin
  • Connect Nextion Display Blue wire (TX) wire to Arduino RX pin


Nextion Editor

FY5FQ84LDD3VKES.jpg
FNOX4N6LDD3VKEU.jpg
FGQHAUMLDD3VKET.jpg
2023-04-07_13-41-10.jpg
2023-04-07_13-41-42.jpg
2023-04-07_13-35-53.jpg
2023-04-07_13-44-16.jpg
2023-04-07_13-46-27.jpg
2023-04-07_13-56-37.jpg
2023-04-07_13-57-02.jpg
2023-04-07_13-58-44.jpg
2023-04-07_13-59-13.jpg
  • Download Nextion Editor and Install it
  • Start Nextion Editor
  • In the Nextion Editor click on the "New" button
  • In the Window set the name for the Project like "STEPPER"
  • In the "Setting" window select the Model of your Nextion Display & click "Ok"
  • Select Display Direction 90 & click "Ok"
  • In the Menu select "Tools">"Font Generator"
  • In the Font creator window set the name for your font and click "Generate Font", Save the Font, you will be asked "Add the generated font?" Click Yes
  • In the Editor on the left in the "Toolbox" find:
  • "Text" & drag it to the right
  • and in the Attribute window set "vscope" to global and "key" to numericKeyboard and "txt" to 0
  • "Slider" & drag it to the right and in the Attribute window set "maxval" to 100 & "minval" to 0
  • "Dual-state Button" & drag it to the right and in the Attribute window set "txt" to DIRECTION
  • "Button" & drag it to the right and in the Attribute window set "txt" to START
  • For each component you can set the color under "bco" in the Attribute window


  • For both buttons, slider and Text:
  • In the "Event" window > Touch Press Event" Check the "Send component ID"
  • In the "Event" window > Touch Release Event" Check the "Send component ID"
  • In the Toolbar click on the "Compile" button
  • In the Menu Select "File" > "TFT File Output"
  • Set the Output folder & click on the "Output" button
  • Save the File to the SD card
  • Insert the SD card to your Nextion Display
  • Power the Arduino and you will notice that the Nextion Display will start to Update it self
  • On the Finish disconnect the power and remove the SD card from the Nextion display


Start Visuino, and Select the Arduino UNO Board Type

select-board-uno.jpg
Visuino-Select-Board-UNO.jpg

Start Visuino as shown in the first picture Click on the "Tools" button on the Arduino component (Picture 1) in Visuino When the dialog appears, select "Arduino UNO" as shown on Picture 2

In Visuino Add & Set Components

F57G0DELDD3VL3L.jpg
2023-04-07_14-10-45.jpg
2023-04-07_14-12-08.jpg
2023-04-07_14-12-37.jpg
2023-04-07_14-12-53.jpg
2023-04-07_14-13-06.jpg
2023-04-07_14-13-24.jpg
2023-04-07_14-18-49.jpg
2023-04-07_14-21-42.jpg
2023-04-07_14-24-08.jpg
2023-04-07_14-25-51.jpg
2023-04-07_14-25-16.jpg
2023-04-07_14-54-09.jpg
2023-04-07_14-55-56.jpg
2023-04-07_14-56-16.jpg
2023-04-07_14-58-43.jpg
2023-04-07_14-59-05.jpg
2023-04-07_14-59-29.jpg
  • Add "Nextion Display" component
  • Double click on the "DisplayNextion1" And in the Elements window drag "Button" to the left side and in the properties window set "Element Name" to bt0
  • Drag another "Button" to the Left side and in the properties window set "Element Name" to b0
  • Drag "Get String" to the Left side and in the properties window set "Command" to: get t0.txt
  • Drag "Slider" to the Left side
  • Close the Elements window


  • Add "Text To Integer" component
  • Add "Multiply Analog By Value" component and in the properties window set "Value" to 1000
  • Add "Delay" component
  • Add 2X "Toggle(T) Flip-Flop" component
  • Add "Digital Multi Source" component
  • Add "Unsigned To Digital" component and in the properties window set "Output Pins" to 1
  • Add "Pulse Generator" generator and in the properties window set "Frequency (Hz)" to 2000 and click on the Pin icon and select "Float SinkPin" and Select "Enabled" and click on the Pin icon and select "BooleanSinkPin"
  • Add "Counter" component and in the properties window set "Max">"Value" to 0 and "Max">"Roll Over" to false and "Min">"Value" to 0 and "Min">"Roll Over" to false
  • Select "Max">"Value" and click on the Pin icon and select "Integer SinkPin"

In Visuino Connect Components

next-step.png
2023-04-07_15-04-08.jpg
  • Connect "DisplayNextion1" > "GetString1" Pin[Out] to "TextToInteger1" pin [In]
  • Connect "DisplayNextion1" > "Button1" Pin[Out] to "DisplayNextion1" > "GetString1" pin [Clock]
  • Connect "DisplayNextion1" > "Button1" Pin[Out] to "TFlipFlop2" pin [Clock]
  • Connect "DisplayNextion1" > "Button2" Pin[Out] to "Delay1" pin [Start]
  • Connect "DisplayNextion1" Pin[Out] to "Arduino" > "Serial [0]" pin [In]
  • Connect "TextToInteger1" pin [Out] to "Counter1" > Max pin[ Value]
  • Connect "DisplayNextion1" > "Slider1" Pin[Out] to "MultiplyByValue1" pin [In]
  • Connect "MultiplyByValue1" pin [Out] to "PulseGenerator1" pin [Frequency]
  • Connect "PulseGenerator1" pin [Out] to "Counter1" pin [In]
  • Connect "TFlipFlop1" pin [Out] to "DigitalMultiSource1" pin [In]
  • Connect "DigitalMultiSource1" pin [0] to "Counter1" pin [Reset]
  • Connect "DigitalMultiSource1" pin [1] to "PulseGenerator1" pin [Enabled]
  • Connect "TFlipFlop2" Pin[Out] to "Arduino" digital pin [3]
  • Connect "Counter1" pin [Out] to "UnsignedToDigital1" pin [In]
  • Connect "UnsignedToDigital1" Pin[Out] to "Arduino" digital pin [2]

Generate, Compile, and Upload the Arduino Code

2023-04-07_15-19-47.jpg
Visuino-Compile-UNO.jpg

Before Uploading Disconnect RX pin on Arduino and connect it back after the Upload.

In Visuino, at the bottom click on the "Build" Tab, make sure the correct port is selected, then click on the "Compile/Build and Upload" button.

Play

If you power the Arduino module and press the on the Text "1" on the Nextion Display you will be able to set the amount of steps, by changing the slider position you can adjust the stepper motor speed, by pressing on the button DIRECTION you can change the motor direction & if you press START the motor will start to rotate.


Congratulations! You have completed your project with Visuino. Also attached is the Visuino project, that I created for this Instructable, you can download it here and open it in Visuino: https://www.visuino.eu