Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

8051 Bluetooth Simple Code

Status
Not open for further replies.

johnjameson

Junior Member level 3
Junior Member level 3
Joined
Jan 30, 2012
Messages
31
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
1,516
Hey Guys,
I have a visual basic *program here which can be used to read data from the serial port(pretty sure its working right as I have a com port emulator program to simulate data coming in and it reads it ok)
I also have a AT89S52 micro interfaced with a HC-06 bluetooth module which is paired with a pc.
Just wondering is there any example programs of sending data via bluetooth?
Just something simple like sending a number or a word

*left out program
 
Last edited:

hello,

So, in your PC you must have a vrtual COM port ,linked to your
USB/bluetooh interface ?
and you need also a service (program) to establish this link
after you can use the created virual COM port with your Basic Program..

Do you know BlueSoleil application ?
(or another programme to get the virtual port !)

an example of link between a PIC + HC05 or RN41 blue tooth module:
an APM USB/Bluetooth Key on PC
BlueSoleil see all devices around the PC
You appair the correct device
After you open a service PORT A
and connect your terminal r (or your Appli VB on PC) to the COM8 port..

PIC_BlueSoleil_COM8.jpg
 

Sorry I wasn't too clear in my intial post.
I used a program called "virtual null modem" to create a virtual com port,then I used a program call "Com Port Data Emulator" to simulate data coming from the virtual com port e.g number or words.
The visual basic program was then able to read this data coming from the virtual com port and display it on screen.

Now as I mentioned above I have a AT89S52 8051 micro interfaced with a HC-06 bluetooth module and I wanna see can the visual basic program receive data from 8051.
Now like what I mean can I load some sort of simple c program onto the micro that can send out a number/word via bluetooth to the same visual basic program.
 

HI John,

You already have a system where you can read the 8051 serial stream on the PC's serial port, right?

Then, you need nothing more to use the HC-06. Just connect the HC-06 Tx and Rx to the 8051 Rx and Tx respectively (make sure you have the level shifters right, the HC-06 would require 3.3 volt swings), and you should be able to catch the data on the PC using any USB bluetooth dongle running on a virtual com port. You can confirm the 2-way comms using a terminal emulator on the PC.

Regards,

Anand Dhuru
 

HC 06 is only a slave (receiver). It will not transmit. You need master like HC 05 to send out data. Use HC 05 instead of HC 06.
 

hello,

you can use booth HC05 or HC06 for SSP link ...
but i found sometimes probleme to establish the link at first time, when HC06 is not ready to accept apparairing
so i fund on the web a solution: use the RESET entry on HC06 ..
unfortunatly, this entry is not connected to a Pin Out on the board...
i soldered a little wire directly on the daugter board..an get a PIN RESET !

i send a little initialising part of code to be shure ,the link is OK
after i use the PIC UART like a traditionnal RS232 link ...without wires.

i tested this datas link to PC with 12F1840 and HC05.. successfuly at 10 meters

here is a portion of my used code:

Code:
========================================================
void interrupt(void)  org 0x04
{
 if ((RCIE_bit==1) &&(RCIF_bit==1))
   {
   // traitement separe des erreurs de COM
      if (RCSTA.OERR==1)    // voir parag 16.1.26 p273
      {
      c1=RCREG;           // efface drapeau OVERRUN
       RCSTA.CREN = 0 ;
       RCSTA.CREN = 1 ;
       //CptOV++;
        CptErr++;
       }
      if(RCSTA.FERR==1 )
      {
      RCSTA.SPEN = 0 ;
      //CptFE++;
      RCSTA.SPEN= 1 ;
      CptErr++;
      }
      c1 = RCREG;
     if (c1==CR)
      {
      Flag_Buffer=1;
      PIE1.RCIE=0 ; //interdit IT Reception UART
      Buffer[i1]=0;
      Index1=i1;
      i1=0;
      c1=0;
     }
     else
     {
        buffer[i1]=c1;
        i1++;
        Index1=i1;
      }
     PIR1.RCIF=0   ;
    }
 //.... other interrupts
//

}





void Get_Answer()
{

 Delay_ms(1500); 
 if (i1>0)           // test sur index car pas de CR sur reponse HC06
 {   buffer[i1+1]=0;     // limite largeur affichage  du nokia=14cars
    if((buffer[0]='O') && (buffer[1]='K')) k++;
    //UART2_Write_Text(buffer); 
  }
   Delay_ms(100);
    buffer[0]=0;
    i1=0; c1=0;
    RCIF_bit=0;
    Index1=0;
}  



void  Init_BT_HC06_direct()        // en aveugle,sans test reponse
 { 
 //00:15:83:2B:6D:87 MyPC  OWNPF
 // D8:95:2F:3F:F7:10  Archos43
 UART1_Write('A'); UART1_Write('T'); 
 Get_Answer();   //OK
 UART1_Write_Text((const char *)"AT+NAMEHC06-7D69"); //98:D3:31:B1:7D:69
 
 Get_Answer();     //OKsetname
 UART1_Write_Text((const char *)"AT+PIN1234"); 
 
 Get_Answer();   //OK19200
 UART1_Write_Text((const char *)"AT+BAUD5"); 
     
 Get_Answer();  //OK19200
 UART1_Write_Text((const char *)"AT+VERSION");
    
 Get_Answer();  //OKlinvorV1.80
}    

#define Reset_BT_HC06 LATA5_bit     // RA5 direct sur circuit imprimé RESET HC06




.... inside the main -------

   
    Init_Hardware();
    Reset_BT_HC06=1;
   .....
   UART1_Init(19200);
   .....
 
   Reset_BT_HC06=0;

  
  
  PIE1.RCIE=1;
  PIE1.TMR1IE=0;  // Enable interrupt on PR1=TMR1
  INTCON.PEIE=1;  // autorise IT des peripherique voir fig  8.1 p 77
  INTCON.GIE=1;   // Enable all interrupts (timer1 & UART)
  i1=0;
  buffer[0]=0;
  Index1=0;

   
  ....
 Init_BT_HC06_direct() ;

.. then , use UART like a RS232 link ...
 

HI John,

You already have a system where you can read the 8051 serial stream on the PC's serial port, right?

Then, you need nothing more to use the HC-06. Just connect the HC-06 Tx and Rx to the 8051 Rx and Tx respectively (make sure you have the level shifters right, the HC-06 would require 3.3 volt swings), and you should be able to catch the data on the PC using any USB bluetooth dongle running on a virtual com port. You can confirm the 2-way comms using a terminal emulator on the PC.

Regards,

Anand Dhuru
Yes I have a program that can read from the serial port.
I've also connected the HC-06 to the micro as you mentioned above and reduced the voltage to 3.3v(as I was using a 5v input)

Its the next phase I wanna test,like for example on the 8051 micro instead of sending numbers/words to a lcd,I want to instead send this to the pc

- - - Updated - - -

Something similar to this code here except here instead of using an 8051 micro they're using a Arduino
http://learning.grobotronics.com/2013/07/communicating-using-bluetooth-hc-06/
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top