Download as pdf or txt
Download as pdf or txt
You are on page 1of 45

instructables

Control Stepper Motor Using a NEXTION Display and Arduino

by RonFrtek

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!

https://www.youtube.com/watch?v=YU2iN06gzxI

Step 1: What You Will Need

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

Control Stepper Motor Using a NEXTION Display and Arduino: Page 1


Control Stepper Motor Using a NEXTION Display and Arduino: Page 2
Control Stepper Motor Using a NEXTION Display and Arduino: Page 3
Control Stepper Motor Using a NEXTION Display and Arduino: Page 4
Control Stepper Motor Using a NEXTION Display and Arduino: Page 5
Control Stepper Motor Using a NEXTION Display and Arduino: Page 6
Control Stepper Motor Using a NEXTION Display and Arduino: Page 7
Control Stepper Motor Using a NEXTION Display and Arduino: Page 8
Step 2: The Circuit

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]
Control Stepper Motor Using a NEXTION Display and Arduino: Page 9
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

Control Stepper Motor Using a NEXTION Display and Arduino: Page 10


Step 3: Nextion Editor

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" nd:
"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"
Control Stepper Motor Using a NEXTION Display and Arduino: Page 11
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

Control Stepper Motor Using a NEXTION Display and Arduino: Page 12


Control Stepper Motor Using a NEXTION Display and Arduino: Page 13
Control Stepper Motor Using a NEXTION Display and Arduino: Page 14
Control Stepper Motor Using a NEXTION Display and Arduino: Page 15
Control Stepper Motor Using a NEXTION Display and Arduino: Page 16
Control Stepper Motor Using a NEXTION Display and Arduino: Page 17
Control Stepper Motor Using a NEXTION Display and Arduino: Page 18
Control Stepper Motor Using a NEXTION Display and Arduino: Page 19
Control Stepper Motor Using a NEXTION Display and Arduino: Page 20
Control Stepper Motor Using a NEXTION Display and Arduino: Page 21
Step 4: Start Visuino, and Select the Arduino UNO Board Type

Start Visuino as shown in the rst 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

Control Stepper Motor Using a NEXTION Display and Arduino: Page 22


Control Stepper Motor Using a NEXTION Display and Arduino: Page 23
Step 5: In Visuino Add & Set Components

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"

Control Stepper Motor Using a NEXTION Display and Arduino: Page 24


Control Stepper Motor Using a NEXTION Display and Arduino: Page 25
Control Stepper Motor Using a NEXTION Display and Arduino: Page 26
Control Stepper Motor Using a NEXTION Display and Arduino: Page 27
Control Stepper Motor Using a NEXTION Display and Arduino: Page 28
Control Stepper Motor Using a NEXTION Display and Arduino: Page 29
Control Stepper Motor Using a NEXTION Display and Arduino: Page 30
Control Stepper Motor Using a NEXTION Display and Arduino: Page 31
Control Stepper Motor Using a NEXTION Display and Arduino: Page 32
Control Stepper Motor Using a NEXTION Display and Arduino: Page 33
Control Stepper Motor Using a NEXTION Display and Arduino: Page 34
Control Stepper Motor Using a NEXTION Display and Arduino: Page 35
Control Stepper Motor Using a NEXTION Display and Arduino: Page 36
Control Stepper Motor Using a NEXTION Display and Arduino: Page 37
Control Stepper Motor Using a NEXTION Display and Arduino: Page 38
Control Stepper Motor Using a NEXTION Display and Arduino: Page 39
Control Stepper Motor Using a NEXTION Display and Arduino: Page 40
Control Stepper Motor Using a NEXTION Display and Arduino: Page 41
Control Stepper Motor Using a NEXTION Display and Arduino: Page 42
Step 6: In Visuino Connect Components

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]

Control Stepper Motor Using a NEXTION Display and Arduino: Page 43


Step 7: Generate, Compile, and Upload the Arduino Code

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.

Control Stepper Motor Using a NEXTION Display and Arduino: Page 44


Step 8: 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
Download
https://www.instructables.com/FCE/4ZM4/LG6K5CME/FCE4ZM4LG6K5CME.visuino

Control Stepper Motor Using a NEXTION Display and Arduino: Page 45

You might also like