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.

[PIC] Need a program for a bluetooth connection with MCU for autopairing.

Status
Not open for further replies.

emiel1963

Newbie level 4
Joined
Dec 15, 2014
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
64
Hello , everyone. We are a none profit organization working for schools in Brazil at this moment. For one of our projects we need a piece of programming in ASM or other language so that we can store MAC addresses from paired phones into the PIC. The PIC will then compare them and if they are in the memory of the PIC it drives a GPIO high ( LED ON ). If the phone is out of reach of the Module the PIC drives the GPIO LOW (LED OFF ). We are using the WT11 from Blue Giga ( donated ) and the PIC 16F628A. The connection goes over UART. Can anyone help us out please. We can pay some money for it or give advertising time wen the project comes on TV in Brazil. Hope to hear from some genius who is familiar with this equipment and language. Thanks
 

Okay so let me get this straight first. You are talking to the PIC through UART and will give it a MAC address of a phone. At that time you will compare the MAC addresses in memory and determine if it is a stored phone or not. Does that sound right? How do you store the initial MAC addresses? What interfacing do you need?
 

Hi , CL. Thanks for replying to my question. You´ve goy it right that we are talking about a module that is connected thru UART on a low baud of 9600. Al the commands that has to be given by the PIC is in IWRAP command like INQUIRY 2 to let the module search for devices , and SET BT PAIR to get devices and store them into the memory of the PIC. By inquiring constantly ( every 10 seconds ) the PIC should get the MAC addresses of al the phones nearby and compare them with the memory. With the IWRAP command INQUIRY 2 you limit the number of phones ( to 2 ) that are looked up for and that the PIC has to compare. The initial storing of the phone should be done after a phone is paired thru a password , that is controlled by the module. If I am right this can be done with the IWRAP command SET BT PAIR ( I will get the right command from Blue Giga ) and the settings for the module to achieve this. I hope that you understand what I need and thank you again for your reply.
 

Okay so let me get this straight first. You are talking to the PIC through UART and will give it a MAC address of a phone. At that time you will compare the MAC addresses in memory and determine if it is a stored phone or not. Does that sound right? How do you store the initial MAC addresses? What interfacing do you need?



Hi CL10GREG . After receiving responses of the donator of the module , blue giga , I know what to do to et were we want to go. I will explain the steps to take , the needed commands and the responses of the wt11. This because I do not know if the MCU can read only the word in a sentence that it need to take action.

1) Power up , wen serial available sent RESET and wait for READY. ( response wt11 READY , clearing all the pairings in the module )Also clear all the stored MAC addresses in the memory of the 16F628A

2 pull up RA1(pin 18 ) of 16F628A up for 1 second and wait for READY ( response wt11 READY , ) entering command mode

3 When received CONNECT send RSSI 0 in a endless loop and the first time capture only mac address( for comparing later ) of connected phone and write to memory of 16F628A. ( response wt 11 RSSI < MAC ADRRESS > AND rssi value )
Same time pull up RA0 of 16F628A

4 when receive RSSI value of -100 ( or response NO CARRIER ) pull RA0 low ( the value must be adjustable for us in the initial programming for test purposes )
( complete response wt11 after losing connection = NO CARRIER 0 ERROR c0c RFC_L2CAP_LINK_LOSS )

5 Next time that the mac address appears in the wt11 response of the RSSI loop compare with memory of 16F628A ( if true pull up RA0 , if falls leave RA0 low. )

6 When receive RSSI -100 ( or response NO CARRIER ) pull RA0 low


I hope that I explained it all clearly and that you guys understand it because I have no experience with programming
Thanks upfront and I wish you all a merry Christmas.
 

Small change in the programming!!!

Hi CL10GREG . After receiving responses of the donator of the module , blue giga , I know what to do to et were we want to go. I will explain the steps to take , the needed commands and the responses of the wt11. This because I do not know if the MCU can read only the word in a sentence that it need to take action.

1) Power up , wen serial available sent RESET and wait for READY. ( response wt11 READY , clearing all the pairings in the module )Also clear all the stored MAC addresses in the memory of the 16F628A

2 When receive CONNECT pull up RA1(pin 18 ) of 16F628A up for 1 second and wait for READY ( response wt11 READY , ) entering command mode

3 Wait 1 second and start sending RSSI 0 in a endless loop and the first time capture only mac address( for comparing later ) of connected phone and write to memory of 16F628A. ( response wt 11 RSSI < MAC ADRRESS > AND rssi value )
Same time pull up RA0 of 16F628A

4 when receive RSSI value of -100 ( or response NO CARRIER ) pull RA0 low ( the value must be adjustable for us in the initial programming for test purposes )
( complete response wt11 after losing connection = NO CARRIER 0 ERROR c0c RFC_L2CAP_LINK_LOSS )

5 Next time that the mac address appears in the wt11 response of the RSSI loop compare with memory of 16F628A ( if true pull up RA0 , if falls leave RA0 low. )

6 When receive RSSI -100 ( or response NO CARRIER ) pull RA0 low


I hope that I explained it all clearly and that you guys understand it because I have no experience with programming
Thanks upfront and I wish you all a merry Christmas.
 

hello,

I am not using same bluetooth module, but an RN41
and i add some choice to connect any slave to android application
maybe it can inspire you..

Code:
int  BT_Configure(void);
void  Init_BT_direct(void);
char BT_Get_Response(void);
void Test_BT_Answer(void);



