Let’s move to the stepper motor. Now, we run the motor.py python script as root user in the console. It will interact with the emulated motor driver IC, which then moves the motor in the web view.
sudo python motor.py
We can see the motor is rotating as we have both a red mark on the stepper motor and a numeric value of the rotation angle.
Stepper motor executes rotation in “steps” where a step corresponds to a fixed amount of rotation. In typical embedded applications, we use motors with 200 steps per revolution, which means that one step corresponds to a 1.8-degree rotation. That’s why we chose our motor to have 200 steps per revolution.
To change the steps, we open the motor.py script and we can see that it executes a rotation of a fixed number of steps given by the “steps” variable.
We can also change the value of the “steps” variable and re-execute the script and see the motor is rotating by a different amount. The motor will rotate clockwise if the number of steps is positive, and counter-clockwise if the number of steps is negative.
Here, also you can find some declaration at the beginning of the script. It shows which Rpi GPIOs are used to connect different pins of DRV8834 IC (Motor driver IC). So that you can have the idea of how Driver IC is connected to the Raspberry Pi GPIO. The Driver IC can work in both modes i.e. Indexer Mode and phase/enable mode.
The motor.py script is for both the modes; we can change the mode by just changing the “indexer_mode” variable value (True or False). By default, it is in Indexer mode because it’s easier to use. We can modify the code and make it work as per our application.