-
Notifications
You must be signed in to change notification settings - Fork 11
AR Fishing
SenseHat Joystick Tutorial
Every game needs a controller, the most common of all is, of course, the joystick. We used the integrated joystick of the SenseHat, mounted on a Raspberry Pi 3 - Model B, and made a simple fishing game with two players out of it.
In this tutorial you will find all the steps we went through to connect SenseHat to Unity using Spacebrew. Once you are set up you can make your own fishing game or use the joystick of the SenseHat to controll your interactive projects.
HARDWARE NEEDED
- 2 Raspberry Pi 3 - Model B
- 2 Raspberry Pi SenseHat
SOFTWARE NEEDED
- Unity
- Mixed-Reality-Hardware-Kit Library
- Spacebrew Library for Python
- SenseHat Library for Python
- A text editor - we used Visual Studio Code
STEP 1 - Assemble the hardware Mount your SenseHat on your Raspberry Pi. We advice you to use stand offs for a more stable connection and to avoid shorting it, which may happen easily considering it is going to be our controller.
STEP 2 - Get Raspberry to talk with Spacebrew
A. First of all, to use our Pi as a controller we want it to be as free as
possible, and reduce to minimum the number of cables connecting to it.
Therefore, we want it to talk with our computer through wi-fi instead of
through the USB cable.
B. We want on our Pi the Mixed-Reality-Hardware-Kit Library on our Pi
C. In the MRHKLib Python folder we can either create a new python script
and edit it in our terminal or we can upload on our Pi a script we have
written in a text editor on our computer.
Either way we want the Spacebrew python script in the MRHKLib/Python folder
D. In this script "Python Script for Raspberry Pi" (link at the bottom) we want to:
- create a spacebrew object with the name of our game
- set the joystick directions as inputs
- have spacebrew to publish value whenever the SenseHat joystick is used
E. Save it
Now, if you open the Spacebrew Admin you can see your Pi and its publishers and
you can check if the data is coming through (the dot will turn black every time
a piece of data is published).
NB: You have to repeat this process for both Pis - remember to give it unique names
STEP 3 - Prepare your Unity file
A. Create a new Unity file by making a new copy of MRHW_Proto001 (you can find it in
the Unity folder of the MRHT-master2)
B. Create the objects you want to controll with the SenseHat joystic, in this case
we got two fishing poles from the Polly Assets.
Remember to place them in the correct level of hierarchy (in YourObjectsGoHere)
C. Set up spacebrew subscribers - select SpacebrewObject and edit elements of
Spacebrew Client script FROM UNITY
- set the spacebrew admin ip address
- add all the subscribers you need and have a specific name for each one - in
our case we will have 8
- edit your client name
D. Edit the Spacebrew Event script to describe what kind of changing you want to
make happen whenever the joystick data is received
- add as many event listeners as subscribers you have added in the previous step
NB: the names must match
- create if statements to isolate the event with each input - we are rotating
our fishing poles according to the input using transform.Rotate
- save the code
STEP 4 - Run your FishingGame.py code on both your Pis and Play your Unity file
STEP 5 - Open your spacebrew admin and connect the correct input with the right output
`
STEP 6 - Go back to Unity, set up your cam on top of your fiducial in a way that you have the perfect view and do some fishing with your best bud