The Simplest Way to Control a Fast Brushless Motor with Raspberry Pi Using SOLO [+ Code]
Controlling a brushless motor with Raspberry Pi can get very challenging especially when you want to do advanced controls like FOC on a fast brushless motor that can go all the way up to 30,000 mechanical RPM which is very fast, to look at this problem from another perspective, it’s fair to say, Raspberry Pi devices are not generally designed to control very fast real-time operations in matter of microseconds like controlling a Motor or even if they could, they don’t have that much electrical power, so eventually you need to pair your Raspberry Pi with an external controller which are called a Motor Controllers or as some conventional terms Motor Drivers, however the main difference between a Motor Controller and a Motor Driver is that a Motor controller is a smart unit that not only can inject power into your motor, but it can be commanded externally and it can automatically stabilize the motor on various references like Speed, Torque or Position ( like SOLO ), but a Motor driver is just simply inject power to your motor and will have no control over the reaction of the Motor or how to control its Torque, Speed or even Position of the shaft.
A Motor controller like SOLO by offering a unique Dual-core architecture with parallel processing, will enable your Raspberry Pi to become extremely powerful and with simple Python codes you will be able to control any types of Motors specially BLDC and PMSM motors with Raspberry Pi ( SOLO supports DC brushed and AC Induction motors too, and in other tutorials, we will show how to control them using Raspberry Pi)
To do that we developed an extensive library in Python to interface Raspberry Pi with SOLO through UART port that natively exist on any Raspberry Pi, and your Raspberry Pi will be able to send and receive all types of commands to SOLO to control Torque, Speed and Position of all the Motors that SOLO supports. Using that you can control your Motors both in Sensorless or Sensor-based manners ( using Hall sensors or Incremental Encoders).
In this tutorial we will showcase a simple example on an Extremely fast brushless Motor for sensorless speed control and we will demonstrate the Python code written for Raspberry Pi as well as some plots to clarify the behaviour better and how you really can interface your Raspberry Pi with SOLO to control such motors.
The Wiring
The only wiring you need to apply will be the connection of the Motor to SOLO and by just connecting UART_TX, UART_RX and GND lines between SOLO and Raspberry Pi as below, The wiring connection of the motor to SOLO is not important as we are operating in Sensorless Mode and it can only affect the direction of rotation of the Motor.
SOLO UNO Data-line Wiring to Raspberry Pi
SOLO UNO wiring

SOLO MINI wiring

SOLO’s Setup
In This example make sure you put SOLO into Closed-Loop control mode by pressing the Piano Switch PIN NO# 5 DOWN in SOLO UNO similar to image below, the rest of the PINs can remain UP.

The Motor
The Motor used in this example is “Turnigy TrackStar SCT 5T Brushless Motor” with 4150KV and you can order it from here. This motor also features Hall sensor outputs which we didn’t use in this example as we are working in Sensorless Mode.

