Considering a new project using P1AM-100, questions on stepper driver and serial communication

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:

 

  1. #include <AccelStepper.h>
  2.  
  3. 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:

 

  1. Z_axis.setMaxSpeed(200);
  2.  
  3. Z_axis.setAcceleration(200);
  4.  
  5. Z_axis.move(200);
  6.  
  7. while(z_axis.distanceToGo() != 0)
  8.  
  9. {
  10.  
  11. Z_axis.run();
  12.  
  13. }

 

 

 

 A basic serial setup between Python and Arduino is:

 

  1. Serial.begin(38400);
  2.  
  3. Serial.write(‘0’);
  4.  
  5. char d;
  6.  
  7. while(d != (’1’))
  8.  
  9. {
  10.  
  11. D = Serial.read();
  12.  
  13. }

 

 

 

 

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:

 

  1. // Open serial communications and wait for port to open:
  2.  
  3. Serial.begin(115200);
  4.  
  5. while (!Serial) {
  6.  
  7. ; // wait for serial port to connect. Needed for native USB port only
  8.  
  9. }
  10.  
  11. 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?

 

 

  1. Serial.write(‘0’);
  2.  
  3. char d;
  4.  
  5. while(d != (’1’))
  6.  
  7. {
  8.  
  9. D = Serial.read();
  10.  
  11. }

 

 

 

 

2. Could I use the AccelStepper library as I’ve been doing, but this time use the P1-04PWM module:

https://www.automationdirect.com/adc/shopping/catalog/programmable_controllers/open_source_controllers_(arduino-compatible)/productivityopen_(arduino-compatible)/industrial_i-z-o_(p1k)/p1-04pwm

 

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.

 

https://www.automationdirect.com/adc/shopping/catalog/programmable_controllers/open_source_controllers_(arduino-compatible)/productivityopen_(arduino-compatible)/controllers_-a-_shields/p1am-gpio

 

Thanks!

 


  • FACTS_AdamC (AutomationDirect)

    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"

    • Definitely! The serial library isn't used for any actual IO module comms, just to show functionality during examples. If the extra printouts from the library are causing problems, go into "defines.h" and comment out "#define DEBUG_PRINT_ON" in line 31. This should suppress most messages.

    "2. Could I use the AccelStepper library as I’ve been doing, but this time use the P1-04PWM module:"

    • Currently, the AccelStepper library isn't compatible with our P1 IO modules like the P1-04PWM. I have casually re-written some of the functions to approximate things, but nothing that is tested or robust. The trick with the P1-04PWM will be adjusting speed to account for any latency in backplane communications to keep things accurate. Possible, but will take a few more lines of code.

     

    Thanks

    Adam

     

     

     

    Expand Post
  • FrogsAutomation (Customer)

    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.

    Expand Post
    • FACTS_AdamC (AutomationDirect)

      • 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.
        • Easiest solutions will probably be a MOSFET or a shifter IC like this: https://www.adafruit.com/product/1787. When looking at solutions, make sure they drive about 6mA or so. Both can be installed easily in a P1AM-PROTO
      •  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?
        • You'll want to get a few measurements of your bus performance with your specific module stackup and function calls and factor in that latency. For instance: if it takes 2 millisenconds to turn the P1-04PWM on/off, at 2kHz that would be 4 extra steps. There's a few different ways to tackle this issue that can be mixed and matched to some degree (e.g. timing estimates for over/undershoot, encoders, using faster IO on enable/limit switches)

       

      Thanks

      Adam

      Expand Post
  • DrMartin (Customer)

    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.

  • FrogsAutomation (Customer)

    DrMartin - thank you for the response, that is very good to know.