PiBleMobile Design Tips

PiBleMobile is an adapter interface tool for transfer from Raspberry Pi to Unity via an Android mobile phone using BLE (Bluetooth low energy). By connecting to the sensors device (gyro, accelerometer, GPS, etc.) with Raspberry Pi, Unity can input various data from the sensors device. This design tip explains the transfer method to Unity by referencing Raspberry Pi and Unity sample code in the purchased asset.

1. How to set up data in Raspberry Pi

Python script ”pible.py” generates 3D Object tilt data “x, y, z” with the sin function, then store in variable “x” and “y”. When you connect your sensors device, you need to change this code according to the input means from sensors.

Copy to Clipboard

2. How to get data from Raspberry Pi in Unity

Unity script ”PiBleSampleCode.cs” receives BLE data from Raspberry Pi as string data “str” of return value of “obj.Call(“UpdateRead”)” function. “str.Split(‘,’).Select(byte.Parse).ToArray()” function changes the string data “str” into array byte data “data”. Array byte data “data” encodes string code using “System.Text.Encoding.UTF8.GetString” function and, using “text.Split” function and “float.Parse” function, the string code is converted to float position data.

Copy to Clipboard