Monday, 30 September 2013

Communication between two mbeds LPC11U24 via SPI and each have 2 LEDS and 2 switches

 Code for Master mbed:
#include "mbed.h"
SPI ser_port(p11, p12, p13);
DigitalOut red_led(LED1);
DigitalOut green_led(LED2);
DigitalOut cs(p14);
DigitalIn switch_ip2(p7);
DigitalIn switch_ip1(p6);
char switch_word;
char recd_val;

int main() {
    while(1) {
    switch_word=0xa0;
     if(switch_ip1==1)
    switch_word=switch_word|0x01;
    if(switch_ip2==1)
    switch_word=switch_word|0x02;
    cs=0;
    recd_val=ser_port.write(switch_word);
    cs=1;
    wait(0.1);
    red_led = 0;
    green_led = 0;
    recd_val=recd_val&0x03;
    if(recd_val==1)
    red_led=1;
    if(recd_val==2)
    green_led=1;
    if(recd_val==3){
    red_led=1;
    green_led=1;
    }
    }

}

Code for Slave mbed
#include "mbed.h"
SPISlave ser_port(p11, p12, p13, p14);
DigitalOut red_led(LED1);
DigitalOut green_led(LED2);
//DigitalOut cs(p14);
DigitalIn switch_ip2(p7);
DigitalIn switch_ip1(p6);
char switch_word;
char recd_val;

int main() {
    while(1) {
    switch_word=0xa0;
     if(switch_ip1==1)
    switch_word=switch_word|0x01;
    if(switch_ip2==1)
    switch_word=switch_word|0x02;
    if(ser_port.receive()){
    recd_val=ser_port.read();
    ser_port.reply(switch_word);
    }
    red_led = 0;
    green_led = 0;
    recd_val=recd_val&0x03;
    if(recd_val==1)
    red_led=1;
    if(recd_val==2)
    green_led=1;
    if(recd_val==3){
    red_led=1;
    green_led=1;
    }
    }
}


SPI communication

Sunday, 4 August 2013

Keypad and Serial Communication with PC using 8051

#include <reg51.h>

#define COL P2
#define ROW P0



 void MSDelay(unsigned int vaulue);
 void SerTx(unsigned char);
// void lcddata(unsigned char value);

 unsigned char keypad[4][4]= {'0','1','2','3',
                               '4','5','6','7',
      '8','9','A','B',
'C','D','E','F'};
 void main()
 {
 unsigned char colloc, rowloc;
 TMOD=0X20;
TH1=-3;
SCON=0X50;
TR1=1;
  COL=0xFF;
  while(1)
  {
    do
 {
   ROW=0x00;
colloc =COL;
colloc &=0x0F;
}
while(colloc!=0x0F);
    do
{
do
 {
  MSDelay(20);
  colloc=COL;
colloc&=0x0F;
}
while(colloc==0x0F);
MSDelay(20);
  colloc=COL;
colloc&=0x0F;
}
while(colloc==0x0F);
while(1)
{
  ROW=0xFE;
colloc=COL;
colloc&=0x0F;
if(colloc!=0x0F)
{
rowloc=0;
break;
}

ROW=0xFD;
colloc=COL;
colloc&=0x0F;
if(colloc!=0x0F)
{
rowloc=1;
break;
}

ROW=0xFB;
colloc=COL;
colloc&=0x0F;
if(colloc!=0x0F)
{
rowloc=2;
break;
}

ROW=0xF7;
colloc=COL;
colloc&=0x0F;
rowloc=3;
break;
}

if (colloc==0x0E)
SerTx(keypad[rowloc][0]);
  else if(colloc==0x0D)
 SerTx(keypad[rowloc][1]);
else if(colloc==0x0B)
 SerTx(keypad[rowloc][2]);
else
SerTx(keypad[rowloc][3]);
}
}
 
 void SerTx(unsigned char x)
 {
 SBUF=x;
while(TI==0);
TI=0;
 }

 void MSDelay(unsigned int value)
{
 unsigned int x, y;
 for(x=0;x<1275;x++)
 for(y=0;y<value;y++);
 }

Serial Communication with PC using 8051

#include<reg51.h>
sbit MYSW=P2^0;
void main(void)
{
unsigned char z;
unsigned char fname[]=" Abha ";
unsigned char lname[]=" Singh ";
TMOD=0x20;
TH1=0xFD;
SCON=0x50;
TR1=1;
if(MYSW==0)
{
for(z=0;z<10;z++)
{
SBUF=fname[z];
while(TI==0);
TI=0;
}
}
else
{
for(z=0;z<15;z++)
{
SBUF=lname[z];
while(TI==0);
TI=0;
}
}
}

