Stepper motor control from Python

Greetings gents!

I'm stuck with my project and looking for advice from experienced ones.

I need to operate stepper motor from Python program. Stepper motor is controlling Z axis of 3D printer (its actually not 3D printer at all but it's hard to describe so imagine 3D printer with only Z axis working). The program is tracking some parameter changing over time and based on the value of the parameter it should move printer head up or down or to some particular position (min aka 0, max, etc).
Also I need the program to check min and max positions using 2 end buttons.

Parts I have:
Arduino Mega 2560 (Repetier Firmware by default)
Ramps1.4
DRV8825 drivers
MT-1703HS120AW stepper motors
End buttons

What I need to do from python:

  1. Run motor to find min (I.e. 0) and max position using 2 end buttons
  2. Move to particular position
  3. Move up/down with particular speed

Arduino is currently flashed with Repetier firmware but I'd use any solution which is easier to learn how to deal with because I'm coding noob (I mean absolutely noob).

Any help is very welcome!
Thanks in advance!

I presume Repetier deals with GCode so the simplest thing is probably to figure out the GCode messages that are needed for each action and get the Python program to send them.

I think there is Repetier program for the PC that acts as a console for a 3D printer. I use a program called Pronterface. With one of those programs you can experiment with GCode. There are lots of websites that explain GCode. You should be able to do what you want with some very simple GCode.

...R

Robin2:
I presume Repetier deals with GCode so the simplest thing is probably to figure out the GCode messages that are needed for each action and get the Python program to send them.

I think there is Repetier program for the PC that acts as a console for a 3D printer. I use a program called Pronterface. With one of those programs you can experiment with GCode. There are lots of websites that explain GCode. You should be able to do what you want with some very simple GCode.

...R

G-code itself is easy, the question is how to send it from Python to arduino and how to make arduino actually run them. I can send g-code from Repetier-host, the PC software for 3D printers, I can save it to file, but I have no idea how to push these commands avoiding Repetier-host or how to force Repetier-host to send them by Python. So the mystery lies between Python (full criteria for choosing which gcode to send is already coded) and stepper motor (I.e. I could find no copy-paste solution easy enough to understand and customize)

Getting Python to send a GCode message is straightforward

# this is Python code
gcodeMessage = "G0Z23"
serialPort.write(gcodeMessage.encode('utf-8')) # encode needed for Python3

The more complex part is figuring out how to deal with the responses from Repetier which tell the PC that it is ready for more data. I presume this is well covered in the Repetier documentation.

This Simple Python - Arduino demo may give you some ideas. But keep in mind that you will need to adapt the ideas to whatever is required by Repetier. For example I doubt if it expects messages to be surrounded by '<' and '>'

...R

Robin2:
Getting Python to send a GCode message is straightforward

# this is Python code

gcodeMessage = "G0Z23"
serialPort.write(gcodeMessage.encode('utf-8')) # encode needed for Python3




The more complex part is figuring out how to deal with the responses from Repetier which tell the PC that it is ready for more data. I presume this is well covered in the Repetier documentation.


This [Simple Python - Arduino demo](http://forum.arduino.cc/index.php?topic=598209.) may give you some ideas. But keep in mind that you will need to adapt the ideas to whatever is required by Repetier. For example I doubt if it expects messages to be surrounded by '<' and '>'

...R

That piece of code is already something, thanks. Didn't expect the received messages to be any important