yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
L-Type Motor📖
1.About motor
  • About motor
2.ROS robot control board drive
  • 0. Notes (Must read!!)
  • 1. Control motor
  • 2. Timer captures encoder data
  • 3. PID control robot car
  • 4. Kinematic Analysis-Mecanum wheel structure
  • 5. Kinematic Analysis-Ackerman structure
  • 6. Kinematic Analysis-4WD structure
3.STM32 board car tutorials
0. Notes (Must read!!)
  • Notes
1. Get started quickly
  • 0. Installation Instructions
  • 1. Version configuration
  • 2. Smart car installation video
  • 3. Precautions for use
2. Introduction to STM32 development board
  • 0. Notes (must read)
  • 1. Learn about STM32
  • 2. Introduction to STM32 development board
  • 3. Development board pin assignment
  • 4. Introduction to HAL library and LL library
3. Setting up and using the development environment
  • 1. Common development tools
  • 2. STM32CubeMX Install - Use
  • 3. STM32CubeIDE Install - Use
  • 4. Common Driver Installation
  • 5. Program download and simulation
  • 6. Engineering experience and migration
4. Car expansion tutorial
  • 1. Servo control
  • 2. Basic use of ultrasonic steering gear gimbal
  • 3. Motor control
  • 4. OLED display light sensitivity value
  • 5. Infrared sensor
  • 6. Four-way tracking module
  • 7. Infrared remote control
  • 8. Ultrasonic ranging
  • 9. PS2 controller test
  • 10. Car line patrol
  • 11. Ultrasonic follow
  • 12. Ultrasonic obstacle avoidance
  • 13. Ultrasonic obstacle avoidance (servo gimbal version)
  • 14. Infrared sensor obstacle avoidance
  • 15. Infrared remote control
  • 16. PS2 handle remote control
4. 2-channel motor drive module
For MSPM0G3507
  • 1.AT8236 drive tutorials
  • 2.TB6612 drive tutorials
For MSPM0G3519
  • 1.AT8236 drive tutorialsnew
  • 2.TB6612 drive tutorialsnew
5. 4-channel motor drive module
Introduction and Debug
  • 1.Introduction to 4-channel motor drive board
  • 2. Control command
  • 3. 520 motor introduction and usage
  • 4. PC host
IIC communication
  • For MSPM0G3507
  • For MSPM0G3519new
  • For STM32
  • For ESP32
  • For Arduino
  • For PICO2
  • For Jetson NANO
  • For RPi5
  • For RDK X5
USART communication
  • For MSPM0G3507
  • For MSPM0G3519new
  • For STM32
  • For ESP32
  • For Arduino
  • For PICO2
  • For Jetson NANO
  • For RPi5
  • For RDK X5
Download
  • 3D-Model-File
  • Code
Download ZIP

Welcome to L-Type Motor repository

9. PS2 controller test

PS2 controller test

PS2 controller test1. Software-Hardware2. Brief principle1. Hardware schematic diagram2. Physical connection diagram3. Control principle3. Project configuration1. Description2. Pin configuration4. Main functions1. User function5. Experimental phenomena

This tutorial demonstrates: How to connect an external PS2 controller receiver to the expansion board and print the key values of the controller through the serial port.

1. Software-Hardware

  • STM32F103CubeIDE

  • STM32 Robot Development Board

  • PS2 controller and receiver

  • Type-C data cable or ST-Link

    Download programs or simulate the development board

  • Serial Assistant

    Receive serial port data and print

2. Brief principle

1. Hardware schematic diagram

image-20230925153122335

2. Physical connection diagram

image-20230926100744845

3. Control principle

(Schematic name)Control pinSpecific meaning
PS2-CSPA4Chip select signal
PS2-SCKPA5Serial clock signal
PS2-MISOPA6Host input and slave output signal terminal
PS2-MOSIPA7Host output slave input signal terminal

SPI communication protocol:

The full English name of SPI is Serial Peripheral Interface, which as the name suggests is a serial peripheral interface. SPI is a synchronous serial communication interface specification mainly used for short-distance communication in embedded systems. The interface was developed by Motorola in the mid-1980s and later became an industry standard.

SPI devices communicate in full-duplex mode, which is a master-slave mode between a host and one or more slaves. The host is responsible for the initialization frame. This data transmission frame can be used for both read and write operations. The chip select line can select one from multiple slaves to respond to the host's request.

