Android Bluetooth Interface

safflowerpepperoniMobile - Wireless

Nov 24, 2013 (4 years and 1 month ago)

105 views

MOBILE PHONE
INTERFACING

Electronic Engineering Polytechnic Institute of Surabaya (EEPIS)

Using Android


SAMSUNG Galaxy Tab 10.1

Instructor : A.R.
Anom

Besari


Adnan

Rachmat

Anom

Besari

born in
Surabaya, 1985. Received his Bachelor of
Application Science degree from Electronic
Engineering Polytechnic Institute of
Surabaya (EEPIS) Indonesia in 2008. He
finished his master degree at Department of
Robotic and Automation in Faculty of
Manufacturing Engineering,
Universiti

Teknikal

Malaysia Melaka (
UTeM
) in 2011.
Now, he is currently a lecturer in Computer
Engineering department EEPIS. And his
research interests are in computer vision and
artificial intelligent.


anom@eepis
-
its.edu

Instructor : Fernando
Ardilla


Fernando
Ardilla

born in Surabaya, 1982.
Received his Bachelor of Application
Science degree from Electronic Engineering
Polytechnic Institute of Surabaya (EEPIS)
Indonesia in 2005. He finished his master
degree at Game Technology in Department
Electronics Engineering, Institute Technology
of
Sepuluh

Nopember

(ITS) in 2010. Now,
he is currently a lecturer in Computer
Engineering department EEPIS and his
research interests are in robotic and
artificial intelligent.

nando@eepis
-
its.edu

Objective


To know . . .


How to understand the simple hardware and software
interfacing.


How to control hardware from Android device with
orientation sensor using Bluetooth wireless
communication.


CHAPTER

1:

AN INTRODUCTION OF MOBILE
PHONE INTERFACING

What is Interfacing ?


An interface is a tool and concept that refers to a
point of interaction between components, and is
applicable at the level of both hardware and
software. It may refer to the means of
communication between the computer and the user
by means of

peripheral

devices.

Hardware & Software Interface


Hardware Interfaces


Hardware interface is described by the mechanical,
electrical and logical signals at the interface and the
protocol for sequencing them (sometimes called
signaling)


Software Interfaces


Software interface may refer to a range of different
types of interface at different "levels": an operating
system may interface with pieces of
hardware,

applications

or

programs

running on the
operating system

OSI Layer

Data Transmission


Data transmission,

digital transmission, or

digital
communications

is the physical transfer
of

data

(a

digital

bit stream) over a point
-
to
-
point
or

point
-
to
-
multipoint communication channel.


Example of wireless data communication:


WiFi


InfraRed


BlueTooth


etc…


Why Bluetooth…?


Bluetooth is created by telecoms vendor Ericsson in
1994, it was originally conceived as a wireless
alternative to RS
-
232 data cables. It is a
proprietary open wireless technology standard for
exchanging data over short distances (using short
wavelength radio transmissions in the ISM band
from 2400
-
2480 MHz) from fixed and mobile
devices, creating personal area networks (PANs)
with high levels of security.

Bluetooth Application


Home Automation


http://www.youtube.com/watch?v=e94ITffGa1E&featu
re=related


http://www.youtube.com/watch?v=JVcMy18mVbI

CHAPTER

2:

INTERFACE IN
ANDROID

USING
BLUETOOTH

Bluetooth in Android


Bluetooth is an important tools in Android device to
communicate with others hardware. The main
functions are to transfer file and data.


In this session, Bluetooth will be used as a
communicator between Android device and
hardware to control mobile robot.

Bluetooth Settings


In Android Applications, select:


Settings > Wireless and Networks


Check the “Bluetooth” [v]


Bluetooth settings > Fine nearby devices


Find “Bluetooth_V3”


Enter PIN (Try 0000 or 1234)


Make sure

the device is

paired

Bluetooth Settings (captured)

Exercise :
BlueChat


BlueChat

(Bluetooth
Terminal) is an program in
Android device that is used
to transfer a message via
Bluetooth to computer or
other hardware/devices.


Let’s try the
BlueChat

program…


Import Project


Open Eclipse SDK


Select: File > Import







Chose project (example:
BlueChat
)


Click: Finish

CHAPTER

3:

SENSOR

APPLICATION

Android for Racing…


http://www.youtube.com/watch?v=gXaE3dqsx
zs


http://www.youtube.com/watch?v=fX77rWs9
Z7A&feature=related



Android Sensor for Controller


Android has a supporting sensors for detecting the
surrounding environment. Android supports several
sensors for example :


Proximity


Touch Screen


Accelerometer / Orientation


Gyroscope


Magnetic (compass)


