If I run on Raspberry Pi some Python commands from the shell they are executed, but not from scripts

74 Views Asked by At

I'm trying to control a robot via a Raspberry Pi, using Python language. If I run the commands from the shell they work fine. If I call them from a *.py script the robot doesn't move. If in the script I put the command print('hello') the word 'hello' is displayed but the motors still do not move. How can I solve the problem? Thank you

enter image description here

from gpiozero import Motor

motor1 = Motor(4, 14)
motor2 = Motor(17, 27)

motor1.forward()
motor2.forward()

UPDATE: I solved the problem with sleep(5) after the command for move motors. Thanks!!!

1

There are 1 best solutions below

3
spaceKelan On

did you check this one, maybe the problem is related to the library https://stackoverflow.com/a/72207592/11594679

alternatively, did you check, if the path of the library is a problem. Do you call the script with the same python version, that you execute as shell? Maybe the gpio library is not installed for the one you call the script with.