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!

Owner
Pip
PhD in physics from the University of Manchester, using python to make life easier and for fun projects.
Pip
Beam designs for infinite Z 3D printers

A 3D printed beam that is as stiff as steel A while ago Naomi Wu 机械妖姬 very kindly sent us one of Creality's infinite-Z belt printers. Lots of people h

RepRap Ltd 105 Oct 22, 2022
Windhager myComfort custom component for Home Assistant

Windhager myComfort custom component for Home Assistant

5 Apr 27, 2022
The ABR Control library is a python package for the control and path planning of robotic arms in real or simulated environments.

The ABR Control library is a python package for the control and path planning of robotic arms in real or simulated environments. ABR Control provides API's for the Mujoco, CoppeliaSim (formerly known

Applied Brain Research 277 Jan 05, 2023
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
A python script for Homeassistant that counts down the days to birthdays, anniversaries etc

Date Countdown A python script for Homeassistant that counts down the days to birthdays, anniversaries etc Important note I no longer use homeassistan

Marc Forth 21 Mar 12, 2022
Trajectory optimization package for Mini-Pupper robot

Trajectory optimization package for Mini-Pupper robot Purpose of this repository is to provide low-torque and low-impact trajectory for Mini-Pupper qu

Sotaro Katayama 38 Aug 17, 2022
Play music on Raspberry Pi Pico Without CPU involvement

MicroPython_PIO_Music_DMA Play music on Raspberry Pi Pico Without CPU involvement This is based on PIOBeep (https://github.com/benevpi/pico_pio_buzz)

3 Nov 27, 2022
raspberry pi servo control using pca9685

RPi_servo-control_pca9685 raspberry pi 180° servo control using pca9685 Requirements Requires you to have the adafruit servokit library installed You

1 Jan 10, 2022
This Home Assistant custom component adding support for controlling Midea dehumidifiers on local network.

This custom component for Home assistant adds support for Midea dehumidifier appliances via the local area network. homeassistant-midea-dehumidifier-l

Nenad Bogojevic 91 Dec 28, 2022
A simple small scale electric car was build which can be driven by remote control and features a fully autonomous parking procedure.

personal-autonomous-parking-car-raspberry A simple electric car model was build using Raspbery pi. The car has remote control and autonomous operation

Kostas Ziovas 2 Jan 26, 2022
DOS-like OS for RP2040 basic microcontroller boards

Micropython DOS-like OS for RP2040 microcontroller boards. Check out the demo video at https://www.youtube.com/watch?v=Az_oiq8GE4Y To start the OS typ

RetiredWizard 58 Dec 27, 2022
EuroPi: A reprogrammable Eurorack project based on the Raspberry Pi Pico

EuroPi The EuroPi is a fully user reprogrammable module based on the Raspberry Pi Pico, which allows users to process inputs and controls to produce o

Allen Synthesis 218 Jan 01, 2023
A low power 1U Raspberry Pi cluster server for inexpensive colocation.

Raspberry Pi 1U Server There are server colocation providers that allow hosting a 1U server for as low as $30/month, but there's a catch: There are re

Paul Brown 627 Dec 31, 2022
Control DJI Tello with Raspberry Pi and PS4 Controller

Control-DJI-Tello-with-Raspberry-Pi-and-PS4-Controller Demo of this project see

MohammadReza Sharifi 24 Aug 11, 2022
DongshanPI Seven for STM32MP157DAC.

STM32MP1 Buildroot External Tree

DongshanPI 14 May 06, 2022
ENC28J60 Ethernet chip driver for MicroPython (RP2)

micropy-ENC28J60 ENC28J60 Ethernet chip driver for MicroPython v1.17 (RP2) Rationale ENC28J60 is a popular and cheap module for DIY projects. At the m

11 Nov 16, 2022
A 3rd party Moonraker component to create timelapse of 3D prints.

A 3rd party Moonraker component to create timelapse of 3D prints.

Mainsail-Crew 166 Dec 26, 2022
Create (templateable) cameras that display qr codes in homeassistant

QRCam This custom component creates cameras displaying qrcodes. The QRCodes can be static or generated from templates. If you use a template as conten

Jannes Müller 5 Oct 06, 2022
Open source home automation that puts local control and privacy first.

Home Assistant Open source home automation that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY enthusiast

Home Assistant 57k Jan 01, 2023
Monitor an EnvisaLink alarm module running Honeywell firmware, and set a Nest device to Home/Away depending on whether the alarm is Disarmed/Away.

Nestalarm Monitor an EnvisaLink alarm module running Honeywell firmware, and set a Nest device to Home/Away depending on whether the alarm is Disarmed

1 Dec 30, 2021