Open Loop Control
In this tutorial, we will explore how to run a BLDC motor using open loop control.
Prerequisites
In this tutorial, the following hardware is used:
- Aotenjo One Board
MCU: STM32G431CBU6
Version: Aotenjo One V1.4 - ST-LINK V2 Clone
- BlackPill STM32 Board
- BE4108 75T Gimbal Motor
- Power Supply (12V)
You need a ST-LINK V2 Clone to upload the firmware to the board. You can purchase a cheap clone ST-LINK V2 under $5.
USB to Serial Adapter
Since the Aotenjo One board doesn't have an USB port, you need a USB to Serial adapter to communicate with the board via serial. In this tutorial, we will use a Blackpill STM32 board as a USB to Serial adapter to communicate with the Aotenjo One board, but you can use a cheap USB to Serial adapter or another STM32 board like the Blackpill as an USB to Serial adapter.
You can use the following development boards as a USB to Serial adapter:
- BlackPill STM32 board
- BluePill STM32 board
- ESP32-DevKitC
If you're not sure how to use the BlackPill STM32 board as a USB to Serial adapter, you can refer to the Serial Communication tutorial.
Make sure your BLDC motor's internal resistance is greater than 10 Ω; otherwise, the board may burn out.
Installation
VScode with PlatformIO
You can install PlatformIO from the VSCode extension marketplace.
STM32CubeProgrammer
You need this to flash the firmware to the board.
Clone the repository
git clone https://github.com/aotenjo-xyz/one.git
cd one
The example code for the LED blink is located in the examples/openloop
directory, so run the following command if you use linux or macOS to copy the example code to the src
directory:
rm src/*
cp examples/open_loop/main.cpp src/
cp examples/open_loop/platformio.ini platformio.ini
For Windows, you can copy the files manually.
Quickstart
-
Connect the Aotenjo One board to the ST-LINK V2 programmer.
ST-LINK V2 <-> Aotenjo One
3.3V <---> 3.3V
GND <---> GND
SWDIO <---> SWDIO
SWCLK <---> SWCLK
RST <---> NRSTinfoUnlike the blackpill board, you need to connect the NRST pin to the ST-LINK V2 programmer for STM32G4 series.
-
Connect the ST-LINK V2 programmer to your computer.
-
Open the project folder in VSCode.
-
Click on the PlatformIO tab on the left sidebar and click on the
Upload
button to upload the firmware to the board. -
Disconnect the ST-LINK V2 programmer, then connect the power supply and the BlackPill STM32 board to the Aotenjo One board. Finally, connect the BlackPill STM32 board to your computer.
Power Supply <-> Aotenjo One
12V <---> VCC
GND <---> GND
Aotenjo One <-> Blackpill STM32
TX <---> PA3 (RX)
RX <---> PA2 (TX)
GND <---> GND
Blackpill STM32 <-> Computer
USB <---> USB -
Click on the PlatformIO tab on the left sidebar and click on the
Monitor
button to open the serial monitor. -
Turn on the power supply and input the following command in the serial monitor and press enter:
T1
Now you should see the motor spinning at a constant velocity. The value
T1
represents the target velocity, which you can adjust to control the motor's speed. For example, enteringT6.28
sets the target velocity to 6.28 rad/s — meaning the motor completes one full rotation per second. You can also rotate the motor in the opposite direction by entering a negative value, such asT-6.28
.Here is the video demonstration:
Commander
The code uses SimpleFOC library to control the motor, so you can use the Commander interface to control the motor. Here are some useful commands:
T<value>
: Set the target velocity (in rad/s)L<value>
: Set the target voltage (in V)?
: Get the available commands
If you enter ?
in the serial monitor, you will see the list of available commands:
T:target velocity
L:target voltage
You can see the current target velocity by entering T
and the current target voltage by entering L
in the serial monitor.