10. STM32 platform-------PS2 control car
1. Introduction of PS2 controller and MCU communication:
The PS2 consists of two parts: the handle and the receiver. The handle is mainly responsible for sending key information. When the power is turned on and the handle switch is turned on, the handle and the receiver are automatically paired.
When the pairing is not successful, the green light of the receiver flashes, and the light on the handle also flashes.
After the pairing is successful, the green light on the receiver is light on. the light on the handle also light on. You can press the “MODE” button to select the handle transmission mode.
Red light mode: analog output value of the joystick;
Green light mode: The remote lever corresponds to the above four buttons, and only four extreme directions correspond.
The receiver is connected to the host (single chip microcomputer) to realize communication between the host and the handle.
Table 10-1: receiver pin output
Figure 10-1 receiver
DI/DAT: Signal flow direction, from the handle to the host, this signal is an 8-bit serial data that is transmitted synchronously in the falling edge of clock. The reading of the signal is done during the course of the clock from high to low.
DO/CMD: Signal flow direction, from the host to the handle. This signal is opposite to DI. The signal is an 8-bit serial data that is synchronously transmitted on the falling edge of the clock.
NC: empty port.
GND: power ground.
VDD: receiver working power supply, power supply range 3~5V;
CS/SEL: Used to provide the handle trigger signal. During communication, at a low level;
CLK: clock signal, sent by the host to keep data synchronized;
NC: empty port;
ACK: The response signal from the handle to the host.
Table 10-2 Data meaning comparison table
When a button is pressed, the corresponding bit is "0" and the other bits are "1", for example, when the key "SELECT" is pressed, Data=11111110B.
Red light mode: the left and right joysticks send analog values, between 0x00 and 0xFF, and the key values of the joystick are pressed L3, R3 are effect;
Green light mode: the analog values of the left and right joysticks are invalid. When pushed to the limit, the corresponding UP、RIGHT、DOWN、LEFT、△、○、╳、□ buttons L3, R3 are invalid.
Figure 10-2 Receiver pins
Figure 10-3 Receiver pins
The joystick analog value corresponds to the XY coordinate map:
Figure 10-4 STM32 main control board circuit diagram
Table 10-3 Receiver and STM32 main control board pins
2.Handle button definition
Figure 3-1 Front view and function of the handle
!Note: After the car is powered on, you need to press the start button next to the PS2 logo on the expansion board.
On the red light mode, the joystick can output the analog value, the car can only advance, back, turn left, turn right. And when you push the rocker to the lower left corner and the lower right corner, the car will back to the left or back to the right.
On the green light mode, the car can only advance, back, turn left, turn right.
When using the Rocker 1, you need to hold down L1 at the same time.
When using the Rocker 2, you need to hold down R1 at the same time.
4-3 About the code
Please see the folder named PS2_control in the code folder.
The code of the experiment: 10.PS2_control.rar
STM32 Visual Tracking Car Tutorial Overview
- 2.1 Keil uVision5 install tutorial
- 2.2 Keil uVision5 create a new project tutorial
- 2.3 How to download code
- STM32 Visual Tracking Car Tutorial 3.1 Light up LED
- STM32 Visual Tracking Car Tutorial 3.2 Advance
- STM32 Visual Tracking Car Tutorial 3.3 Servo control
- STM32 Visual Tracking Car Tutorial 3.4 OLED
- STM32 Visual Tracking Car Tutorial 3.5 Battery voltage detection
- STM32 Visual Tracking Car Tutorial 3.6 Color LED
- STM32 Visual Tracking Car Tutorial 3.7 Ultrasonic obstacle avoidance
- STM32 Visual Tracking Car Tutorial 3.8 Screen display font
- STM32 Visual Tracking Car Tutorial 3.9 Camera vision tracking
- STM32 Visual Tracking Car Tutorial 3.10 PS2 control car
- STM32 Visual Tracking Car Tutorial 3.11 Bluetooth control car
4. About battery
5. About installation
Buy the STM32 Visual tracking robot car