I had a little thought, so I tried to control a commercially available brushless motor using RPi Zero.
For the time being, specify the pulse width and repeat turning it little by little.
import pigpio
import time
motor_pin = 27 #Noted GPIO number
pi = pigpio.pi()
for i in range(3):
pi.set_servo_pulsewidth(motor_pin, 1500)
time.sleep(1)
pi.set_servo_pulsewidth(motor_pin, 1600)
time.sleep(1)
pi.set_servo_pulsewidth(motor_pin, 1700)
time.sleep(1)
pi.set_servo_pulsewidth(motor_pin, 1800)
time.sleep(1)
pi.set_servo_pulsewidth(motor_pin, 1900)
time.sleep(1)
pi.set_servo_pulsewidth(motor_pin, 2000)
time.sleep(1)
pi.set_servo_pulsewidth(motor_pin, 0)
pi.stop()
pi.set_servo_pulsewidth(motor_pin, 1500)
time.sleep(1)
Specify the GPIO number with motor_pin and specify the pulse width numerically. The range of values that can be specified depends on the ESC specifications. If you don't know the ESC specifications, you have to fumble around. In this ESC, it was possible to specify from about 1500 to about 2000. In sleep, specify the duration until the next state.
pi.set_servo_pulsewidth(motor_pin, 0)
If you want to stop it, I feel that it wouldn't work unless you wrote something like this. Maybe I didn't need it. Well, it's magical.
It seems that some ESCs need magic before moving. It has no choice but to check the ESC specifications.
With that feeling, I was able to control the brushless motor very easily. However, it may not be a strict brushless motor control because it uses the existing ESC to control the pulse and time. Originally, I want to control the ESC function itself with RPi.
By the way, this brushless motor does not rotate the contents, but the outer gawa rotates, so if you do not fix it, it will go wild (laugh) I think it is safer to use a motor that rotates the central rotor.
If you use RPi to control the motor, you can control it visibly! !! It gives you a sense of accomplishment, so it is also recommended for studying programming. You can buy this brushless motor and ESC set for about 1000 yen, so I think you can enjoy it at a lower price than buying a poor electronic work kit.
Recommended Posts