PiBleMobile Quick Start
A Unity 3D object ‘tumbler’ in the Demo scene tilts using acceleration data of the Raspberry Pi. The Raspberry Pi generates 3D Object acceleration ‘x, y, z’ data using the sin function. The Raspberry Pi sends the data from the Raspberry Pi to Unity through an Android mobile phone using the BLE (Bluetooth low energy) interface.
The following shows the capture screen when the Demo scene runs.
This Quick Start explains how to display the Demo scene on Unity using PiBleMobile. This Quick Start also includes some steps for setting up the Raspberry Pi code and downloading Unity objects to the Android mobile phone.
Step-1 Download and set up a package in Unity Project
(1)Download PiBleMobile from the Asset Store, and click on the ‘Import’ button.
(2)Import the package under the Assets folder in Unity project.
(3)Click the ‘Project’ tab, choose ‘Assets’>‘PiBleMobileInterface’>‘Scenes’ folder of the left side menu, double click on the demo scene ‘PiBleMobileScene’ in the ‘Project’ tab.
(4)Connect the Android mobile phone by USB cable to Windows PC, build the purchased assets according to ‘Building games for Android,‘ and run it in the Android mobile phone.
(5)Display PiBleMobile from application information in the Android mobile phone as follows. Change the ‘Location permission’ to ‘ON’ because of the need to enable Bluetooth Low Energy Scanning.
Step-3 Run Demo scene
(1) The installed PiBleMobile on the Android mobile phone displays the game object as follows.
Result of Start Process | ‘Success’: Success start process. ‘Enable BLE 1’or ‘Enable BLE 2’: disable location permission. Refer to Step-1 (5). |
---|---|
Received Raspberry Pi data | Display the Raspberry Pi data when Unity receives it from Raspberry Pi ‘Not Connect’: Android mobile phone is not connect Raspberry Pi, |
Exception Message | Display the content of the exception when Unity sample script issues the exception. |
(2)In the Raspberry Pi, run the python script “pible.py” using the following command. The generated data “x, y, z” is Displayed as follows.
$ sudo python3 pible.py on -> stateChange: poweredOn on -> advertisingStart: success EchoCharacteristic - onSubscribe--20 Sending notification with value-cmd : -0.643,-0.500,0.140 b'-0.643,-0.500,0.140' -0.643,-0.423,0.140 b'-0.643,-0.423,0.140' -0.643,-0.342,0.140 b'-0.643,-0.342,0.140' -0.643,-0.259,0.140 b'-0.643,-0.259,0.140' -0.643,-0.174,0.140 b'-0.643,-0.174,0.140' -0.643,-0.087,0.140 b'-0.643,-0.087,0.140' -0.643,0.000,0.140 b'-0.643,0.000,0.140' -0.643,0.087,0.140 b'-0.643,0.087,0.140' -0.643,0.174,0.140 b'-0.643,0.174,0.140' -0.643,0.259,0.140 b'-0.643,0.259,0.140'