2023-11-14 07:10 AM - edited 2023-11-29 03:07 AM
This article contains a description of how to create a custom gaming controller using the new box kit SensorTile.box PRO. The controller will be providing data over Bluetooth® Low Energy (BLE), specifically orientation, and button status data. To get the orientation data, a sensor fusion low power functionality is used. To get the button status data, the Qvar functionality is used. Both functionalities are included in the LSM6DSV16X sensor. If the game cannot process data directly from BLE, it is possible to use a bridge to convert the communication from BLE to VCOM. The output of this tutorial game using SensorTile.box PRO as a controller, is shown in the following video.
FP-SNS-STBOX1 - FP-SNS-STBOX1 is an STM32Cube function pack for the pro mode of the SensorTile.box wireless multisensor development kit. STWIN.box - SensorTile, and for the Sensortile.box pro multisensors and wireless connectivity development kit for any intelligent IoT node.
The tutorial was created using package version 1.5.0
STM32CubeWB - STM32Cube MCU package for STM32WB series (HAL, low-layer APIs and CMSIS, USB, file system, RTOS, BLE, Thread, and Zigbee stacks with examples running on STMicroelectronics boards).
The tutorial was created using package version 1.16.0
Programming IDE supported by packages (for example STM32CubeIDE, IAR EWARM, etc.)
Your custom-made game. In this youtube video an Unreal Engine based game was used, reading the VCOM data and controlling the game thanks to the SerialCOM plugin.
The firmware is based on a BLEDualProgram example available within the FP-SNS-STBOX1 package. The example can be found within the package in the following path: STM32CubeFunctionPack_STBOX1_V1.5.0\Projects\STM32U585AI-SensorTile.boxPro\Applications\BLEDualProgram.
In this project we modified nine files:
And added two new files:
Click on the "spoiler" tag below to view how and why the files are modified.
Click here to see a list of modified files
Modifying main.h and main.c
The main file is modified to include TargetPlatform code files, GPIO, and I²C initialization (to communicate with the LSM6DSV16X sensor) and initialization of the sensor itself. The original BLEDualProgram is written to send random quaternion data over BLE to STBLEapp. This code is modified to collect quaternion and Qvar button state data from the sensor and send these data over BLE.
Modifying stm32u5xx_it.c
The file includes handling of all defined interrupt requests. This file was modified to handle interrupts from LSM6DSV16X and BLE.
Modifying stm32u5xx_hal_msp.c
Added code for I²C initialization to be able to communicate with LSM6DSV16X.
Modifying STBOX1_config.h
Disabled BLE secure communication not to require PIN during pairing of devices.
Modifying SensorTileBoxPro_conf.h
Enabled sensors and defined the firmware version.
Modifying BLE_Manager_Conf.h
Disabled BLE parson (for STBLESensor app support).
Modifying BLE_Implementation.h and BLE_Implementation.c
Disabled extended configuration, disabled the original example, which generates random environmental data. In the header file, we set the BLE name to “MAZEGAM.”
Create TargetPlatform.h and TargetPlatform.c
The code includes the main application logic. This means initializing the sensor, getting the quaternion data on sensor interrupt, and reading the Qvar value to determine if the button is “pressed” or not. The data is sent over BLE in the following format: q_y, q_x, q_z, q_w, button_state.
Creating firmware for P-NUCLEO-WB55 (sending received data over BLE to VCOM)
For this firmware, we start from the example BLE_p2pClient. Then modify it so that it can receive data from SensorTile.box PRO over BLE and send received data to VCOM. The example BLE_p2pClient can be found within the package STM32CubeWB in the following path: STM32Cube_FW_WB_V1.16.0\Projects\P-NUCLEO-WB55.Nucleo\Applications\BLE\BLE_p2pClient. In this example, we modified two files - app_ble.c and p2p_client_app.c.
Modifying file app_ble.c
Let us start with the file app_ble.c. In this file, we can find code related to searching and connecting to the BLE device server. In our case, the BLE device server is SensorTile.box PRO. In the SensorTile.box PRO firmware, we set the BLE name to be “MAZEGAM.” Since we want to be able to use any box with this firmware, we modified the file to connect to any device with the name “MAZEGAM.” The firmware checks the advertisement data of all available BLE devices and connects to any device with the selected name.
Modifying file p2p_client_app.c
The peer-to-peer client application was modified to print received quaternion and Qvar button data into the serial COM port. Additionally, it was modified to recover the connection process when the connection between the SensorTile.box PRO and P-NUCLEO-WB55 ends unexpectedly or the SensorTile.box PRO is restarted during the usage.
In this article, we described how to use SensorTile.box PRO as a gaming controller. Optionally using P-NUCLEO-WB55 to receive data over BLE and send them further via a COM port. The possibilities with SensorTile.box PRO are flexible and the user can adapt the firmware further to adapt the gaming controller for a different game or use-case.
You may also be interested in exploring the following landing page dedicated to SensorTile.box PRO: Take IoT to the next level with SensorTile.box PRO
wow informational