cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a custom gaming controller using SensorTile.box PRO

Denise SANFILIPPO
ST Employee

Summary

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.

 

DeniseSANFILIPPO_0-1696928140178.png

 

 Hardware prerequisites

DeniseSANFILIPPO_1-1696928283916.png
  • SensorTile.box PRO used as controller. The STEVAL-MKBOXPRO (SensorTile.box PRO) is a ready-to-use programmable wireless box kit for developing any IoT application based on remote data gathering and evaluation. Use the full kit potential by leveraging both motion and environmental data sensing, along with a digital microphone. Enhance the connectivity and smartness of whatever environment that you find yourself into.
  • P-NUCLEO-WB55 used as BLE to VCOM bridge. The P-NUCLEO-WB55 pack is a multiprotocol wireless and ultra-low-power device. Embedding a powerful and ultra-low-power radio compliant with the Bluetooth® Low Energy (BLE) SIG specification v5.0 and with IEEE 802.15.4-2011.
  • [optional] 3D printed case for SensorTile.box PRO for better hand grip based on the design of your choice.
  • 1x USB to USB Type-C® to flash firmware from PC to SensorTile.box PRO.
  • 1x USB to micro USB to flash firmware from PC to P-NUCLEO-WB55.

Software prerequisites

  • 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.

Creating firmware for the SensorTile.box PRO (sending orientation and button status data over BLE)

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:

  • main.h and main.c
  • BLE_Implementation.h and BLE_Implementation.c
  • BLE_Manager_Conf.h
  • SensorTileBoxPro_conf.h
  • STBOX1_config.h
  • stm32u5xx_hal_msp.c
  • stm32u5xx_it.c

And added two new files:

  • TargetPlatform.h and TargetPlatform.c

Click on the "spoiler" tag below to view how and why the files are modified.

 

Spoiler

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.

 

 

Conclusion

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 

 

Comments
AhsanAnsari
Associate II

wow informational

Version history
Last update:
‎2023-11-29 03:07 AM
Updated by: