Help with bluetooth...


Closed Thread
Results 1 to 25 of 25
  1. #1
    Join Date
    Oct 2008
    Posts
    65

    Unhappy Help with bluetooth...

    Hi everyone, I got an EGBC-04 bluetooth module. When I powered the EGBC-04 my pc detects it(Bluetooth discovery). But I'm having problem communicating with it(sending data only). I place leds to test the communication setup from PC to EGBC04 to PIC16F877A but no luck. Kindly check my setup and codes in the pic....I appreciate any help.

    Code:
    CLEAR		;read and write hardware USART
    B1	VAR     BYTE	;initialize USART
    
        TRISB = %00000000
        PortB = %00000000
    	TRISC = %10111111	;set TX (PORTC.6) to out, rest in
    	SPBRG = 25	;set baud rate to 2400
    	RCSTA = %10010000	;enable serial port and continuous receive
    				
    LOOP:		
    GOSUB CHARIN	;get a character from serial input, if any
    	IF B1 = 0 THEN LOOP 	;no character yet
    	GOTO LOOP	;do it forever
    			;subroutine to get a character 
    			;from usart receiver
    CHARIN: 
    B1 = 0			;preset to no character received
    	IF PIR1.5 = 1 THEN	;if receive flag then...
    		B1 = RCREG	;get received character to b1
    
    	   IF B1 = 65 then  
    	       If PortB.0 = 0 then
    	          High PortB.0 
               else
                  Low PortB.0
               Endif 	           
    	   ENdif
           
       ENdif            
    goto loop
    Thanks in advance,
    mbox
    Attached Images Attached Images  

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    I have not used an EGBC-04, but looking at the data sheet I will ask...

    Did you set the EGBC-04 for the baud rate you are using? I think it defaults to 9600.
    Did you set it as SLAVE? I think that is what you want.

    And, I would also think an inverter chip (RS232) is needed.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Oct 2008
    Posts
    65

    Default

    Hi Dave, I did adjust it to 9600 and do I really need the inverter chip? As I understand I only need it if I directly connect the BT module to the PC. But instead I have a USB bluetooth attached to PC to link with th EGBC-04. Please help..

    thanks,
    mbox
    Last edited by mbox; - 4th October 2009 at 14:47.

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    Quote Originally Posted by mbox View Post
    Hi Dave, I did adjust it to 9600 and do I really need the inverter chip? As I understand I only need it if I directly connect the BT module to the PC. But instead I have a USB bluetooth attached to PC to link with th EGBC-04. Please help..

    thanks,
    mbox
    I do not know for sure but to have a PIC communicate with a PC and using hardware serial the inverter chip is needed.

    I would think that any data passing through the BT module is inverted. As a quick test you could try SERIN2/SEROUT2 and use inverted mode.

    And you have your serial on the PIC set as 2400 baud. The BT is 9600???
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Oct 2008
    Posts
    65

    Default

    Hi Dave, thanks for the replies and I really do appreciate it. Ahm...I'm a little confuse, I hope you dont mind if I'm very slow to pick it all up. But may I explaine my hardware setup to understand what I'm missing.

    PC side: [Port - COM7] [Baud rate - 9600] [Byte size - 8] [Stop bit - 1]
    Sends character data 'A' over COM7 as given(device discovery).

    EBC-04 side: [Operates on 3.3v] [Baud rate - 9600] [Byte size - 8] [Stop bit - 1]

    PIC side: [Baud rate - 2400] PortC.7-->Rx

    Okay, I understand that I need to change 2400 to 9600 from PIC baud rate to communicate with EGBC. There are two option as I see, either I change the baud rate of the EGBC using AT commands by connecting to the pc with LVTTL TO RS-232 CONVERTER or change PIC's baudrate. But I dont have TTL to RS232 converter right now. So changing the Pic's baud rate is my option. I'm using 4MHZ crystal..how do I change it to 9600?

    Thanks,
    mbox
    Attached Images Attached Images  
    Last edited by mbox; - 5th October 2009 at 03:23.

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    The easy way to figure the USART settings is to use Mister E's PicMultiCalc
    http://www.picbasic.co.uk/forum/showthread.php?t=4994

    It gives
    Code:
     
    RCSTA = $90 ' Enable serial port & continuous receive
    TXSTA = $24 ' Enable transmit, BRGH = 1
    SPBRG = 25  ' 9600 Baud @ 4MHz, 0.16%
    But even changing the baud I still think you will need an inverter.
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Oct 2008
    Posts
    65

    Default

    Okay I will be purchasing my inverter module this week..I will post my updates. I can't wait this to be solve and the same time learn in the process.
    The inverter should be between the Bluetooth and the Pic ?

    Thanks again Dave,
    mbox
    Attached Images Attached Images  
    Last edited by mbox; - 5th October 2009 at 12:20.

  8. #8
    Join Date
    Dec 2005
    Posts
    1,073

    Default

    Quote Originally Posted by mackrackit View Post
    But even changing the baud I still think you will need an inverter.
    The manual shows two BT module to µC examples and one BT module to PC serial port example. Only the latter uses an inverter (i.e. their RS232 module).

    The PIC UART will likely have a Schmidt Trigger input - 3.3V is too low to be seen as logic high - 0.8Vdd is required. With SerIn or SerIn2 and TTL inputs, logic high is 2V.

    FIG 14 & FIG 15 of this app note http://www.zbasic.net/appNotes/AN213.pdf shows how to interface to the Schmidt Trigger input.
    Last edited by dhouston; - 5th October 2009 at 12:33. Reason: added link to app note

  9. #9
    Join Date
    Oct 2008
    Posts
    65

    Default

    Hi dhouston, I'm a beginner in electronics and seasonal pbp programmer. I hope I got this one, so in order to communicate properly I must use a Logic Translation Level between EGBC-0 and pic like the one below..
    BTW thanks for the link...I will experiment with it and post my updates.
    Attached Images Attached Images  
    Last edited by mbox; - 6th October 2009 at 04:29.

  10. #10
    Join Date
    Dec 2005
    Posts
    1,073

    Default

    @mbox

    The simplest solution would be to use SerIn or SerIn2 on a pin that has a TTL buffer. Read the I/O Ports section of the datasheet for the 16F877a as well as the Electrical Characteristics section. Ports A & B have TTL buffers on the pins and only need 2.0V for logic high.

    If you must use the hardware UART, I suggest using the circuit in FIG 15 of the app note. If you use FIG 14, the diode forward voltage drop may be marginal for the logic low input voltage (1.0V) unless you use a germanium diode. Read the explanation in the app note.

    EDIT: Also, if you use the diode, use the attached circuit.
    Attached Images Attached Images  
    Last edited by dhouston; - 6th October 2009 at 05:32.

  11. #11
    Join Date
    Oct 2008
    Posts
    65

    Default

    Hi to all, I change the codes and Port pin setup, at this time I used the SERIN and SEROUT...
    Code:
    include "modedefs.bas"
    B2 var byte 
    pause 500
    
    start:   
    
           serin 0,T9600,B2 ''''''''''''''''''''''''''' PortB.0 as my recieve pin from bluetooth Tx
           Serout PORTC.6, T9600, [#B2,10,13] '''''''''''''''''''''''PortC.6 as Transmit pin	 to pc com1
    
    	   IF B2 = 65 then  
    	       If PortB.1 = 0 then
    	          High PortB.1 
               else
                  Low PortB.1
               Endif 
               else
               	            
    	   ENdif
    goto start
    I noticed that it is generating random numbers pls see the attach...anybody knows what's the reason?

    Thanks in advance
    mbox
    Attached Images Attached Images  
    Last edited by mbox; - 6th October 2009 at 08:34.

  12. #12
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    Are you sending somthing from the PC and the random numbers are the echo?
    Dave
    Always wear safety glasses while programming.

  13. #13
    Join Date
    Dec 2005
    Posts
    1,073

    Default

    SerOut to the PC serial port needs to be inverted - use N9600.

  14. #14
    Join Date
    Oct 2008
    Posts
    65

    Default

    Hi everyone,

    mackrackit: Are you sending somthing from the PC and the random numbers are the echo?
    It suppose to lit a LED on PortB.1 when "A" is pressed. Connecting the EGBC TX--> PIC Rx causes the random generation number.

    dhouston: SerOut to the PC serial port needs to be inverted - use N9600.
    I tried that but it gives character sysmbols..pls see the attachment.
    Attached Images Attached Images   

  15. #15
    Join Date
    Dec 2005
    Posts
    1,073

    Default

    Quote Originally Posted by mbox View Post
    I tried that but it gives character sysmbols..pls see the attachment.
    I'm confused. Your code example comment says "PortC.6 as Transmit pin to pc com1" but your latest schematic appears to indicate another wireless connection to the PC.

    A wired RS232 connection needs N9600 for SerOut while a wireless connection may use T9600. A wireless connection may also be noisy, leading to the random data of your first example.

  16. #16
    Join Date
    Oct 2008
    Posts
    65

    Default

    Hi, sorry if it is confusing. I forgot to tell you that I'm using my mobile to send data to the bluetooth module and hopefully have it echoed to the Pc. My code for my phone is tested, it can send letter 'A' from phone to Pc thru bluetooth communication. And hoping it will the same way to pic with a bluetooth module. So this noise is normal? How can I prevent it from generating. I tried to observe while sending from my phone to pic if 65 is recieved, unfortunately it is not.
    Code:
     IF B2 = 65 then  ' waits for "A"
               If PortB.1 = 0 then
    	 High PortB.1 
               else
                  Low PortB.1
               Endif 
    
               else
               	            
    Endif
    Attached Images Attached Images  
    Last edited by mbox; - 7th October 2009 at 09:17.

  17. #17
    Join Date
    Dec 2005
    Posts
    1,073

    Default

    It may just be that your schematic is what confused me. I'm not familiar with Bluetooth serial adapters but would expect them to handle the noise suppression automatically.

    Try this:
    Code:
    start:  SerIn PortB.0,T9600,["A"] 		'wait for "A" on PortB.0
    	If PortB.1 = 0 Then
    	  SerOut PORTC.6,N9600,["HIGH",13,10]
    	  High PortB.1 
            Else
              Serout PORTC.6,N9600,["LOW",13,10]
              Low PortB.1
            Endif             	            
    	GoTo start

  18. #18
    Join Date
    Oct 2008
    Posts
    65

    Default

    I tried using the code but I got character symbols coming out.
    I tried to make them all T9600 and I got High and Low display...and I'm not even sending any data yet to the module..
    Attached Images Attached Images   

  19. #19
    Join Date
    Dec 2005
    Posts
    1,073

    Default

    Try
    Code:
    SerIn PortB.0,T9600,["ABC"]

  20. #20
    Join Date
    Oct 2008
    Posts
    65

    Default

    Hi there,
    SerIn PortB.0,T9600,["ABC"]
    No random generation, I then try to send "ABC" but nothing happen.
    I think somethings wrong with my bluetoooth and pic setup.
    I checked the supply its getting only 2.9 instead of 3.3v. I'm going to get IC regulator 3.3v and try to redo the setup...and let you know what happen.
    Attached Images Attached Images

  21. #21
    Join Date
    Dec 2005
    Posts
    1,073

    Default

    It would be helpful to know whether the output from the BT module is noisy. If you do not have an oscilloscope, you can record it as a .WAV file using the LineIn of your soundcard.

  22. #22
    Join Date
    Oct 2008
    Posts
    65

    Default

    Okay..I will do that sometime later today... I'm getting frustrated...do you know of any bluetooth module that you tried and tested in pic with pbp?

  23. #23
    Join Date
    Dec 2005
    Posts
    1,073

    Default

    No, I haven't used Bluetooth.

  24. #24
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    Can you try bypassing the PIC and connect the TX from the Bluetooth module directly to the PC com port?
    Dave
    Always wear safety glasses while programming.

  25. #25
    Join Date
    Oct 2008
    Posts
    65

    Default

    Hi,
    mackrackit: Can you try bypassing the PIC and connect the TX from the Bluetooth module directly to the PC com port?
    I can not do that right now. I dont have any Max232 chip.
    Last edited by mbox; - 8th October 2009 at 07:19.

Similar Threads

  1. Bluetooth problme with the 16F877A
    By slimpeng in forum Bluetooth
    Replies: 6
    Last Post: - 27th June 2009, 13:06
  2. interaction between Bluetooth and PIC MCU
    By veenadari in forum Bluetooth
    Replies: 1
    Last Post: - 23rd June 2009, 16:03
  3. help my bluetooth and PIC 16F877A?
    By slimpeng in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th March 2008, 07:52
  4. Bluetooth GPS and PBP interfacing
    By RFsolution in forum Bluetooth
    Replies: 0
    Last Post: - 5th January 2006, 12:17
  5. Bluetooth wireless with PIC / HSERIN / DAC
    By rpatel in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 20th December 2004, 23:13

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts