Bluetooth remote control

The tutorial mainly demonstrates the remote control function of the balance car combined with the Bluetooth module.

Hardware connection

Bluetooth moduleDevelopment board
VCCVCC
TXDRXD5
RXDTXD5
GNDGND

Control principle

The mobile phone connects to the Bluetooth module (slave) on the balance car through the built-in Bluetooth (host). The Bluetooth module receives the data of the balance car APP and sends it to the development board for analysis.

Master-slave mode

The host is responsible for managing the communication process and controlling data transmission, while the slave performs corresponding operations according to the host's instructions.

Host mode

The controller in Bluetooth communication is responsible for initiating connection requests and controlling the entire communication process.

Slave mode

Passively wait for the host's connection request and accept the host's control.

Communication protocol

The Bluetooth module sends the data transmitted by the mobile phone APP to the development board through TXD. The development board then parses the received data and obtains the corresponding command data. Later, the movement state of the car can be controlled according to this command data.

Main code

The tutorial mainly explains the code for implementing some Bluetooth remote control functions. For detailed code, please refer to the corresponding project file.

deal_bluetooth

Receive data sent by the Bluetooth module.

Protocol

Parse the Bluetooth module data according to the protocol.

Program flow chart

Briefly introduce the process of function implementation:

image-20240911190938842

Experimental phenomenon

Software code

The bluetooth_control.hex file generated by the project compilation is located in the OBJ folder of the bluetooth_control project. Find the bluetooth_control.hex file corresponding to the project and use the FlyMcu software to download the program into the development board.

Experimental phenomenon

After the program is started, press the KEY1 button according to the OLED prompt to start the balance car Bluetooth remote control function: OLED will display the balance car inclination angle in real time!

Bluetooth remote control

Download Bluetooth remote control APP

Use the mobile browser to scan the QR code to download the APP (only supports Android)

image-20240905102958598

Bluetooth connection

When you open the BalanceBot APP for the first time, it will automatically search and connect to nearby Bluetooth devices. We need to bring the phone close to the car, and the BalanceBot APP will automatically connect; if the connection is successful, a "Connection successful" prompt will appear.

If no search is found, you can click the Bluetooth search and connection options in turn.

23debde35890e856bd1e6db1caae4228

Main control interface

Used for basic control and data display of the balance car.

d4975e8e8ee55ee9c4672afb64d8cdcc

Direction control

The main control interface can control the movement of the balance car through buttons, gravity and joystick.

Data display

The main control interface will automatically obtain gravity, ultrasonic distance, battery voltage, and left and right motor speed display.

PID debugging

Used for online query and adjustment of PID parameters to achieve the best effect.

2310a787d2a3a83ff38d6045e0e0e90a

Vertical ring

Adjust the vertical ring PD parameters, support dragging and keystrokes to update data.

Speed ring

Adjust the speed ring PI parameters, support dragging and keystrokes to update data.

Steering ring

Adjust the steering ring PD parameters, support dragging and keystrokes to update data.

PID parameter range

Click the P, I, D options on the interface to adjust the adjustment range of each PID parameter.

e3bbe6df080fae67b4a86bbf3e2ed59f

Waveform display

Check the corresponding option to display the dynamic changes of acceleration, gyroscope and battery voltage data.

6000af23bc854f605a67506a274161a5