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
SOLO UNO Data-line Wiring to Raspberry Pi
SOLO UNO wiring
SOLO MINI wiring
SOLO’s Setup
![IMG3_Closed_loop_Config_SOLO Simplest way to control a Fast Brushless Motor with Raspberry Pi using SOLO [+ Code] 3](https://www.solomotorcontrollers.com/wp-content/uploads/2021/01/IMG3_Closed_loop_Config_SOLO-scaled.jpg)
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.
![IMG1_SCT_550_4150KV Simplest way to control a Fast Brushless Motor with Raspberry Pi using SOLO [+ Code] 4](https://www.solomotorcontrollers.com/wp-content/uploads/2021/01/IMG1_SCT_550_4150KV.png)
The Code
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.
![IMG1_15000RPM_Raspberry Pi_BLDC_SpeedControl_FOC Simplest way to control a Fast Brushless Motor with Raspberry Pi using SOLO [+ Code] 5](https://www.solomotorcontrollers.com/wp-content/uploads/2021/06/IMG1_15000RPM_Raspberry-Pi_BLDC_SpeedControl_FOC-2.png)
Figure 1- 15,000 RPM step response of the BLDC using Raspberry Pi and SOLO
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:
![IMG2_30000RPM_Raspberry Pi_BLDC_SpeedControl_FOC Simplest way to control a Fast Brushless Motor with Raspberry Pi using SOLO [+ Code] 6](https://www.solomotorcontrollers.com/wp-content/uploads/2021/06/IMG2_30000RPM_Raspberry-Pi_BLDC_SpeedControl_FOC-1.png)
Figure 2- 30,000 RPM step response of the BLDC using Raspberry Pi and SOLO
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.
![IMG3_30000RPM__Raspberry Pi_BLDC_SpeedControl_FOC_Disturbance Simplest way to control a Fast Brushless Motor with Raspberry Pi using SOLO [+ Code] 7](https://www.solomotorcontrollers.com/wp-content/uploads/2021/06/IMG3_30000RPM__Raspberry-Pi_BLDC_SpeedControl_FOC_Disturbance-1.png)
Figure 3- Aggressive Load disturbance on the BLDC and how SOLO reacts to keep the Speed constant by Increasing the Torque
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.