Interfacing LCD and Keypad with 8051

#include <reg51.h>

#define COL P2
#define ROW P0
#define LCD P3
sbit rs = P1^5;
sbit rw = P1^6;
sbit en = P1^7;
sbit refresh = P1^4;

 void MSDelay(unsigned int vaulue);
 void lcdcmd(unsigned char value);
 void lcddata(unsigned char value);

unsigned char keypad[4][4]= {'0','1','2','3',
                               '4','5','6','7',
                 '8','9','A','B',
                'C','D','E','F'};
 void main()
 {
//refresh=1;
 unsigned char colloc, rowloc;
restart:
 lcdcmd(0x38);
 MSDelay(250);
 lcdcmd(0x0E);
 MSDelay(250);
 lcdcmd(0x01);
 MSDelay(250);
 lcdcmd(0x06);
 MSDelay(250);
 lcdcmd(0x80);
  COL=0xFF;
  while(1)
  {
if(refresh==0)
{
goto restart;
     }
    do
 {
   ROW=0x00;
colloc =COL;
colloc &=0x0F;
}
while(colloc!=0x0F);
    do
{
do
 {
  MSDelay(20);
  colloc=COL;
colloc&=0x0F;
}
while(colloc==0x0F);
MSDelay(20);
  colloc=COL;
colloc&=0x0F;
}
while(colloc==0x0F);
while(1)
{
  ROW=0xFE;
colloc=COL;
colloc&=0x0F;
if(colloc!=0x0F)
{
rowloc=0;
break;
}

ROW=0xFD;
colloc=COL;
colloc&=0x0F;
if(colloc!=0x0F)
{
rowloc=1;
break;
}

ROW=0xFB;
colloc=COL;
colloc&=0x0F;
if(colloc!=0x0F)
{
rowloc=2;
break;
}

ROW=0xF7;
colloc=COL;
colloc&=0x0F;
rowloc=3;
break;
}

if (colloc==0x0E)
{ lcddata(keypad[rowloc][0]);
     MSDelay(250); }
else if(colloc==0x0D)
{ lcddata(keypad[rowloc][1]);
     MSDelay(250); }
else if(colloc==0x0B)
 { lcddata(keypad[rowloc][2]);
     MSDelay(250); }
else
{ lcddata(keypad[rowloc][3]);
     MSDelay(250); }
}

}
 
 void lcdcmd(unsigned char value)
 {
 LCD = value;
 rs=0;
 rw=0;
 en=1;
 MSDelay(1);
 en=0;
 return;
 }

 void lcddata(unsigned char value)
 {
 LCD = value;
 rs=1;
 rw=0;
 en=1;
 MSDelay(1);
 en=0;
 return;
 }

void MSDelay(unsigned int value)
{
 unsigned int x, y;
 for(x=0;x<1275;x++)
 for(y=0;y<value;y++);
 }

Interfacing LCD with 8051

//Program to display String on LCD

#include<reg51.h>
#define  lcd_data_pin P1 // data port P2
sbit rs=P2^0; // Register select pin
sbit rw=P2^1; // Read write pin
sbit en=P2^2; // Enable pin
void delay(unsigned int msec)    //delay function
{
int i,j;
for(i=0;i<msec;i++)
for(j=0;j<1275;j++);
}
void lcd_command(unsigned char comm) // function to send command to LCD
{
lcd_data_pin=comm;
en=1;
rs=0;
rw=0;
delay(1);
en=0;
}
void lcd_data(unsigned char disp)    // function to send data on LCD
{
lcd_data_pin=disp;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
}

lcd_dataa(unsigned char *disp)    // function to send string to LCD
{
int x;
for(x=0;disp[x]!=0;x++)
{
lcd_data(disp[x]);

}
}

void lcd_ini()     //Function to inisialize the LCD
{
lcd_command(0x38);  
delay(5);
lcd_command(0x0F);      
delay(5);
lcd_command(0x80);
delay(5);
 

}
void main()
{
lcd_ini();
lcd_dataa("ABHA SINGH");
}

Ethernet


I2C

Introduction

Interrupt

Introduction

Timer

Introduction

RF Module


  • Introduction

RFID


  • Introduction

IR Transmitter-Reciever

Introduction

Android Apps for Project


  • Introduction

GSM Module


  • Introduction

GPS Module


  • Introduction

