0% found this document useful (0 votes)
45 views19 pages

Bluetooth SPP

The document describes a demonstration of using Bluetooth SPP to remotely control LEDs on a DE10-Nano board from an Android phone. It provides details on the system setup, including required hardware, and steps to run the Linux application on the DE10-Nano and Android application. The Linux application uses Bluetooth to control the LEDs while the Android application allows sending commands to control the LEDs remotely.

Uploaded by

mcamacho
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views19 pages

Bluetooth SPP

The document describes a demonstration of using Bluetooth SPP to remotely control LEDs on a DE10-Nano board from an Android phone. It provides details on the system setup, including required hardware, and steps to run the Linux application on the DE10-Nano and Android application. The Linux application uses Bluetooth to control the LEDs while the Android application allows sending commands to control the LEDs remotely.

Uploaded by

mcamacho
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Content

1. Overview ........................................................................................................ 1

2. Setup Demonstration .................................................................................... 3

3. Linux Application Project on DE10-Nano ....................................................... 6

4. Android Application Project........................................................................... 8

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.

 System Block Diagram


Figure 1 System Block Diagram shows the system block diagram of this
demonstration. In the demonstration, we implement two Bluetooth application
software. One is running on Android and one is running on DE10-Nano. These two
application communicate with each other based on a propriety command set.

In DE10-Nano, the Bluetooth application is running on the Linux. A classical USB


Bluetooth dongle is used to expand DE10-Nano Bluetooth capability. The SPP (Serial
Port Profile) protocol is used as communication protocol. The BlueZ Bluetooth
protocol software stack is used by the application to handle the Bluetooth protocol.
The Linux BSP build in the BlueZ and Bluetooth USB dongle driver, so user don’t
need install to install any library or driver in this demonstration.

Figure 1 System Block Diagram

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

“ATLED0\n” Turn one LED0 only

“ATLED1\n” Turn one LED1 only

“ATLED2\n” Turn one LED2 only

“ATLED3\n” Turn one LED3 only

“ATON\n” Turn on all four LEDs.

“ATOFF\n” Turn off all four LEDs.

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:

 DE10-Nano Board with shipped microSD card


 Classical Bluetooth USB dongle
 USB Mouse
 USB hub with two ports at least.
 Android Smart Phone with Bluetooth supporting
 A microSD card writer is required if reprogramming the microSD card is
necessary.

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:

1. Connect the HDMI port of DE10-Nano to a monitor as shown in Figure 2.


2. Connect a USB hub into the micro USB port of DE10-Nano.
3. Plug the USB mouse to the USB hub.
4. Plug a Bluetooth USB dongle into USB hub.
5. Insert the microSD card, came with this kit, into the DE10-Nano.
6. Make sure MSEL[4:0] is 01010.
7. Power on DE10-Nano.
8. When the LXDE desktop appears on the monitor, use a mouse to double click the
BT_LED_AP icon to launch the Bluetooth Application as shown in Figure 3.

DE10-Nano 3 www.terasic.com
Bluetooth SPP February 24, 2017
Figure 2 DE10-Nano Demo Setup

Figure 3 Launch BT_LED_AP on LXDE

Here are the procedure to setup the demonstration on Android Smart Phone:

1. Download the TerasicBluetooth App from the QR code shown Figure 4.


2. Install TerasicBluetooth.
3. Launch TerasicBluetooth.
4. For first time to connect DE10-Nano, click the ZOOM icon to discovery nearby
devices, select DE10_Nano device, and pair it with password “1234” as shown in
Figure 5.
5. Click the ZOOM icon and connect the paired DE10_Nano device.
6. In the TerasicBlueooth App GUI, click the LED0/LED1/LED2/LED3 and
ON/OFF icons to control the on the DE10-Nano.

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

Figure 4 BT_LED_APP QR-Code

Figure 5 Search Bluetooth Device

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.

Figure 6 Major objects in the system

 C++ Class
The major class used in this project as shown in the table below.

Class Function Description Implementation Files

BtSppCommand Parse the raw data coming from BtSppCommand.cpp/h


Bluetooth. Derive from the CBtSpp
class.

BtSpp Provide Bluetooth SPP service BtSpp.cpp/h


based on the RFCOMM Bluetooth
stack in Linux kernel

CQueueCommand Queue received Bluetooth QueueCommand.cpp/h

DE10-Nano 6 www.terasic.com
Bluetooth SPP February 24, 2017
command

CQueue Provide queue function Queue.cpp/h

CPIO_LED Control the LEDs from HPS side of PIO_LED.cpp/h


DE10-Nano

 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

Please follow the steps below to compile the project.

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.

Figure 7 Screenshot of build all

 Test BT_LED_AP Binary File


Copy the generated BT_LED_AP binary file into the /home/root directory of DE10-
Nano Linux. Then following the demonstration setup procedure to perform the test.

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.

 Android UI Layout and Components


Figure 8 shows the User Interface of this application software. Two kinds of build-in
components are used in this application software. They are ImageView and ListView.
The ImageView is used to implement button functions. When users click a button, the
associated command will be sent to DE10-Nano through Bluetooth. When DE10-
Nano receives the command, it will change the LED status. List View is used to log
the command translated between Phone and DE10-Nano.

ImageView Component
ListView Component
Spcial Component

Figure 8 Android User Interface layout

 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.

Figure 9 New and Edit Android Device

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.

Figure 11 Root Directory for Imported Project

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.

Figure 12 Project Main GUI

 Download Binary File the Android Device


Note, before the TerasicBluetooth.apk binary file can be downloaded to Android
mobile through Eclipse tool, the Debug mode of the users’ Android Device must be
enabled to allow the installation from an unknown source. The phone must also have
the developer option turned on. The corresponding driver for users’ Android Device
also needs to be installed on the host PC.

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
AsAndroid 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 AsAndroid Application”

 Run and Test Android 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.

1. Launch TerasicBluetooth application.


2. For first time to connect DE10-Nano, click ZOOM icon to discovery the
DE10-Nano and pair it with pin-code “1234” as shown in Figure 14.
3. Click the ZOOM icon to connect the paired DE10-Nano.
4. In the TerasicBlueooth App GUI, click the LED0/LED1/LED2/LED3 and
ON/OFF icons to control the on the DE10-Nano.

Figure 14 TerasicBluetooth Application UI

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

 Install Java JDK

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

Figure 15 JAVA SE Download Web

In the download web as shown in Figure 16, select proper installer for your Host PC.

Figure 16 JAVA SE Development Kit


DE10-Nano 13 www.terasic.com
Bluetooth SPP February 24, 2017
 Install Eclipse

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/

Figure 17 Eclipse Download Web

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.

Figure 18 Workspace directory for Eclipse

 Install ADT (Android Development Tools)

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.

Figure 19 Install New Software

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/

Figure 20 Install ADT

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

After the installations completed, restart the Eclipse.

 Install Android SDK


Go to the web link below to download the Android SDK as shown in Figure 22. Then
uncompressed the downloaded zip file.

https://developer.android.com/studio/index.html

Figure 22 Android SDK Download

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 “WindowsAndroid 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.

Figure 24 Android SDK Manager

DE10-Nano 17 www.terasic.com
Bluetooth SPP February 24, 2017

You might also like