MicroBle Quick Start
A Unity 3D object ‘glasses’ in the Demo scene tilts using acceleration data of the micro:bit. The micro:bit generates 3D Object acceleration ‘x, y, z’ data using an accelerometer on the micro:bit. The micro:bit sends the acceleration data from the micro:bit 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 position data of the LED screen obtained from a Unity 3D object ‘Inputfield’ to the micro:bit. The micro:bit turns ON/OFF LED screen using it. Unity works at Windows PC and sends the LED screen data to the micro:bit 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 MicroBle. This Quick Start also includes some steps for downloading and setting up a package in Unity Project, and writing the micro:bit code.
Step-1 Download and set up a package in Unity Project
Step-2 Write micro:bit code using Arduino IDE
Step-3 Run Demo scene
Step-1 Download and set up a package in Unity Project
- Download MicroBle-v2 from the Asset Store, and click on the Import button.
- The package is imported under the Assets folder in your Unity project.
- Download the external plugin ’MicroBleConnect-v2’ below and set it into the
‘Assets/MicroBleInterface’ folder. - Click the Project tab, choose ‘Assets’ > ‘MicroBleInterface’ > ‘Scene’ folder of the left side menu, double click on the Demo scene ‘MicroBleSampleScene’ in the Project window.
. external plugin ’MicroBleConnect-v2’
Step-2 Write micro:bit code using Arduino IDE
- Connect the micro:bit by Micro USB cable to Windows PC, then build a software development environment for MicroBle with the Arduino IDE according to Arduino IDE for MicroBle.
- Compile and write micro:bit code ‘microble-v2.ino’ of the folder ‘/Assets /MicroBleInterface/microble-v2’ into the micro:bit using the Arduino IDE.
[ micro:bit Version 1.x ( not work 2.x) ]
Step-3 Run Demo scene
- 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.
- Like below, select the Bluetooth device ‘micro:BLE’ you want to add from the list.
- Click the ‘Play’ button on Unity. The Unity 3D object ‘glasses’ tilts in sync with the micro: bit when inclining the micro:bit. The ‘Accelx, Accely, Accelz’ in the ‘MicroBle Sample Code’ of the ‘Inspector’ tab displays the received acceleration data ‘x, y, z’ from the micro:bit as follows.
- The ’console’ tab displays the game status as follows.
- The ‘Serial Monitor’ of Arduino IDE displays the acceleration data “x, y, z” as follows.
- Set Row / Col of the LED screen into Inputfield ’Row’ / Inputfield ‘Col’ in the game screen, then click the Button ‘On’ to display the indicated LED of the micro:bit. Show correspondence between the Row / Col in the LED screen and Inputfield ’Row’ / Inputfield ‘Col’ as follows.
- The ’console’ tab displays the game status at clicking Button ‘On’ as follows.
- The ‘Serial Monitor’ in Arduino IDE displays the LED Row/Col data of the LED screen as follows.
[ Not connect to Unity ]
[ Connect to Unity and send acceleration data ]