A script and GUI for controlling stepper motors from an arduino

Overview

Controlling-Stepper-Motors-with-Arduino-NEMA-

A python script and GUI for controlling 3 stepper motors in 3 directions (X, Y, Z) from an arduino (I was using nema 23 but it should work for others in general, maybe with some small changes).

I used an Arduino uno with usb connection, using pyfirmata to control it from python, the arduino pins (details below) were fed into 3 DM542 microstep drivers (powered with 24 V power supplies), and the outputs from the drivers were connected to the NEMA23 stepper motors through 3x custom (5-pin) XLR cables (using 4 of the connections).

For X, Y and Z directions I set up the pins as follows (but you can change it easily in the code) X direction pin - 3 pulse pin - 2 enable pin - 12 Y direction pin - 5 pulse pin - 4 enable pin - 11 Z direction pin - 7 pulse pin - 6 enable pin - 10

brief explanation of the pin type functions: direction - high (5V) or low (0V) depending on whether you want to drive forwards or backwards pulse - pulses between high and low, the driver will then interpret this (depending on the driver settings) as e.g. 400 pulses need to rotate the stepper drive one full rotation. So if this pin goes high to low 400 times your driver will rotate 360 degrees in this example. enable pin - when high this will block the driver from taking action when recieving pulses. In the end I didn't experience much push back so I left this low all the time but you can edit to set it high and then only low when the move loop is activated if you experience unwanted movement.

The GUI is quite basic, made using tkinter. I recommend first time you run it putting x,y and z in your e.g. 0 positions and saving those positions as 0. Note #1 that they can go to negative values. Note #2 that z is set up in cm and running backwards (ie higher up is a lower value) because this is how my physical z drive was set up, but changing that should be fairly straight forward! Here you can either set a position for x/y/z (or all 3) and start the system moving there. The positions text will update once they arrive in position. You can also set a jog size and then move either x y or z in those steps. There's a stop button in case of emergencies. If you hit stop the positions text will update to the position they reached when you hit stop. There's also the buttons 'set safe place' - the system will the current position, and if you later hit 'go to safe place' it will move there. Note that the system will always move first in x, then y, and last z. If you want to change the order just switch the order x y and z are checked and acted on at line 255 in the def movebutton. You can also set the speed in the GUI between fast, medium and slow, this just changes the sleep time between pulses sent to the drivers. You can change them easily. If fast is still not fast enough then decrease you drivers pulses per revolution settings if possible.

There are a few places in the code where you will need to set things specific to your setup (the COM port of the arduino, the arduino pins used, driver and thread settings, and the file directory for storing positions between uses if you want this). Elaborating on that last point, line 76, set a path to a folder you created called XYZ log. This will save the current XYZ positions (in a text file) if you close the GUI and load the most recent when you open the GUI.

I usually ran the script from a batch file on the desktop so that noone would accidentally edit the code (.bat file example included too). For this to work for you change the first "" contents to your python path and the second to the script path.

I'll upload some photos of the setup and a wiring diagram. I hope this is useful for someone else that is sick of trying to get labview to do what they want. Happy stepping!

You might also like...
This Home Assistant custom component adds support for controlling Midea dehumidiferes on local network.

This is a custom component for Home assistant that adds support for Midea dehumidifier appliances via the local area network. midea-dehumidifier-lan H

Controlling fireworks with micropython
Controlling fireworks with micropython

Controlling-fireworks-with-micropython How the code works line 1-4 from machine

GUI wrapper designed for convenient service work with TI CC1352/CC2538/CC2652 based Zigbee sticks or gateways. Packed into single executable file
GUI wrapper designed for convenient service work with TI CC1352/CC2538/CC2652 based Zigbee sticks or gateways. Packed into single executable file

ZigStar GW Multi tool is GUI wrapper firtsly designed for convenient service work with Zig Star LAN GW, but now supports any TI CC1352/CC2538/CC2652 b

Simple Python script to decode and verify an European Health Certificate QR-code

A simple Python script to decode and verify an European Health Certificate QR-code.

