PiBle Quick Start

A Unity 3D object ‘glasses’ in the Demo scene tilts using the generated data of the Raspberry Pi. The Raspberry Pi generates 3D Object position data ‘x, y, z’ using the SIN function. The Raspberry Pi sends that data from the Raspberry Pi to Unity through Windows PC using the BLE (Bluetooth low energy) interface.

When clicking a Unity 3D object ‘Button’ in the Demo scene, Unity sends the numerical data obtained from the Unity 3D object ‘Inputfield’ to the Raspberry Pi. Unity works at Windows PC and sends the numerical data to the Raspberry Pi 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 PiBle. This Quick Start also includes some steps for downloading and setting up a package in Unity Project, and writing the Raspberry Pi code (Python script).

Step-1 Download and set up a package in Unity Project
Step-2 Copy Raspberry Pi code to the Raspberry Pi using SFTP
Step-3 Run Demo scene

Step-1 Download and set up a package in Unity Project

  1. Download PiBle from the Asset Store, and click on the Import button.
  2. The package is imported under the Assets folder in your Unity project.
  3. Download the external plugin ’PiBleConnect-v2’ below and set it into the ‘Assets/PiBleInterface’ folder.
  4. Click the Project tab, choose ‘Assets’ > ‘PiBleInterface’ > ‘Scenes’ folder of the left side menu, double click on the Demo scene ‘PiBleSampleScene’ in the Project window.

Step-2 Copy Raspberry Pi code to the Raspberry Pi using SFTP

  1. Connect Raspberry Pi 4 (include Raspberry Pi 3 or Raspberry Pi Zero W) or higher by USB cable to Windows PC.
  2. [Raspberry Pi Zero W]

    [Raspberry Pi 4]

    [Raspberry Pi 3]

  3. Transfer folder ‘pible-v2’ to Raspberry Pi using SFTP (SSH File Transfer Protocol). We use the free FTP solution ‘FileZilla Client’ in our case as follows.

Step-3 Run Demo scene

  1. Connect Windows PC to Raspberry Pi using SSH (Secure Shell) protocol. In Raspberry Pi, run the Raspberry Pi code ‘pible-v2.py’ using the following command from Windows PC.
  2. $ ls
    $ cd pible-v2
    $ ls
    $ sudo python3 pible-v2.py
    

    We use the terminal emulator ‘Tera Term’ in our case as follows.

  3. In Windows PC, go to ‘Start’, choose ‘Settings’ > ‘Devices’ > ‘Bluetooth and other devices settings’. Click ‘Add Bluetooth or other device’ to start searching for the device.
  4. Like below, select the Bluetooth device ‘PiBle’ you want to add from the list.
  5. Click the ‘Play’ button on Unity. The Unity 3D object ‘glasses’ tilts in sync with the received data from the Raspberry Pi. The ‘Accelx, Accely, Accelz’ in the ‘Raspberry Pi Sample Code’ of the ‘Inspector’ tab displays the received data ‘x, y, z’ from the Raspberry Pi as follows.
  6. The ’console’ tab displays the game status as follows.
  7. The terminal emulator ‘Tera Term’in Windows PC displays the data ‘x, y, z’ from Raspberry Pi as follows.
  8. [ Not connect to Unity ]

    [ Connect to Unity and send acceleration data ]

  9. Set No0 / No1 into Inputfield ’No0’ / Inputfield ‘No1’ in the game screen, then click the Button ‘On’ to send to the Raspberry Pi. Show Inputfield ’No0’ / Inputfield ‘No1’ as follows.
  10. The ’console’ tab displays the game status at clicking Button ‘On’ as follows.
  11. The terminal emulator ‘Tera Term’in Windows PC displays the No0/No1 data from Windows PC as follows.