2.4G handle control

2.4G handle control1. Opening Notes2. Experimental PreparationThe relationship between the 4 motor interfaces and the car is as follows:Hardware wiring:Overall wiringWiring pins3. Key code analysis4. Experimental phenomenon

1. Opening Notes

Please read the "Introduction to Motors and Usage" in the four-way motor driver board information first to understand the motor parameters, wiring methods, and power supply voltage you are currently using. To avoid burning the motherboard or motor.

Motor: The case and code take the 310 motor in our store as an example.

2. Experimental Preparation

National Race Chassis V2 Four-wheel Drive Version, 4*310 Motors, 7.4V Lithium Battery, PS2 Wireless Controller, STM32F103C8T6 Core Board.

The relationship between the 4 motor interfaces and the car is as follows:

M1 -> upper left motor (left front wheel of the car)

M2 -> lower left motor (left rear wheel of the car)

M3 -> upper right motor (right front wheel of the car)

M4 -> lower right motor (right rear wheel of the car)

Hardware wiring:

Overall wiring

PixPin_2025-03-27_11-46-27

Wiring pins

Four-way motor driver boardSTM32C8T6
5V5V
GNDGND
SCLPB10
SDAPB11

Take M1 motor as an example below, and other motors are similar.

MotorFour-way motor driver board (Motor)
M2M1-
VCC3V3
AH1A
BH1B
GNDGND
M1M1+
PS2 Wireless controllerSTM32C8T6
VCC3V3
GNDGND
SCKPB15
CSPB14
MISOPB12
MOSIPB13
ACKNot connected

3. Key code analysis

The control_pwm() function is used to control the four motors and send PWM signals to the motor driver board through i2c communication to adjust the speed and direction of the motor.

PS2_RedLight(): Checks whether the controller has entered simulation mode (traffic light mode).

Get_PS2data(): Reads the current status data of the PS2 joystick and buttons.

PS2_CarControl(): Determines the movement intention based on the joystick direction or button value, and calls control_pwm() to implement various actions of the car (forward, backward, rotation, tilt, etc.).

First, initialize the serial port, PS2 handle interface, i2c motor drive and delay function, then read the handle data continuously in the main loop. When the handle is detected in analog mode (traffic light mode), analyze the joystick data and control the motor movement through i2c communication. Finally, maintain a stable control cycle through 10ms delay to achieve real-time response to handle operation and precise motor control.

4. Experimental phenomenon

After connecting the car and burning the program to STM32, put the car on the ground and connect the car power supply. At this time, the receiver has a red light and a green light. It is waiting for pairing. Then turn on the handle switch. At this time, when the red and green lights on the receiver are always on, it means the match is successful. If the match is not successful, please check the wiring again. Press and hold the handle mode key to switch the mode. The mode in which the red and green lights on the top of the handle are always on is the analog value mode. At this time, you can press the direction key on the left side of the handle or push the left joystick; the up and down direction keys control the car to move forward and backward, and the left and right direction keys control the car to rotate left and right; the control effect of the left joystick is similar to that of the direction keys.