[PYTHON] Control brushless motors with GPIOs on Raspberry Pi Zero

Control a brushless motor with a Raspberry Pi Zero

Overview

I had a little thought, so I tried to control a commercially available brushless motor using RPi Zero.

Constitution

IMG_20191018_212638-01-small.jpg

Connect

  1. Connect the motor and ESC. There are 3 lines, but even if you connect them properly, the rotation will only be reversed, so it's okay.
  2. Connect ESC and RPi. There are three in the connector, but the middle wire is not used. Use another one of some color on the opposite side of the black line. Connect the black one to the appropriate GND and the colored one to the appropriate GPIO. GPIO will be specified later in the program, so make a note of the number. Pin assignment Reference: https://www.raspberrypi.org/documentation/usage/gpio/
  3. Connect the battery at the stage of checking the operation. I don't know what will happen, so a safe battery is recommended. In the example, we used the eel-shaped LiFe that was lying around. Please note that eels are not usually rolled.

programming

For the time being, specify the pulse width and repeat turning it little by little.

Sample source code

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()

Commentary

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.

Summary

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

Control brushless motors with GPIOs on Raspberry Pi Zero
[Raspberry Pi] Stepping motor control with Raspberry Pi
Control the motor with a motor driver using python on Raspberry Pi 3!
Programming normally with Node-RED programming on Raspberry Pi 3
Working with sensors on Mathematica on Raspberry Pi
Working with GPS on Raspberry Pi 3 Python
Use python on Raspberry Pi 3 to light the LED with switch control!
Discord bot with python raspberry pi zero with [Notes]
Enjoy electronic work with GPIO on Raspberry Pi
Power on / off your PC with raspberry pi
Beginning cross-compilation for Raspberry Pi Zero on Ubuntu
Play with your Ubuntu desktop on your Raspberry Pi 4
Connect to MySQL with Python on Raspberry Pi
GPGPU with Raspberry Pi
DigitalSignage with Raspberry Pi
Cython on Raspberry Pi
Record temperature and humidity with systemd on Raspberry Pi
Run LEDmatrix interactively with Raspberry Pi 3B + on Slackbot
Try debugging Python on Raspberry Pi with Visual Studio.
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
Make an umbrella reminder with Raspberry Pi Zero W
Control power on / off of USB port of Raspberry Pi
Install pyenv on Raspberry Pi and version control Python
Troubleshoot with installing OpenCV on Raspberry Pi and capturing
Control music playback on a smartphone connected to Raspberry Pi 3 and bluetooth with AVRCP
Mutter plants with Raspberry Pi
Introduced pyenv on Raspberry Pi
Use NeoPixel on Raspberry Pi
Install OpenCV4 on Raspberry Pi 3
Install TensorFlow 1.15.0 on Raspberry Pi
Play with the Raspberry Pi Zero WH camera module Part 1
Production of temperature control system with Raspberry Pi and ESP32 (1)
Use vl53l0x with Raspberry Pi (python)
MQTT on Raspberry Pi and Mac
raspberry pi 4 centos7 install on docker
I learned how the infrared remote control works with Raspberry Pi
Let's make a cycle computer with Raspberry Pi Zero (W, WH)
Serial communication with Raspberry Pi + PySerial
Cross-compile for Raspberry Pi Zero on Debian-Create your own shared library
OS setup with Raspberry Pi Imager
Try using ArUco on Raspberry Pi
Try L Chika with raspberry pi
OpenCV installation procedure on Raspberry Pi
VPN server construction with Raspberry Pi
Try moving 3 servos with Raspberry Pi
Power on / off Raspberry pi on Arduino
Detect switch status on Raspberry Pi 3
Install OpenMedia Vault 5 on Raspberry Pi 4
Using a webcam with Raspberry Pi
L Chika on Raspberry Pi C #
Build wxPython on Ubuntu 20.04 on raspberry pi 4
Detect analog signals with A / D converter using python on Raspberry Pi 3!
Try tweeting arXiv's RSS feed on twitter from Raspberry Pi with python
Production of temperature control system with Raspberry Pi and ESP32 (2) Production of transmission device
Measure SIM signal strength with Raspberry Pi
Pet monitoring with Rekognition and Raspberry pi
"Honwaka Notification Lamp" on Raspberry Pi Part 2
Detect "brightness" using python on Raspberry Pi 3!
USB boot on Raspberry Pi 4 Model B
Hello World with Raspberry Pi + Minecraft Pi Edition
"Honwaka Notification Lamp" on Raspberry Pi Part 1