
FrogsAutomation (Customer) asked a question.
Hello,
I have built a couple of pieces of equipment that use a combination of Python, Arduino Uno, and Stepper Drivers + Motors for linear automation.
Python is running on a desktop computer and is the ‘master’ – I’ve programmed a graphical user interface in Python, so I can click on buttons on the GUI and the commands are then sent to the Arduino.
I should also add that I am using the Ethernet port on the computer to connect with a Ethernet camera.
Arduino Uno is Python’s ‘slave’ – essentially after starting up and doing tasks such as homing the linear translation stage, etc, the Arduino just waits to receive commands from Python, then does something, and after finishing it sends a message to Python saying it’s done with the task.
Communication between Python and Arduino is done using serial commands sent through a USB cable.
For linear motion, I use the Sure Step STP-DRV-6575 stepper drive + stepper motor, and I send pulse width modulation (PWM) commands from Arduino Uno to the stepper drive.
I use the AccelStepper library for the stepper drivers/motors.
To setup a stepper motor:
- #include <AccelStepper.h>
-
- AccelStepper z_axis(AccelStepper::DRIVER,3,2); #Initialize the stepper motor on pins 3 = step and 2 = direction
To move 1 rotation using the stepper motor with 200 steps/revolution:
- Z_axis.setMaxSpeed(200);
-
- Z_axis.setAcceleration(200);
-
- Z_axis.move(200);
-
- while(z_axis.distanceToGo() != 0)
-
- {
-
- Z_axis.run();
-
- }
A basic serial setup between Python and Arduino is:
- Serial.begin(38400);
-
- Serial.write(‘0’);
-
- char d;
-
- while(d != (’1’))
-
- {
-
- D = Serial.read();
-
- }
I like the idea of the P1AM-100 and the different modules to make things more rugged and making wiring more standardized, but I can’t figure out if I can duplicate what I am doing right now using the system.
1. In order to use the Productivity 1000 modules on the right side of the system, example code shows that the Serial library is used:
- // Open serial communications and wait for port to open:
-
- Serial.begin(115200);
-
- while (!Serial) {
-
- ; // wait for serial port to connect. Needed for native USB port only
-
- }
-
- SD_Begin();
After setting up the modules, can I still use the Serial library as what I’ve been doing for communication between Python and Arduino?
- Serial.write(‘0’);
-
- char d;
-
- while(d != (’1’))
-
- {
-
- D = Serial.read();
-
- }
2. Could I use the AccelStepper library as I’ve been doing, but this time use the P1-04PWM module:
Or alternatively, use the P1AM-GPIO shield? The issue I see with the GPIO shield is that it is running 3.3 V rather than 5V, and thus wouldn’t work out of the box with the Sure Step STP-DRV-6575 driver.
Thanks!
Hey FrogsAutomation,
This sounds like a really cool application. I really like the setup of using the python for high level user stuff and running the P1AM as a slave.
"1. In order to use the Productivity 1000 modules on the right side of the system, example code shows that the Serial library is used"
"2. Could I use the AccelStepper library as I’ve been doing, but this time use the P1-04PWM module:"
Thanks
Adam
Adam,
Thanks for the information and great news on the serial communication.
Given the stepper situation, sounds like I need to figure out how to convert the 3.3V PWM on the P1AM-GPIO shield to 5V.
You mentioned latency challenges. In the stepper run code, I run the stepper until it gets to position or a limit switch is hit. If the limit switch is wired to a Productivity 1000 module and so it's polling the limits, will this be a problem in terms of messing up positioning due to the latency?
I'll add that based on my system design, I should only ever hit a limit switch during startup for homing purposes, but that's assuming that everything is working.
Thank you.
Thanks
Adam
Adam,
Thanks for the information, this is very helpful!
Don't worry about the 3.3V. the STP-DRV-6575 driver just has a LED on the input with a small resistance. I know the DRV manual says like 4.8V for input, but I have been running stepper 24/7 with the same driver with no problems for months. My 3.3V pulse signal is from an ESP32 GPIO.
DrMartin - thank you for the response, that is very good to know.