The Code
# Title: How to Drive Fast Drone or RC car Brushless Motors using RASPBERRY-PIand SOLO in Sensoless Mode
# Author: SOLOMOTORCONTROLLERS
# Date: 2021
# Code version: 2.0.0
# Availability: https://github.com/Solo-FL/SoloPy/
# Please make sure you are applying the right wiring between SOLO and your RASPBERRY-PI
# The Code below has been tested on RASPBERRY-PI 4B
# The Motor used for Testings: 4150KV, 4x4 SCT 550
#Importing SoloPy
import SoloPy as solo
import time
import sys
# In this example, make sure you put SOLO into Closed-Loop by
# pressing the Piano Switch NO # 5 DOWN. in SOLO UNO
# Initialize the SOLO object
mySolo = solo.SoloMotorControllerUart()
# wait here till communication is established
while mySolo.serial_is_working() == False:
time.sleep(1)
print("Communication Established succuessfully!")
# Initial Configurations
mySolo.set_command_mode(solo.COMMAND_MODE.DIGITAL)
mySolo.set_motor_type(solo.MOTOR_TYPE.BLDC_PMSM_ULTRAFAST)
mySolo.set_output_pwm_frequency_khz(79)
mySolo.set_current_limit(32.0)
# run the motor identification
# run ID. always after selecting the Motor Type!
print("\n Identifying the Motor")
mySolo.motor_parameters_identification(solo.ACTION.START)
# wait at least for 2sec till ID. is done
time.sleep(3)
mySolo.set_control_mode(solo.CONTROL_MODE.SPEED_MODE)
mySolo.set_feedback_control_mode(solo.FEEDBACK_CONTROL_MODE.SENSOR_LESS)
mySolo.set_motor_poles_counts(2)
# Speed Controller Tunings
mySolo.set_speed_controller_kp(0.3)
mySolo.set_speed_controller_ki(0.005)
# Initial Configurations end
# loop actions
while True:
mySolo.set_motor_direction(solo.DIRECTION.CLOCKWISE)
mySolo.set_speed_reference(15000)
# wait till motor reaches to the reference
time.sleep(1)
print("Motor Speed: "+ str(mySolo.get_speed_feedback()))
time.sleep(5)
# stop the motor
mySolo.set_speed_reference(0)
time.sleep(2)
mySolo.set_motor_direction(solo.DIRECTION.COUNTERCLOCKWISE)
mySolo.set_speed_reference(30000)
# wait till motor reaches to the reference
time.sleep(1)
print("Motor Speed: "+ str(mySolo.get_speed_feedback()))
time.sleep(5)
# stop the motor
mySolo.set_speed_reference(0)
time.sleep(2)
Code Explanations
As mentioned before, to control an electrical motor of any kind using Raspberry Pi you need to have a Motor controller like SOLO that can manage the high input/output power and it’s fast enough to deal with motors in real-time within a couple of microseconds ( Raspberry Pi can not natively do that…)
In this code we asked SOLO through Raspberry Pi to spin the BLDC motor firstly with 15,000 RPM ( mechanical) as can be seen in Figure 1 below, it worth mentioning that the RED plot is the Actual speed of the motor and the Blue plot is the actual quadrature current or Iq which has direct relationship with the Torque of the motor ( Torque = Iq * Torque constant of the Motor), all the plots are sampled with 500Hz simultaneously.

Once the Motor stabilized at 15,000 RPM we stopped the motor abruptly, waited for a couple of seconds and then spun the motor this time with 30,000 RPM in reverse direction as can be seen in Figure 2 below:

As can be seen in both figures, SOLO could fastly follow the speed reference and stabilize there, but how about any unforeseen disturbances? For example what if there are sudden loads applied on the shaft of the motor? The actual behaviour of SOLO can be seen in Figure 3 below, as can be seen once there is an increase in the Load on the shaft, SOLO will try to increase the Torque ( Iq ) to overcome the effect and keep the speed constant at 30,000 RPM, please note that the load variation and how to tackle them is totally tunable by changing Speed controller Kp and Ki gains so you can tune how harsh or slow you’d like to respond to these disturbances by fine tuning them.

Conclusion
So as you saw, using our Python Library with Raspberry Pi, you will have a new door opened to you for controlling Brushless Motor’s Speed, Torque or Position using Raspberry Pi and SOLO, this will give you a huge edge to save time and dive into project developments right from Linux environment to Power Electronics and Motor controlling world, if you have any questions or doubts you can ask us in our Forum.
Products in this article


Related articles

SOLOPY v4.1.0: New Python Library Release
SoloPy v4.1.0 adds CANopen and CANable support on Windows, Linux and Raspberry Pi, PDO capabilities on all platforms and new examples organized by platform.

SOLO on Linux
Use SOLO motor controllers on Linux: check the USB port, add your user to the dialout group, fix permissions and remove ModemManager to connect via USB.
![The Easiest way to control the Torque of a BLDC with Raspberry Pi using SOLO with Hall sensors feedback [+ Code]](/media/blog/easiest-way-to-control-torque-bldc-raspberry-pi-hall-sensors-feedback-code/BLDC-Torque-Control-With-Raspberry-Pi-and-SOLO-using-Hall-Sensors-960w.webp)
The Easiest Way to Control BLDC Torque with Raspberry Pi and SOLO Using Hall Sensor Feedback [+ Code]
Control the torque of a BLDC motor with Raspberry Pi, SOLO and hall sensor feedback in Python: wiring, setup, hall calibration, full code and results.