Xbee (Zigbee) Module

  • Introduction

DC Motor

  • Introduction

Stepper Motor


  • Introduction

LEDs and Switches

We do basic and first program on any microcontroller of LED blinking.

Keypad

LCD (Liquid Crystal Display)

Temperature Sensors: LM35

ADC0804

Celsius scale digital thermometer using AT89C51

Circuit

Code:

//Program to make a digital thermometer with display in centigrade scale

#include<reg51.h>
#define port P3
#define adc_input P1
#define dataport P0
#define sec 100
sbit rs = port^0;
sbit rw = port^1;
sbit e = port^2;
sbit wr= port^3;
sbit rd= port^4;
sbit intr= port^5;

int test_intermediate3=0, test_final=0,test_intermediate1[10],test_intermediate2[3]={0,0,0};

void delay(unsigned int msec )
{
int i ,j ;
for(i=0;i<msec;i++)
  for(j=0; j<1275; j++);
}

void lcd_cmd(unsigned char item)  //Function to send command to LCD
{
dataport = item;
rs= 0;
rw=0;
e=1;
delay(1);
e=0;
return;
}

void lcd_data(unsigned char item) //Function to send data to LCD
{
dataport = item;
rs= 1;
rw=0;
e=1;
delay(1);
e=0;
//delay(100);
return;
}

void lcd_data_string(unsigned char *str)  // Function to send string to LCD
{
int i=0;
while(str[i]!='\0')
{
  lcd_data(str[i]);
  i++;
  delay(10);
}
return;
}

void shape()     // Function to create the shape of degree
{
lcd_cmd(64);
lcd_data(2);
lcd_data(5);
lcd_data(2);
lcd_data(0);
lcd_data(0);
lcd_data(0);
lcd_data(0);
lcd_data(0);
}
     
void convert()    // Function to convert the values of ADC into numeric value to be sent to LCD
{
int s;
test_final=test_intermediate3;
lcd_cmd(0xc1); 
delay(2);
lcd_data_string("TEMP:");
s=test_final/100;
test_final=test_final%100;
lcd_cmd(0xc8);
if(s!=0)
lcd_data(s+48);
else
lcd_cmd(0x06);
s=test_final/10;
test_final=test_final%10;
lcd_data(s+48);
lcd_data(test_final+48);
lcd_data(0);
lcd_data('c');
lcd_data(' ');
delay(2);
}

void main()
{
int i,j;
adc_input=0xff;
lcd_cmd(0x38); 
lcd_cmd(0x0c);  //Display On, Cursor  Blinking
delay(2);
lcd_cmd(0x01);  // Clear Screen
delay(2);

while(1)
{
  for(j=0;j<3;j++)
  {
   for(i=0;i<10;i++)
   {
    delay(1);
    rd=1;
    wr=0;
    delay(1);
    wr=1;
    while(intr==1);
    rd=0;
    lcd_cmd(0x88);
    test_intermediate1[i]=adc_input/10;
    delay(1);
    intr=1;
   }
   for(i=0;i<10;i++)
   test_intermediate2[j]=test_intermediate1[i]+test_intermediate2[j];
  }

test_intermediate2[0]=test_intermediate2[0]/3;
test_intermediate2[1]=test_intermediate2[1]/3;
test_intermediate2[2]=test_intermediate2[2]/3;
test_intermediate3=test_intermediate2[0]+test_intermediate2[1]+test_intermediate2[2];
shape();
convert();
}
}

ADC0804: Introduction

FEATURES
• Compatible with 8080 μP derivatives – no interfacing logic needed – access time 135 ns
• Easy interface to all microprocessors, or operates “stand alone”
• Differential analog voltage inputs
• Logic inputs and outputs meet both MOS and  TTL voltage level specifications
• Works with 2.5V (LM336) voltage reference
• On-chip clock generator
• 0V to 5V analog input voltage range with  single 5V supply
• No zero adjust required
• 0.3" standard width 20-pin DIP package resolution.
• 20-pin molded chip carrier or small outline package
• Operates ratiometrically or with 5 VDC, 2.5 VDC, or analog span adjusted voltage reference
Pin Description



bus stop

Relay

Bluetooth Module

Seven Segment Display

1.Digital Clock using 7-segments on mbed LPC11U24
2.Digital Alarm on mbed LPC11U24 using four 7-segments

Serial Communication with PC, Bluetooth and Xbee(Zigbee)

Wednesday, 24 July 2013

