[SOLVED] Bluetooth HC-05 to PC using PIC16F887

Status
Not open for further replies.

Luis Daniel Bolaños

Member level 2
Joined
Apr 4, 2014
Messages
47
Helped
2
Reputation
4
Reaction score
2
Trophy points
8
Visit site
Activity points
342
Hello there!

I have googled for a couple hours but I'm still confused about how to transmit from a PIC16F887 to a PC using the Bluetooth module HC-05 through UART communication. So I'm requesting your help! Oh, and I'm programming on C (still don't get the difference between MikroC and MPLAB X)

I need to transmit some basic characters from the PIC to the PC. So, do I just need to configure the UART as a RS232 transmission and plug in the HC-05? I read something about an AT mode of configuration but it is confusing me. I don't get how to pair the modules, how to configure... I'm lost.

Thanks for your help and sorry if I'm not more specific but don't know more details :-(
 

hello,


Do you have an USB/Blutooth key on your PC ?
Do you have a PC program to catch the Virtual COM ( like BlueSoleil) ?
is it a true HC05 or HC06 ?
One is only a SLAVE ..
Factory config is SLAVE,SSP mode, so in theory ,
you d'ont have to configure it with AT commands, when using as UART link.

When power on, the led must blink on HC-05
then you paire the HC05 device with your PC application
The led must be fixe = linked to PC
Your PC application must support a virtual COM port
connect it ,to get the PIC UART data .

or you can try to connect with an Android Phone or Tablet (with BlueTooth possibility !).
I wrote an application with Appinventor 1 and another with RFObasic
to drive PIC devices trough UART link .

you can see**broken link removed** some tests about BT link.
 


I haven't started yet, so I got nothing done.
Those two articles were useful. So, since it acts as Slave, I only need to configure the UART transmission on the PIC16F887, right? But, what about the parameters? 9600 baud/s? Parity?


I guess I'm buying a Bluetooth adapter for my PC, and yes I have a virtual terminal.
I don't have the HC05, it is shipping.
 

Mine HC05 (sell as a HC05) but is in reality a HC-06 slave only !
can be use at 9600,N,8,1 (factory setting) without any AT command..
but, the main probleme is the Init at Power ON..
sometimes it doesn't blink at power ON.. impossible to paire with other PC or Tablett
and impossible to enter in AT mode..
The Reset pin 34 of the device goes not outside the breakboard
and need a special strap to do , to recover Factory setting

Before to use with your PIC, You better have to test your HC05 direct connected to
a PC terminal RS232 trough a Max3223 (3,3V TTL side) adapter
and try to connect to your same PC or another PC with a BT/USB Key.

and test some AT command... to evaluate your device by yourself.
because HC-05 name cover many different version..
and RPC vendor doesn't provide the own Datasheet .. of there product.
 


OK, I did some code already using libraries from MikroC and set a standard RS232 communication as you said.
Right now, only need to wait for the module. Here goes the code:

Code:
void main( void )
{
     //Declaración de variables.
     int X=0;
     char DATO;
     TRISD = 0xFF;
     TRISC = 0x00;
     PORTC = 0x00;
     UART1_Init(9600);
     UART1_Write_Text("REGISTRO DE ALARMA");
     UART1_Write(13);
     UART1_Write(10);
     UART1_Write_Text("Estado: DESACTIVADA");
     UART1_Write(13);
     UART1_Write(10);
     UART1_Write(13);
     UART1_Write(10);
     while(1)
     {
           if (PORTD.F0 == 1)
           {      
                  X = 0;
                 PORTC.F0 = 0;
                 UART1_Write_Text("Estado: DESACTIVADA");
                 UART1_Write(13); 
                 UART1_Write(10); 
                 UART1_Write(13);
                 UART1_Write(10);
                 delay_ms(500);
           }
           if (PORTD.F1 == 1)
           {
                 X = 1;
                 PORTC.F0 = 1;
                 UART1_Write_Text("Estado: ACTIVADA");
                 UART1_Write(13);
                 UART1_Write(10);
                 UART1_Write(13); 
                 UART1_Write(10);
                 delay_ms(500);
           }
           if (PORTD.F2 == 1 && X == 1)
           {
                 X = 2;
                 UART1_Write_Text("Estado: SONANDO");
                 UART1_Write(13); 
                 UART1_Write(10); 
                 UART1_Write_Text("Causa: Puerta conductor");
                 UART1_Write(13); 
                 UART1_Write(10);
                 UART1_Write(13);
                 UART1_Write(10); 
                 while (PORTD.F0 == 0)
                 {
                       PORTC.F1 = 1;
                       delay_ms(500);
                       PORTC.F1 = 0;
                       delay_ms(500);
                 }
           }


     }

}

I don't have the MAX3223 so I need to test it straight with the PIC. I'm hoping with that code (tested on Proteus, it worked) I just need to connect the HC05 to the Tx and Rx pins and pair to the PC.

How am I doing?
 

I think HC05 is a slave and HC06 is master and slave. If you want PIC to send data and BT connected to PC to receive data and display on Serial terminal software then you have to connect HC-06 to PIC and HC-05 to PC. Then PIC sends data to HC-06 and HC-06 will transmit it to HC-05 and HC-05 to PC.
 


Ok, so now I tested it. I connected directly the HC-05 to the UART and sent some ASCII characters (X,O,P) and received them on my Android via a serial terminal emulator. The issue is I keep receiving wierd stuff, random symbol and chinese letters, any idea why?
 

Maybe something with baudrate ?

Does the module has 5V TTL pins or is it 3.3V TTL pins and you are interfacing it to 5V TTL pins of PIC ?
 
Last edited:

The module has 3.3V TTL and the PIC has 5V, so can that be the issue?

Yes, I think that is the issue. Maybe your BT modules is already damaged. I think PIC16LF887 is not available. So, try to use any other PIC18LF device which are 3.3V devices or use a logic level converter between PIC and BT module.

If you are using these modules then it is mentioned that they can work with both 3.3V and 5V TTL devices.

https://www.banggood.com/HC-06-Wire...F-Main-Module-Serial-For-Arduino-p-80364.html

https://www.banggood.com/HC-05-Wire...sceiver-Module-Slave-And-Master-p-908621.html
 
Last edited:


I used it with Arduino and it's still working!

I used 1,8k and 3,3K resistors to make a voltage divider so it would convert 5V to 3.3V but still.. random characters.

And yes, I'm using the second one, the HC-05
 

Which is master and which is slave ? BT at PC side is slave ? BT connected to PIC is master ?

Change


Code C - [expand]
1
UART1_Init(9600);



to


Code C - [expand]
1
UART1_Init(9615);



and try.

You might be getting 0.16% error in baudrate in messages window of mikroC. I don't know how much that affects.



Have you read this ?

https://www.instructables.com/id/Modify-The-HC-05-Bluetooth-Module-Defaults-Using-A/

https://www.youtube.com/watch?v=-z_0aU8VHzk



Edit

https://alselectro.wordpress.com/2014/10/21/bluetooth-hc05-how-to-pair-two-modules/
 
Last edited:


Changed it to 9615, nothing happened... gonna read the links. However I don't know if changing configurations is going to help because I connected it straight to the Arduino and worked perfectly :|
 

Please zip and post your complete mikroC project files. I will check it once.

Thank you, there goes the MikroC Project and the Proteus 8 simulation. It it just the PIC Tx and Rx pins to the Virtual Terminal, and phisically they go to Rx and Tx of Bluetooth respectively.

View attachment TxBluetooth.rar

I tried with and without the voltage divider in the PIC's Tx pin but nothing changed.
 

Try the attached code. When you tested in Proteus was it working ? What are you using internal RC oscillator or external 8 MHz crystal ?

Maybe your PIC is damaged. Can you connect PIC UART directly to PC using TTL2USB adaptor and check if data is received on Serial Terminal software.

You can also use my code and in Proteus add a COMPIM and set COMPIM's baudrate and COM port properly. Connect both BT modules to PC USB port using TTL2USB adaptors. Note down the COM port (Virtusl COM port) created for each BT module. If COM ports are between 1 and 4 then in COMPIM set COM port to that value else if COM port is higher like 5, 20, etc... then download and install eterlogic Virtual Serial Port Emulator (VSPE) and create a mapper type device which maps physical COM port on your PC like COM1 to Virtual COM port being used by the BT that has to connect to PIC. Then start the mapper. In Proteus set COMPIM's COM port to COM1 or whatever you used in VSPE. Then simulate Proteus. Also connect RxD of VT to Tx of PIC. VT will show PIC's working. A Serial port set to watch another BT will display any received data.
 

Attachments

  • TxBluetooth.rar
    34.6 KB · Views: 165
Last edited:

Try the attached code. When you tested in Proteus was it working ? What are you using internal RC oscillator or external 8 MHz crystal ?

I tried it, nothing improved :bang: And yes, it was working in Proteus. I'm using the intenal RC 8 MHz oscillator.

I attach you a screen capture of what my Android captured: the interrogation signs are the ASCII interpretations and the rest are the HEX strings received.

 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…