Arduino and Python - Problems with stepper motor and limit switch

Hello,
I use an Arduino Uno with Python and Py2duino. For now, I want to control a nema23 stepper motor with a TB6600, but when I want to control the step with a limit switch, it becomes slowly
this is my code :

When i use this, the stepper is moving fast.
MonstepperX.move(2000,0.8)
But When i put't in for bocle the stepper move quite slowly.
def stop_x():
  for i in range(1,50000):
  MonstepperX.move(20,0.8)
  i += 1
  if limitswitchX.read() == 0:
         break
Now, my question is: is there any way to make the stepper go faster using Python?
I really need to use Python instead of using Arduino's IDE directly. think for help.

You have provided very little information with which to help you.

You need to post the complete Arduino program and also provide some examples of the messages that the Python program sends to the Arduino.

...R
Stepper Motor Basics
Simple Stepper Code

Simple Python - Arduino demo

for Arduino program i use this to communicate with python
[toolbox_arduino_v4.ino ](https://github.com/xpessoles/Cycle_01_DecouverteSII/tree/master/Chaine_Fonctionnelle/02_Fonction_Traiter/TP_Traiter_Pyhon_Arduino/Librairie py2duino v4/toolbox_arduino_v4)
and for python i use this librairie
[Py2duino](https://github.com/xpessoles/Cycle_01_DecouverteSII/blob/master/Chaine_Fonctionnelle/02_Fonction_Traiter/TP_Traiter_Pyhon_Arduino/Librairie py2duino v4/py2duino.py)

We are missing your code - where for instance is the declaration of MonstepperX?

saadtarres:
for Arduino program i use this to communicate with python

Please post the code here so we don't have to go to some other website. Also be sure to post the code that you are actually using.

Help us to help you.

See How to get the best out of the Forum

...R

saadtarres:
Where I insert the limitswitchX.read() == 0: condition I got this error
""Erreur de transmission ou bien le pin digital n'a pas ete bien assigne au prealable avec arduino.pinMode"

Maybe you would find it easier to use the French section of the Forum?

If you wish to continue with English then you have not yet posted your Arduino program.

Looking at the Python program in Reply #5 I have the following questions ...

What is the Python program running on?
What is it trying to do?

I am not familiar with py2duino (though I use Python with my own Arduino boards) but it seems as if the Python program is trying to do stuff that should really be done on your Arduino.

...R

saadtarres:
i alrady put the link of the arduino code

Help us to help you. Post your code here so we don't have to go chasing after links.

i want to run cnc mahcine with an arduino uno from a python code interface,

It would be a good start if you tell us what the CNC machine is and what software it is using. The GRBL program is an obvious candidate and you can use the "Universal GCode Sender" program to control a CNC machine that uses GRBL.

On the other hand if you have written your own CNC control program you need to provide details of the commands it expects to receive.

You should NOT be expecting a Python program to do low-level control of a CNC machine - the link between Python and the Arduino is just not fast enough. The Python program should send a message to the Arduino telling it how many steps to move and how fast and then let the Arduino do the detailed stuff.

...R

In addition to what Robin2 wrote, your Arduino program should keep track of how close it is to the limit switch by adding and subtracting steps. The first thing the Arduino program must do is find the limit switch and set your counter to zero. Then any movement of the stepper means add/subtract from that counter.
A program may be slow because it is doing something to test for a limit switch, rather than using a step count.
Paul

saadtarres:
I now use this program to control my arduino uno via GRBL but i tell my this error that serialPort dont found write

As you seem to be inexperienced why not use an off-the-shelf program to communicate with GRBL - such as Universal GCode Sender

And for problems with a Python program you should seek advice on a Forum that deals with Python programming.

...R