My M.tech project -2 :Remote Monitoring Electrical devices using IOT(Internet of Things

6. PROJECT: REMOTE MONITORING ELECTRICAL DEVICES USING BLUETOOTH
As IoT is the new trend in the market. The main blocks of IoT are :
1. Any wireless communication
2. MCU/MPU for processing and software tools and
3. Relays to control 220 volt AC signal electrical devices by 3.2 to 5 volt DC signal.
I have chosen Bluetooth wireless communication because if embedded devices are enabled with Wi-Fi and Bluetooth, they can communicate directly with a smartphone and it is cost effective. I have taken mbed LPC11U24 as it is cost effective and fast in comparison to 8051 and AVR microcontroller. It allow others feature such as analogin, analogout, PWMout, USB device, I2C, SPI, Ethernet etc.

 6.1 Block Diagram of IoT using Bluetooth

Fig 4: Block diagram of IoT using Bluetooth

6.2 Working Principle of IoT using Bluetooth
The Bluetooth module is being interface with MCU via serial pins (p5 & p6 in mbed LPC11U24 and 1 & 2 in Arduino) as shown in fig 4. When we give supply to Bluetooth module then Smartphone will detect it and we can paired with it. Now install Google Play app ‘BlueTerm’ on Android Smartphone and connect Bluetooth module with it as shown in fig 5 given below. This figure shows the display screen of Blueterm.
 This android application is similar to HyperTerminal in PC. When we send command to Bluetooth as it is serial communcaion, then microcontroller do work according to commands received by BlueTerm app. The LCP11U24 ARM works on 3.2 volt which is very low for relay so we require amplifying it by using transistors. The working of relay is described in next topic and fig 6.


Fig 5: Display Screen of BlueTerm on Smartphone


6.6 Flowchart


Fig 7: Flowchart of source code


7.2 Source code on mbed LPC11U24
#include<mbed.h>
Serial blue(p9,p10);          // HC05
AnalogIn ain20(p17);
DigitalOut myled(LED1);
DigitalOut led5(p5);
DigitalOut myled2(LED4);
DigitalOut led6(p6);
float ADCdata;
 int main()
{
    while (1)
    {
      if (blue.avialable())
      {
        if(blue.getc()=1)
        {
       blue.printf("  Red Bulb is ON please press '2' to OFF ");
             myled = 1;
            led5=1;
            }
         if(blue.getc()=2)
         {
           blue.printf("   Red Bulb is OFF please press '1' to ON ");
            myled=0;
            led5=0;
            }
         if(blue.getc()=3){
          blue.printf("   Green Bulb is ON please press '4' to OFF ");
            myled2=1;
            led6=1;}
          if(blue.getc()=4)
          {
         blue.printf("   Green Bulb is OFF please press '3' to ON ");
            myled2=0;
            led6=0;
            }
          if(blue.getc()=5)
          {
            blue.printf("   CHECK THE STATUS OF LEDS ");
            if(led5==1)
            blue.printf("   Red Bulb is ON please press '2' to OFF ");
            if(led5==0)
             blue.printf("   Red Bulb is OFF please press '1' to ON ");
             if(led6==1)
            blue.printf("   Green Bulb is ON please press '4' to OFF ");
            if(led6==0)
             blue.printf("  Green Bulb is OFF please press '3' to ON ");
            }
        }
    }
}


Tuesday, 9 July 2013

bluetoothdemo

Android app : To add two integer values


AndroidMenifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.bekar2"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="16" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.bekar2.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>


</manifest>

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">

    <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/eText1"
            android:layout_alignParentTop="true"
            android:layout_alignLeft="@+id/eText2"
            android:text="text1"/>

    <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/eText2"
            android:layout_below="@+id/eText1"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="16dp"
            android:text="text2"/>

    <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="addButton"
            android:id="@+id/btnadd"
            android:layout_below="@+id/eText2"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="29dp"/>

</RelativeLayout>

strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name" >bekar2
    </string>
</resources>

MainActivity.java

package com.example.bekar2;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {
    private EditText text1,text2;
    private Button addButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        addListenerOnButton();
    }

    public void addListenerOnButton(){
        text1=(EditText)findViewById(R.id.eText1);
        text2=(EditText)findViewById(R.id.eText2);
        addButton=(Button)findViewById(R.id.btnadd);
        addButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String value1=text1.getText().toString();
                String value2=text2.getText().toString();
                int a=Integer.parseInt(value1);
                int b=Integer.parseInt(value2);
                int sum=a+b;
                Toast.makeText(getApplicationContext(),String.valueOf(sum),Toast.LENGTH_LONG).show();
            }
        });
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
 
}