A install script for installing qtile and my configs on Raspberry Pi OS
A install script for installing qtile and my configs on Raspberry Pi OS

QPI OS - Qtile + Raspberry PI OS Qtile + Raspberry Pi OS :) Installation Run this command in the terminal

A script that publishes power usage data of iDrac enabled servers to an MQTT broker for integration into automation and power monitoring systems

iDracPowerMonitorMQTT This script publishes iDrac power draw data for iDrac 6 enabled servers to an MQTT broker. This can be used to integrate the pow

ArucoFollow - A script for Robot Operating System and it is a part of a project Robot
ArucoFollow - A script for Robot Operating System and it is a part of a project Robot

ArucoFollow ArucoFollow is a script for Robot Operating System and it is a part

A Python script to monitor the latest block on an LCD.
A Python script to monitor the latest block on an LCD.

PiHole-Monitoring A Python script to monitor the latest block on a lcd display. The first number represents the dns queries from the last 24h, the sec

A script for performing OTA update over BLE on ESP32

A script for performing OTA update over BLE on ESP32

Owner
Pip
PhD in physics from the University of Manchester, using python to make life easier and for fun projects.
Pip
This application works with serial communication. Use a simple gui to send and receive serial data from arduino and control leds and motor direction

This application works with serial communication. Use a simple gui to send and receive serial data from arduino and control leds and motor direction

ThyagoKZKR 2 Jul 18, 2022
Designed and coded a password manager in Python with Arduino integration

Designed and coded a password manager in Python with Arduino integration. The Program uses a master user to login, and stores account data such as usernames and passwords to the master user. While logging into the program with the master user the Arduino was used as a two-factor authentication key. The program detects a connection to the Arduino and checks if certain parameters are met before completing the login procedure.

Noah Colbourne 1 Jan 16, 2022
A IC scan test interface for Arduino

ICSCAN_ARDUINO Prerequisites Python 3.6 or higher arduino uno or nano what is this It is a bitstream tranceiver to test IC chip It sends bitstream to

Nifty Chips Laboratory 0 Sep 15, 2022
ArduinoWaterHeaterIOT - IoT Probe of a solar PV water heating system - Arduino, Python, MQTT, MySQL

ArduinoWaterHeaterIOT IoT Probe of a solar PV water heating system - Arduino, Raspberry Pi, Python, MQTT, MySQL The Arduino sends the AC and DC watts

Jacques Fourie 1 Jan 11, 2022
Doughskript interpreter for converting simple command sequences into executable Arduino C++ code.

Doughskript interpreter for converting simple command sequences into executable Arduino C++ code.

Svjatoslav 2 Jan 11, 2022
An arduino/ESP project that can play back G-Force data previously recorded

An arduino/ESP project that can play back G-Force data previously recorded

null 7 Apr 12, 2022
Python module for controlling Broadlink RM2/3 (Pro) remote controls, A1 sensor platforms and SP2/3 smartplugs

Python module for controlling Broadlink RM2/3 (Pro) remote controls, A1 sensor platforms and SP2/3 smartplugs

Matthew Garrett 1.2k Jan 4, 2023
🔆 A Python module for controlling power and brightness of the official Raspberry Pi 7

rpi-backlight A Python module for controlling power and brightness of the official Raspberry Pi 7" touch display. Note: This GIF was created using the

Linus Groh 238 Jan 8, 2023
An embedded application for toy-car controlling based on Raspberry Pi 3 Model B and AlphaBot2-Pi.

An embedded application for toy-car controlling based on Raspberry Pi 3 Model B and AlphaBot2-Pi. This is the source codes of my programming assignmen

StardustDL 4 Oct 19, 2022
A Python class for controlling the Pimoroni RGB Keypad for Raspberry Pi Pico

rgbkeypad A Python class for controlling the Pimoroni RGB Keypad for the Raspberry Pi Pico. Compatible with MicroPython and CircuitPython. keypad = RG

Martin O'Hanlon 43 Nov 11, 2022