image-20230926100744845

data transmission:

In SPI communication, the SPI master device transmits data to the SPI slave device through the SCLK line at the frequency supported by the slave device. This also means that the slave device cannot actively send data to the host device, and can only send data to the slave device in polling mode. Or the slave device actively notifies the host of data arrival through an IO port.

In each clock cycle of SPI, a full-duplex data transmission is performed. When the host sends 1 bit through the MOSI line, the slave will also send 1 bit data out through the MISO line after reading it. This means that this communication sequence is maintained even if only simplex communication is performed.

The timing diagram is as follows:

image-20230926100744845

SPI communication process:

  1. The SPI master first pulls the SS or CS line low to inform the SPI slave to start communication.
  2. The host notifies the slave of the upcoming read and write operations by sending the SCLK clock signal. The SCLK clock signal here is determined by the SPI mode whether it is high level or low level, which will be introduced later.
  3. The host (Master) writes the data to be sent to the sending data buffer area (Memory). The buffer area passes through the shift register (0~7). The serial shift register shifts the bytes one by one through the MOSI signal line. Out and transmitted to the slave, at the same time, the data received by the MISO interface is moved to the receiving buffer area bit by bit through the shift register.
  4. The slave (Slave) also returns the contents of its own serial shift register (0~7) to the host through the MISO signal line. At the same time, the data sent by the host is received through the MOSI signal line, so that the contents of the two shift registers are exchanged.

PS2 Controller: The PS2 controller consists of two parts: controller and receiver. The controller is mainly responsible for sending button information; the receiver is connected to the microcontroller (also called the host) and is used to receive information from the controller and pass it to The microcontroller can also send commands to the handle through the receiver and configure the sending mode of the handle.

Mode switching: Press the "MODE" button and the handle can be configured to "Red light mode" or "Green light mode".

Introduction to handle buttons:

image-20230926100744843

Function keysCorresponding key values
L111
L29
R112
R210
Direction keys (up, down, left, right)5/7/8/6
Function keys (X/A/Y/B)16/15/13/14
Select key1
Start key4

image-20230926100744845

image-20230926100744845

PinFunction
DI/DATSignal flow direction, from controller to host
DO/CMDSignal flow direction, from host to handle
GNDPower ground
VDDReceiver working power supply: 3-5V
CS/SELController trigger signal
CLKClock signal

3. Project configuration

1. Description

Omitted project configuration part: New project, chip selection, project configuration, SYS of pin configuration, RCC configuration, clock configuration and project configuration content

Please refer to [2. Development environment construction and use: STM32CubeIDE installation and use] to understand how to configure the omitted parts of the project.

2. Pin configuration

image-20230926100744845

image-20230926100744845

image-20230926100744845

image-20230926100744845

4. Main functions

According to our tutorial STM32CubeIDE can generate the corresponding gpio.c, gpio.h, tim.c and tim.h files. For later transplantation and peripheral module driver, we will place the automatically generated code in the BSP under the project file. folder.

1. User function

Function: PS2_Data_Show

Function prototypevoid PS2_Data_Show(void)
Function descriptionSerial port prints PS controller data
Input parametersNone
Output parametersNone

Function: PS2_Data_Show

Function prototypeuint8_t PS2_DataKey()
Function descriptionProcess the read PS2 data, only process the button part
Input parametersNone
Output parametersWhen only one button is pressed, the value is 0, and when it is not pressed, it is 1

Function: PS2_ReadData

Function prototypevoid PS2_ReadData(void)
Function descriptionRead controller data
Input parametersNone
Output parametersNone

Function: PS2_ClearData

Function prototypevoid PS2_ClearData()
Function descriptionClear data buffer
Input parametersNone
Output parametersNone

Function: PS2_Cmd

Function prototypevoid PS2_Cmd(uint8_t CMD)
Function descriptionSend commands to the controller
Input parametersCMD command
Output parametersNone

5. Experimental phenomena

After downloading the program, set the parameters as shown in the figure below, and then open the serial port assistant. At the same time, connect the handle receiver and expansion board wiring. You can receive the controller key value information through the serial port assistant.

xxxxxxxxxx
For program download, please refer to [2. Development environment construction and use: program download and simulation

The effect is as follows:

image-20230926100744845

 

Ultrasonic ranging
Car line patrol

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文