Connect bluetooth module HC-05 with mbed LPC11U24 and control relay to monitor elctrical device


http://mbed.org/users/edodm85/notebook/HC-05-bluetooth/

Pin description


/media/uploads/edodm85/1-881-.jpg

Schematic for Trasparent data mode

/media/uploads/edodm85/ch05_sch2.png

mbed ARM code:


#include "mbed.h"
Serial blue(p9,p10);          // HC05
DigitalOut myled(LED1);
DigitalOut led5(p5);
DigitalOut myled2(LED4);
DigitalOut led6(p6);

int main()
{

  blue.baud(9600);
  while (1)
    {
      if (blue.readable())
      {
        if(blue.getc()=='1')
        {
        blue.printf("  LED5 is ON please press '0' to OFF ");
             myled = 1;
            led5=1;
            }
         if(blue.getc()=='0')
         {
            blue.printf("   LED5 is OFF please press '1' to ON ");
            myled=0;
            led5=0;
            }
         if(blue.getc()=='3'){
            blue.printf("   LED6 is ON please press '2' to OFF ");
            myled2=1;
            led6=1;}
          if(blue.getc()=='2')
          {
            blue.printf("   LED6 is OFF please press '3' to ON ");
            myled2=0;
            led6=0;
            }
          if(blue.getc()=='5')
          {
            blue.printf("   CHECK THE STATUS OF LEDS ");
            if(led5==1)
            blue.printf("   LED5 is ON please press '0' to OFF ");
            if(led5==0)
             blue.printf("   LED5 is OFF please press '1' to ON ");
             if(led6==1)
            blue.printf("   LED6 is ON please press '2' to OFF ");
            if(led6==0)
             blue.printf("   LED6 is OFF please press '3' to ON ");
            }
        }
   
    }
}

Video



Friday, 21 June 2013

Digital Clock using 7-segments on mbed LPC11U24

/*digital clock*/
#include"mbed.h"
BusOut Seg1(p5,p6,p7,p8,p9,p10,p11,p12);//A,B,C,D,E,F,G,DP

int A,C,D,E,F,G;
char B;
int main(){
char SegConvert(char SegValue);
while(1){
A++;
C=A%4;
switch(C){
 case 0:set1=0,set0=1,set2=0,set3=0;
     B=SegConvert(D);
     break;
 case 1:set1=1,set0=0,set2=0,set3=0;
    B=SegConvert(E);
    break;
 case 2:set1=0,set0=0,set2=1,set3=0;
     B=SegConvert(F);
     break;
  case 3:set1=0,set0=0,set2=0,set3=1;
     B=SegConvert(G);
     break; }
     Seg1=B;
     wait(0.001);
   if(A==1000)
   { A=0;
     D++;
     if (D>9)
      {D=0;
        E++;}
      if (E>5)
        { E=0;
          F++;}      
        if (F>9)
          {F=0;
            G++;}
            if (G>5)
            G=0;      } }}

char SegConvert(char SegValue)
{char SegByte=0x00;
switch(SegValue){
case 0: SegByte=0x3F ;break;
case 1: SegByte=0x06 ;break;
case 2: SegByte=0x5B ;break;
case 3: SegByte=0x4F ;break;
case 4: SegByte=0x66 ;break;
case 5: SegByte=0x6D ;break;
case 6: SegByte=0x7D ;break;
case 7: SegByte=0x07 ;break;
case 8: SegByte=0x7F ;break;
case 9: SegByte=0x6F ;break;
}return SegByte;}

Wednesday, 19 June 2013

How to make BlueTerm for working on HTC incredible mobile.

Overcoming Android bluetooth “blues” with Reflection method

