Game made with @Tartoo during our bachelor year 2 (2021/2022) for an IOT course at Ynov.
- ### I. Présentation
- ### II. Unity part
- A. How to open the project
- B. How to build the project
- C. How to Play the project
- D. Problems solving
- ### III. STM32 part
Project realized during an IOT course in second year at Ynov.
The project includes:
- The source code which is on the STM32 card which allows to recover the values of the joysticks.
- A mini Pong game made with unity3D compatible with joysticks.
- An explanation of how to mount on the STM32 card and how to configure the serial output to retrieve information from the joysticks
In our project a script allows unity to retrieve the hexadecimal values of our joysticks returned by the STM32.
- Clone the git repository to your computer with the following command :
git@github.com:LeoSery/Pong-Game-on-an-STM32.git
-
open Unity Hub and do "Add project from disk"
Select "
..\Pong-Game-on-an-STM32\PongGame
" -
Check that the project opens with the Unity editor in version "2020.3.28f1"
-
Once the project is open in Unity, do "File" > "Build Settings"
-
In the window that has just appeared, in the "Scenes In Build" section, make sure that "scenes/Game" is checked.
-
for the platform choose: "PC, Mac & Linux Standalone"
-
then choose your platform in "Target Platform"
-
and finally press "Build And Run"
The project uses different optional Unity packages. If you have an error concerning a package go to: "Window > Package Manager" and check that you have the following packages installed:
- 2D Pixel Perfect (4.0.1)
- 2D SpriteShape (5.2.0)
- 2D Sprite (1.0.0)
- Text Mesh Pro (3.0.6)
- Unity UI (1.0.0)
First of all, when you arrive on Stm32 CubeMx, you will need to chose the card wich you use. Then, you have to congifure it in a way where we can play with 2 joysticks.
To do this, you must add 2 analogs and configure them like this :
Do the same for the second ADC but be carefull to use differents pin each time !
For the usart you will have to do this :
When the configuration is done, you have to connect joysitcks to the board. Ground must be plugged in ground, 5V in 3V, VRx in PA1 for the 1st joystick and VRy in PB0 again for the first joystick.
When it's done it should look like this :
After you have done this, you will have to generate a code on systeme workbench with those parameters :
In SystemeWorkbench you will have to create your code inside the infinite loop :
This code get the position of the joystick in hexadecimals and stock them in 2 value for each joystick. Then, it display them on Ptty so we can know the values when the joystick is up or down : 00 & FF.
Then we retrieve the value in unity3D and with a script we convert the Hexadecimal value into a displacement vector on the Y axis to move the pong paddle.
In the C# script named ReadData.cs
we convert hexadecimal values to decimal.
and finally in the Paddle.cs
script we use these decimal values as a 2D motion vector on the Y axis.