Get Stepper Motor Positions From SD Card

by RonFrtek in Circuits > Arduino

545 Views, 2 Favorites, 0 Comments

Get Stepper Motor Positions From SD Card

Get Stepper Motor Positions From SD Card using Arduino

In this tutorial we are going to read stepper motor positions from the SD card where we saved a text file with the amount of steps. You can set both directions steps.

Watch the Video!

What You Will Need

STORAGE 1-500x500.jpg
stepper.jpg
F5OFEUQJJ4ZYFKY.LARGE.jpg
breadboard.png
VisuinoAdvrtisemenESPNowESP32C3-1.jpg
FZEK4WBK3XGYAP0.LARGE.jpg
sd card.png
  • Arduino UNO (Or any other Arduino)
  • SD card module
  • SD card to store a file
  • Stepper motor 28byj-48 & stepper motor driver board
  • Jumper wires
  • Breadboard
  • Visuino program: Download Visuino


Brought by PCBWay

FHUQHJ6LF9Y8DUL.png
2022-08-26_13-41-18.jpg

Thank you PCBWay for supporting this tutorial and helping users learn more about electronics.

NEW! Now you can get Aluminum PCB & FLEX PCB in their Special Offer!

What I like about the PCBWay is that you can get 10 boards for approximately $5 which is really cost effective for professional made boards, not to mention how much time you save!

Go check them out here. They also offer a lot of other stuff in case you might need it like assembly3D printingCNC machining and a lot more.

The Circuit

2023-04-22_12-58-41.jpg
  • Connect SD card Module pin GND to Arduino pin GND
  • Connect SD card Module pin VCC to Arduino pin 5V
  • Connect SD card Module pin SCK to Arduino digital pin 13
  • Connect SD card Module pin MISO to Arduino digital pin 12
  • Connect SD card Module pin MOSI to Arduino digital pin 11
  • Connect SD card Module pin CS to Arduino digital pin 10
  • Connect Stepper Motor to Stepper Motor Driver
  • Connect Arduino pin [5V] to Driver Board pin [VCC]
  • Connect Arduino pin [GND] to Driver Board pin [GND]
  • Connect Arduino digital pin [2] to Driver Board pin [IN1]
  • Connect Arduino digital pin [3] to Driver Board pin [IN2]
  • Connect Arduino digital pin [4] to Driver Board pin [IN3]
  • Connect Arduino digital pin [5] to Driver Board pin [IN4]


Prepare the SD Card

2023-04-22_23-36-52.png

In a Notepad type the amount of steps in each line, if you want to change the direction just add the minus (-) in front of the number and save it to the SD Card in file "STEPPER.TXT"

Start Visuino, and Select the Arduino UNO Board Type

FD9ZV5DKU43CVCH.jpg
Visuino-Select-Board-UNO.jpg

The Visuino: https://www.visuino.eu needs to be installed. 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 Components

2023-04-22_13-39-35.jpg
2023-04-22_13-40-17.jpg
2023-04-22_13-42-17.jpg
2023-04-22_13-42-43.jpg
2023-04-22_13-43-43.jpg
2023-04-22_13-44-26.jpg
2023-04-22_13-44-53.jpg
2023-04-22_13-45-50.jpg
2023-04-22_13-46-43.jpg
F1M8P8ML8LN1AJC.jpg
F46KRG9L8K7M1HD.jpg
FH7T9VNL8K7M1HC.jpg
  • Add "Pulse Generator" component
  • Add "Counter" component
  • Add "Micro SD Card Module" component
  • Add "Text Multi Source" component
  • Add "Replace Text" component
  • Add "Text To Integer" component
  • Add "Integer Multi Source" component
  • Add "Contains Text" component
  • Add "Up/Down Counter" component
  • Add "4 Wire Stepper Motor" component
  • Add "Compare Integer Value" component
  • Add "Unsigned To Digital" component

In Visuino Set Components

2023-04-22_13-49-15.jpg
FU51LO2L8LN1B75.jpg
2023-04-22_13-52-26.jpg
FY9UXMLL8LN1B73.jpg
FV1UT5RL8LN1B72.jpg
2023-04-22_13-54-37.jpg
2023-04-22_13-58-16.jpg
2023-04-22_14-01-29.jpg
2023-04-22_14-03-24.jpg
2023-04-22_14-06-08.jpg
2023-04-22_14-06-30.jpg
  • Select "PulseGenerator1" and in the properties window set "Frequency" to 500
  • If you want to set Stepper motor to run faster or slower then adjust the Frequency of the "PulseGenerator1"


  • Double click on the "SDCard1" and in the "Elements" window drag "File" to the left side and in the properties window set "Path Name" to STEPPER.TXT
  • Select "Elements" and click on the 3 dots button and in the new "Elements" window:
  • Drag "Read Seek" to the left side and in the properties window select "Position" and click on the pin icon and select "Cardinal SinkPin"
  • Drag "Read Text Line" to the left
  • Close both "Elements" windows


  • Select "ReplaceText1" and in the properties window set "From Value" to -
  • Select "ContainsText1" and in the properties window set "Text" to -
  • Select "UpDownCounter1" and in the properties window select "Initial Value" to and click on the pin icon and select "Integer SinkPin"
  • Select "UpDownCounter1" and in the properties window set "Min" > "Roll Over" to False and "Min" > "Value" to 0
  • Select "UnsignedToDigital1" and in the properties window set "Output pins" to 1
  • Select "Stepper1" and in the properties select "Reversedand click on the Pin Icon and select "Boolean SinkPin"


In Visuino Connect Components

2023-04-22_14-07-39.jpg
2023-04-22_14-08-12.jpg
stepper-sd-csrd.png
  • Connect "SDCard1" pin [SPI] to "Arduino" pin [SPI]
  • Connect "SDCard1" pin [Chip Select] to "Arduino" Digital pin [10]
  • Connect "Counter1" pin [Out] to "SDCard1" > "Read Seek1" pin [Position]
  • Connect "Counter1" pin [Out] to "SDCard1" > "Read Text Line1" pin [Clock]
  • Connect "SDCard1" > "Read Text Line1" pin [Out] to "TextMultiSource1" pin [In]


  • Connect TextMultiSource1" pin [0] to "ContainsText1" pin [In]
  • Connect "ContainsText1" pin [Out] to "Stepper1" pin [Enabled]
  • Connect TextMultiSource1" pin [1] to "ReplaceText1" pin [In]
  • Connect ReplaceText1" pin [Out] to "TextToInteger1" pin [In]
  • Connect TextToInteger1" pin [Out] to "IntegerMultiSource1" pin [In]
  • Connect IntegerMultiSource1" pin [0] to "UpDownCounter1" pin [Initial Value]
  • Connect IntegerMultiSource1" pin [1] to "UpDownCounter1" pin [Reset]
  • Connect PulseGenerator1" pin [Out] to "UpDownCounter1" pin [Down]
  • Connect "UpDownCounter1" pin [Out] to "UnsignedToDigital1" pin [In]
  • Connect "UpDownCounter1" pin [Out] to "CompareValue1" pin [In]
  • Connect "CompareValue1" pin [Out] to "Counter1" pin [In]

Generate, Compile, and Upload the Arduino Code

Visuino-Compile-UNO.jpg

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, The positions for the Stepper motor will start to rotate and when the amount of steps from the first line is reached it will go to the next line of steps and start to rotate.

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