This library offers the possibility to use a Brushless 3-wire motor as a servomotor. It’s very convenient for making fast precision movements in many applications such as Gimbals. No need to buy or hack an existing ESC (Electronic Speed Control).

Please note that this library operates with sensor-less brushless motors. So the motor may skip steps!

Warning: When you prototype electronic circuits with high current and Brushless motors, things can go wrong and blue magic smoke can appear! Be careful to choose the correct components.

Installation

  • Open Arduino IDE,
  • Go to Sketch > Include Library > Manage Libraries...,
  • Then search for Brushless Servo and hit install.

Settings

In BrushlessServo.h you can set the PRECISION constant to the number of divisions you want in one motor revolution.

Reference

attach()

Attach the BrushlessServo variable to 3 PWM pins.

These pins represent the 3 connectors of the brushless motor, but at low voltage (control signal for MOSFETs…).

Example :

1
2
3
4
5
6
7
8
9
#include <BrushlessServo.h> 

BrushlessServo myservo;

void setup() { 
  myservo.attach(9, 10, 11);
} 

void loop() {} 

write()

Move to a position in degree. This method accepts floats.

1
2
3
myservo.write(0);
delay(500);
myservo.write(54.2);

setOutputPower()

Set a power multiplier between 0 (min) and PWMRANGE (max).

This will be applied to the PWM generator.

Better used just after attach().

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#include <BrushlessServo.h> 

BrushlessServo myservo;

void setup() { 
  myservo.attach(9, 10, 11);
  myservo.setOutputPower(512);  // Mid power
} 

void loop() {} 

setCycles()

Set how many sinusoid periods are needed for a full revolution. This method takes an integer.

Default to 8 cycles if not set.

Demo

Here is a demo with an L293DNE and an ESP8266 running a simple sketch.

Each iteration, the motor is incremented of one degree.