Introduction
It is an Android problem: bluetooth does not function in a satisfactory manner. Having recently  started to “hack” into Android devices, and learning while doing, I was immediately confronted with the real world of something that does not fully work (bluetooth in Android devices) at least not satisfactorily as with J2ME devices I worked with before (Nokia and Blackberry).  It is worse if you do, as I did, in buying an Android smartphone in China (A3 Star, HTC T8585 clone) . You will be immediately confronted with the merchants that are insensitive to your requests for technical support. Effectively you learn immediately that there is nobody out there to talk to.
Android bluetoooth “blues”
When I connected my Android phone to external devices, in my case a bluetooth module, the immediate response was an “unable to connect” toast. “Googling“ made me desperate when the enormity of information confused me even more. How to approach the problem, what is wrong with my cheap chinese Android phone? MediaTek the chipset manufacturer of the device’s processor does not “leak” out any source codes to be able to hack bluetooth libraries for example.
Reflection method – solution to connection problem
If you seek quality technical responses I advise you Stock Overflow. That is where I finally learnt a few things such as the problem of connection is overcome with Reflection method.
Technically-speaking the reason is that the widely used connection method CreateInsecureRfcommSocketToServiceRecord() was only included starting with Android API Level 10. When targeting an API lower than 10 (ex 2.3.3 or Gingerbread), the method is not publicly accessible. The Reflection method overcomes that.
So in my chinese HTC clone “A3 Star” I have now a fully working Android market’sBlueTerm, a free app that I use for my engineering tests with external devices. I had to hack into BlueTerm´s source code (it is publicly available at http://pymasde.es/blueterm/) in order to change the method of connection to the Reflection one.
Looking into libraries of my phone’s processor MTK6573, I noted that they were made in 2008, and were never updated. Perhaps in China (the primary target of MTK processors) they do not use SPP at all, and are insensible to “techie“ learners like me wanting to use SPP connection in bluetooth.
On Reflection method among others, you can read more at Stock Overflow site
The code mod made to BlueTerm app
Additionally a special credit is due to Teholabs and their source code for BlueScripts app and the connection method of Reflection. You need to open in your adequate Eclipse environment BluetoothSerialService.java and add at the begining of the file:
Just before:
import java.util.UUID;
Add:
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
And down in the file find:
 try {
    tmp = device.createRfcommSocketToServiceRecord(SerialPortServiceClass_UUID);
    } catch (IOException e) {
    Log.e(TAG, "create() failed", e);
    }
    mmSocket = tmp;
    }
And substitute with
  Method m;
   try {
     m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class         });
        tmp = (BluetoothSocket) m.invoke(device, 1);  
        } catch (SecurityException e) {
     Log.e(TAG, "create() failed", e);
     } catch (NoSuchMethodException e) {
     Log.e(TAG, "create() failed", e);
     } catch (IllegalArgumentException e) {
     Log.e(TAG, "create() failed", e);
     } catch (IllegalAccessException e) {
     Log.e(TAG, "create() failed", e);
     } catch (InvocationTargetException e) {
     Log.e(TAG, "create() failed", e);
     }         

   mmSocket = tmp;
    }
You are now ready to compile and download the BlueTerm app into your Andorid device, hopefully without any errors.
The Results
You need to first of all to pair your Android phone to the external module. So I assume you have paired your phone to external bluetooth module. Now we are ready to start the BlueTerm app. This is the first screen you see when you start BlueTerm app:
Opening screen of BlueTerm App
First screen of BlueTerm App
showing “not connected”
We next find the paired device pressing the menu button of your Android phone and choose “Connect Device“. You will see the paired devices including the module you have just paired:
Screen showing paired device
Screen showing paired device
Choose the device and immediately BlueTerm will show the message at the top right of the screen “connecting…”.
If connection is successful the folowing screen will show with virtual keyboard to send commands:
Screen showing connected SPP
Screen showing connected SPP
To leave the application you have to press the menu button on your device and you will now have to disconnect. It is advisable to disconnect:
Screen showing disconnect device
Screen showing disconnect device
UPDATE: For non-techincal users of Android devices I have made available a ready to install BlueTerm app at my most recent post. Before downloading the apk, please read my disclaimer on the same page.
Bugs and Improvements
This mod  is quite fresh and needs to be tested further. I have had to reboot once my HTC clone as the app froze when I tried to disconnect. Any improvements and code sharing from visitors to this blog will be appreciated.
Moral of history
If you want a fully working smartphone do not buy in China, and if you really want to take the risk, check beforehand on the reliability of your supplier.
However I confess, I have an inside feeling of gratitude to the chinese, because if everything was working fine, I would have had no challenges to overcome, and would have not learnt much about Android bluetooth.  The chinese manufacturers do not make available source codes, while non-chinese manufacturers do, or have “leaked” source codes.
Source codes mean opportunities to mod and to improve and a chinese manufacturers do not seem to “leak” these codes.
Conclusions
Just as Bluescripts does the next step for me will be to connect in default way, and then in alternate way (update: I have already made a ready to install modded app of Blueterm – check above).
From now on, I will be able to write new apps for my chinese HTC clone, using Reflection method. The Reflection method is only valid for situations similar to mine.  I hope that sharing this work of mine will help others with similar error messages “unable to connect” in their Android devices.