For a robotics project, I have to connect a Raspberry Pi together with two Arduino’s.
Each Arduino controls two stepper stepper motors.
The raspberry pi is sort of the “brain” for the project and thus needs to control the arudino’s actions, often multiple in a row. They communicate over the serial port, therefore in python I use the “pyserial” framework.
My problem is, that I can’t know when exactly an arduino has completed powering the stepper motor so I can run the next action. Often it is crucial for me to know when the Arduino is finished. What I need is the following:
def control_arduino(command, nextcommand):
serial.write(command) # a command for the arduino to move motor x y steps
serial.wait_for_string("end") # a command initiated by the arduino stating that he completed moving the motor
serial2.write(nextcommand) # next command for the other arduino, but the first command has to be completed for this
serial2.wait_for_string("end")
print("ended doing x")
As of the current program, arduino 2 starts is action even if arduino 1 hasn’t even completed his actions due to the missing “wait_for” method.
diepzee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.