Bluetooth SPP
Bluetooth SPP
1. Overview ........................................................................................................ 1
5. Appendix ...................................................................................................... 13
DE10-Nano www.terasic.com
Bluetooth SPP February 24, 2017
1. Overview
This documents describe how to an Android Smart Phone can remotely control the
LEDs on the DE10-Nano board. The Bluetooth SPP (Serial Port Profile) is used as
communication protocol between Smart Phone and DE10-Nano. Classical USB
Bluetooth dongle is used to expand DE10-Nano Bluetooth capability.
DE10-Nano 1 www.terasic.com
Bluetooth SPP February 24, 2017
Command Set
There two application communicates based on the following command set defined by
Terasic. The commands are send by from Android Smart Phone to the DE10-Nano.
Command Description
DE10-Nano 2 www.terasic.com
Bluetooth SPP February 24, 2017
2. Setup Demonstration
This section describe how to setup the Bluetooth remote control demonstrations.
Hardware Requirements
The following hardware items are required to perform this demonstration:
The microSD card came with this kit already include the Linux application in the
/home/root directory. If the microSD content is changed, please program the microSD
card with the Linux Image File locate at http://www.terasic.com.tw/cgi-
bin/page/archive.pl?Language=English&No=1046&PartNo=5.
Execute Demonstration
Here are show the procedure to setup the demonstration. First, the Bluetooth
Application should be launched on DE10-Nano. Then, launch the Bluetooth
Application on the Android phone. In the first time, the Android need to discovery the
DE10-Nano and pair with it. When Android phone connects with the DE10-Nano,
users can controls the four LEDs on DE10-Nano.
Here are the procedure to launch the Bluetooth Application on the DE10-Nano:
DE10-Nano 3 www.terasic.com
Bluetooth SPP February 24, 2017
Figure 2 DE10-Nano Demo Setup
Here are the procedure to setup the demonstration on Android Smart Phone:
DE10-Nano 4 www.terasic.com
Bluetooth SPP February 24, 2017
Note, the QR code link to:
http://www.terasic.com/downloads/demo/de10-nano/TerasicBluetooth.apk
DE10-Nano 5 www.terasic.com
Bluetooth SPP February 24, 2017
3. Linux Application Project on DE10-Nano
The Linux BT_LED_AP is a C++ project. Figure 6 show the main objects in the
system. The CBtSppCommand object is used to receive the led control command
from the Android smart phone. This object is running in a separated thread. The
thread checks whether there is a coming command in polling method. The received
commands are pushed into the CQueueCommand object.
The main program and the other objects are running in main thread. It will check the
CQueueCommand whether there any queue command. If there are queue command, it
will retrieve the command from the CQueueCommand object, and control CPIO_LED
object to perform associated action.
C++ Class
The major class used in this project as shown in the table below.
DE10-Nano 6 www.terasic.com
Bluetooth SPP February 24, 2017
command
Build Project
Altera SoC EDS(Embedded Design Suite) is required to compile this C++ project.
The C++ project is located at:
CD/Demonstrations/SoC_Advanced/Bluetooth_Spp/Linux_BT_App
1. Make sure Altera SoC EDS v16.0 is installed on the host PC.
2. Copy the Linux_BT_App folder into the local hard disk of your host PC.
3. Launch Altera “SoC EDS Command Shell”.
4. In the shell, type “cd” command in the command shell to change the current
directory to folder Linux_BT_App.
5. Type “make” to build the project, as shown in Figure 4
6. The “BT_LED_AP” binary file will be generated in the project directory if
compile is successful.
DE10-Nano 7 www.terasic.com
Bluetooth SPP February 24, 2017
4. Android Application Project
The Android TerasicBluetooth project is Java-based project built by Eclipse. The
main function of the Android TerasicBluetooth project is to receive user’s input from
the GUI and send propriety commands to the spider robot through Bluetooth. The
Android device should equity with Classical Bluetooth capacity for running this
Bluetooth-based application. To open this project, Android Eclipse IDE is required.
For installation details, please refer to the Appendix section in this document.
ImageView Component
ListView Component
Spcial Component
Java Class
There are three Java Classes are used in this project. They are Bluetooth,
BluetoothService and eviceListActivity. Blueotooth is the main Activity that
handle .the GUI event. BluetoothService provides all the work for setting up,
DE10-Nano 8 www.terasic.com
Bluetooth SPP February 24, 2017
managing Bluetooth connector with other devices, and data transmission.
DeviceListActivity appears as a dialog. It lists any paired devices and devices
detected in the area after discovery.
If developers want to change GUI setting, they can modify the main.xml file under the
layout folder in this application project.
Build Project
Both Android SDK and Eclipse ADT Plugin must be installed to complete the
installation for this project prior to the development of Android. For installation
details, please refer to the Appendix section in this document.
Beside, developers need to create a new Android Device for their Android Smart
Phones. In the Eclipse GUI, select the menu item“windows->Android Virtual Devices
Manager->Device Definitions->Create Device”to create a new device as shown in
Figure 9.
The Bluetooth project has to be imported prior to the start of building the project. In
the Eclipsed, select the menu item “File->Import->Android->Existing Android
Code into Workspace” to select the imported project type as shown in Figure 10.
DE10-Nano 9 www.terasic.com
Bluetooth SPP February 24, 2017
Figure 10 Select Imported Project Type
In this Import Projects dialog, specify Bluetooth project location in the Root Directory
edit box as shown in Figure 11. Then, click the Finish button.
After project is imported successfully, open the main gui file main.xml as shown in
Figure 12. In this demonstration, Android Device is 5”1280x720 LCD, and API 19:
Android 4.2.2 is used. Developers can change these setting according to their Android
DE10-Nano 10 www.terasic.com
Bluetooth SPP February 24, 2017
Smart Phone. The binary file TerasicBluetooth.apk will be generated automatically
when it will be download to the Android Smart Phone.
Connect your host PC and Android Smart Phone with a USB cable. To update binary
file, right click on the project folder to pop up a menu, then select the menu item “Run
AsAndroid Application” to download the demo file to Android mobile, as shown in
Figure 13
DE10-Nano 11 www.terasic.com
Bluetooth SPP February 24, 2017
Figure 13 Select menu item “Run AsAndroid Application”
First, please launch the demo code on DE10-Nano. For details, please refer to Chapter
2. The following procedures below to the just download binary file.
DE10-Nano 12 www.terasic.com
Bluetooth SPP February 24, 2017
5. Appendix
The following items should be install on your host PC for developing Android
Applications software. This section will describe how to download and install these
items.
Java JDK
Eclipse
Android SDK
Android ADT
Go to web link below. In the web page, select Java Download icon as shown in.
Figure 15
http://www.oracle.com/technetwork/java/javase/downloads/index.html
In the download web as shown in Figure 16, select proper installer for your Host PC.
Go to the web below. Select proper installer for your Host PC in the download page
as shown in Figure 17. Execute the installer to install the Eclipse.
http://www.eclipse.org/downloads/eclipse-packages/
After Eclipse is installed successfully, launch the Eclipse. A the Workspace Launcher
dialog will appear as shown in Figure 18, input project folder and then click OK.
DE10-Nano 14 www.terasic.com
Bluetooth SPP February 24, 2017
In the Eclipse, select the menu item “Help->Install New Software …” as shown in
Figure 19.
The Install dialog will appear as shown in Figure 20. In the dialog, click the “Add…” button
to popup an Add Repository dialog. In the Add Repository dialog, type in the following
information for Name and Location edit box:
Name: Android
Location: https://dl-ssl.google.com/android/eclipse/
In the Install Dialog, check the Developer Tools check box, then click the Next button to
start downloading Android ADT as shown in Figure 21.
DE10-Nano 15 www.terasic.com
Bluetooth SPP February 24, 2017
Figure 21 ADT Development Kit
https://developer.android.com/studio/index.html
In the Eclipse, select the menu item “Windows > Preference” to open the Preferences dialog
as shown in Figure 23. In the dialog, select Android tab. In the SDK Location edit box, input
the folder location where the uncompressed Android SDK is located.Figure 23
DE10-Nano 16 www.terasic.com
Bluetooth SPP February 24, 2017
Figure 23 Android SDK installation location
Then, we need to selected desired API for your Android Smart Phones. In Eclipse, select the
menu “WindowsAndroid SDK Manager” to popup the Android SDK Manager dialog as
shown in Figure 24. In the dialog, select the desired API package. In this demonstration,
Android 4.2.2 (API 19) is used.
DE10-Nano 17 www.terasic.com
Bluetooth SPP February 24, 2017