Temperature

Button

Steering

1. Touch Screen (Button)


Touch screen
(button) can be use as a
controller for mobile robot. From Android
device, a button can be a communicator to
mobile robot using Bluetooth.

2. Orientation (Steering)


Orientation

is a feature that lets Android
applications detect the direction in which the
device is facing. In this session, orientation sensor
will be used as a steering to control mobile robot.




Project: Steering Controller

-

Import Project


Open Eclipse SDK


Select: File > Import







Chose project (example:
BlueSend
)


Click: Finish

-

Open File

Open File


Src

(
altaz.honey
)


blueSend.java


Res > Layout


main.xml


At
drawable
-
hdpi
, there are
some files that needed for
GUI (forward.png,
backward.png, stop.png)


> Layout (main.xml)

Drag “Button” and drop here…!!!

> Make Buttons

button1

button2

button3

> Make
TextViews

textView1

textView2

> Customize Buttons

> Customize Buttons

# Variable Declaration


Open blueSend.java


Copy this program, that is the declaration for
global variable.

//////////////////////////////////////

/* type your variable declaration here*/


TextView

data, position;

SensorManager

sensor;

int

sensor_data
;


//////////////////////////////////////

# Component Declaration


This program is the declaration for component that has
been made in
main.xml

to be recognize in
blueSend.java.

/////////////////////////////////////////////////////////

/* type your component declaration here*/



final Button button1=(Button)
findViewById
(R.id.
button1);

final Button button2=(Button)
findViewById
(R.id.
button2);

final Button button3=(Button)
findViewById
(R.id.
button3);



data =(
TextView
)
findViewById
(R.id.
textView1);

position =(
TextView
)
findViewById
(R.id.
textView2);

sensor = (
SensorManager
)
getSystemService
(
Context.
SENSOR_SERVICE
);



//////////////////////////////////////////////////////////

# Send Message Code

////////////////////////////////////////////////////////////////

/* type your send message code here */




button1.setOnClickListener(new
View.OnClickListener
() {

@Override


public void
onClick
(View arg0) {


sendMessage
("w"); //Forward

}

});



button2.setOnClickListener(new
View.OnClickListener
() {


@Override


public void
onClick
(View arg0) {


sendMessage
("q"); // Stop

}

});



button3.setOnClickListener(new
View.OnClickListener
() {

@Override


public void
onClick
(View arg0) {


sendMessage
("S"); // Backward


}

});



/////////////////////////////////////////////////////////////////

# Sensor list declaration

///////////////////////////////////////////////////////////////////////

/* type your sensor list here */





List<Sensor>
sList

=
sensor.getSensorList
(
Sensor.
TYPE_ALL
);



for(
int

i
=0;
i
<
sList.size
();
i
++)


{



sensor.registerListener
(this,
sList.get
(
i
),



SensorManager.
SENSOR_DELAY_NORMAL
);


}



///////////////////////////////////////////////////////////////////////

# Implements
SensorEventListener


Tipe

“implements
SensorEventListener
” in the class
blueSend


public class blue extends Activity
implements
SensorEventListener

{ …}


And then type this program (in the end)


@Override

public void
onAccuracyChanged
(Sensor
sensor
,
int

accuracy) {



Log.
d
("
SensorTest","onAccuracyChanged
: " +



sensor + ", accuracy: " + accuracy);

}


#
onSensorChanged
()

@Override

public void
onSensorChanged
(
SensorEvent

event) {

if(
event.sensor.getType
() ==
Sensor.
TYPE_ORIENTATION
)

{

data.setText
("" +/*
event.sensor.getName
() +*/ "" +

"Sensor data:
\
n" + event.values[2] + "
\
n");


sensor_data
=(
int
)
event.values
[2];


if(
sensor_data
<=
-
50){

sendMessage
("l");

position.setText
("Full Right");

}

else if(
sensor_data
>
-
50 &&
sensor_data
<=
-
20){

sendMessage
("k");

position.setText
("Right");

}

else if(
sensor_data
>
-
20 &&
sensor_data
<20){

sendMessage
("j");

position.setText
("Center");

}

else if(
sensor_data
>=20 &&
sensor_data
<50){

sendMessage
("h");

position.setText
("Left");

}

else if(
sensor_data
>=50){

sendMessage
("g");

position.setText
("Full Left");

}

}

}


Robot Steering Movement

Center (“j”)

Right (“k”)

Full Right (“l”)

Full Left (“g”)

Left (“h”)

GUI : Steering Controller

Bluetooth settings

Forward “w”

Sensor data

Robot steering movement

Stop “q”

Backward “s”

Lets Go for Racing ...!!!