int  BT_Configure()
{ 
  dummy=PutStrR_RS("---");    // Exit mode command mode
  Put_RS(13);
  Tempo(200000L); 
  dummy=PutStrR_RS("---");    // to be sure !
  Put_RS(13);
  Tempo(100000L); 
  State=0;
 
 do 
  {
    dummy=PutStrR_RS("$$$");    // Enter command mode, attend CMD
     Put_RS(13);
    Tempo(200000L);
    //signed char memcmppgm2ram(const void * buf1,const rom void * buf2,sizeram_t memsize );
  } while ((memcmppgm2ram(pBuff,"CMD",3)!=0)&& (Elapsed==0));
  Test_BT_Answer();
 if (State!=1)return(0);

 do {
    dummy=PutStrR_RS("SN,MyBT-DB49"); //Name of the device, 20 characters maximum
    Put_RS(13);
    Tempo(150000L);
 } while ((memcmppgm2ram(pBuff,"AOK",3)!=0)&& (Elapsed==0));
 Test_BT_Answer();
 if (State!=2)return (0);
 
      
 do {
    dummy=PutStrR_RS("SU,19.2"); // Vitesse en bauds 
    Put_RS(13);
    Tempo(150000L);
 }  while ((memcmppgm2ram(pBuff,"AOK",3)!=0)&& (Elapsed==0));
 Test_BT_Answer();
 if (State!=3)return(0);
    
 do {
   dummy=PutStrR_RS("SO,13");   //break caractere
    Put_RS(13);
    Tempo(150000L);
  } while ((memcmppgm2ram(pBuff,"AOK",3)!=0)&& (Elapsed==0));
 Test_BT_Answer();
 if (State!=4)return (0);
   
 do {
    dummy=PutStrR_RS("SM,0");
  // Set mode (0 = slave, 1 = master, 2 = trigger, 3 =auto, 4 = DTR, 5 = ANY)
    Put_RS(13);
    Tempo(150000L);
  } while ((memcmppgm2ram(pBuff,"AOK",3)!=0)&& (Elapsed==0));
 Test_BT_Answer();
 if (State!=5)return (0);

  do {
    dummy=PutStrR_RS("SA,1");    // Authentication (1 to enable, 0 to disable)
    Put_RS(13);
    Tempo(150000L);
 } while ((memcmppgm2ram(pBuff,"AOK",3)!=0)&& (Elapsed==0));
  Test_BT_Answer();
  if (State!=6)return (0);
    
  do {
    dummy=PutStrR_RS("SP,1234");  // Security pin code (mikroe)
    Put_RS(13);
    Tempo(150000L);
  } while ((memcmppgm2ram(pBuff,"AOK",3)!=0)&& (Elapsed==0));
  Test_BT_Answer();
  if (State!=7)return (0);

  do {
    dummy=PutStrR_RS("---");   // fin mode config
    Put_RS(13);                          // CR
    Tempo(150000L);
  }  while ((memcmppgm2ram(pBuff,"END",3)!=0)&& (Elapsed==0));
  Test_BT_Answer();
  if (State!=8)return (0);
  return(State);        // si link OK on doit avoir State=8  
}


void Test_BT_Answer()
{
   if (Elapsed==0) 
   {
    State++;
    Erase_Ligne(2);
    LCD_PutRamString(pBuff);
    Arme_Elapsed_Timer3();
    }   
    else
    {
    State=0;
    }
 }

 ******************************************
 
 //use inside the main program
// and choose the correct slave to connect to Android App
 
  
  // init partielle du RN41
  Init_BT_RN41_direct() ;

  Nokia_Erase_Ligne(7);
 
  
  Nokia_Erase_Ligne(5);
 if(Client_BT==1)  // RB5==1 ?
 { 
   // Adresse ARchos par defaut
   dummy=PutStrR_RS("SR,D8952F3FF710");  
   Put_RS(13);
   Nokia_PutRomString("SR,D8952F3FF710"); 
   Delay_mS(100);
   dummy=PutStrR_RS("C,D8952F3FF710");   // Connection forcee 
   Put_RS(13);
 
  }
  else
  {  
    // Adresse PC  cle USP APM      
  dummy=PutStrR_RS("SR,0015832B6D87");    
  Put_RS(13);    
 
   Nokia_PutRomString("SR,0015832B6D87"); 
   Delay_mS(100);
   dummy=PutStrR_RS("C,0015832B6D87"); 
   Put_RS(13);
  
  // Adresse HC05-7D69-B   bleu  as slave
  // dummy=PutStrR_RS("SR,98D331B17D69");   
  // Put_RS(13);
  //  Nokia_PutRomString("SR,98D331B17D69"); 
  // dummy=PutStrR_RS("C,98D331B17D69");   // Connection forcee 
 
  // Adresse HC06-1122-V  Vert  as slave 
  // dummy=PutStrR_RS("SR,201301241122");   
  // Put_RS(13);
  // Nokia_PutRomString("SR,201301241122");  
  
  // Adresse HC06-2187-J  as slave
  // dummy=PutStrR_RS("SR,201308072187");  
  //  Put_RS(13);
  //  Nokia_PutRomString("SR,201308072187");   
    
  }
 

Hi, Paul . Thanks for your reply but as a mentioned I have no programming skills and it´s more that we are stuck with this non-profit project because of this. I can read your script a 1000 times and still don't understand it ( LOL ). We really need a piece of programming for the steps mentioned above . I would love to understand it but there is no time for me to start learning programming because of the time that we have to finish it . I hope there is some genius that´s able to do this. Again , thanks for your reply.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top