简体   繁体   中英

How to detect if a device get my phone bluetooth name?

蓝牙和蓝牙与蓝牙

Im guessing you want something like this: VIDEO

Lets start with the basics:

The typical default factory settings for a new Bluetooth HC-05 module are:

  • Default Bluetooth Name: “HC-05”
  • Default Password: 1234 or 0000
  • Default Communication: Slave Device
  • Default Mode: Data Mode
  • Default Data Mode Baud Rate: 9600, 8, N, 1
  • Default Command Mode Baud Rate: 38400, 8, N, 1
  • Default firmware: LINVOR

1. To TEST Bluetooth connections from your android device use id suggest you use this APK

2. Connect the HC-05 BT module as shown in the diagram

在此处输入图片说明

3. Initialize the UART receiver at the microcontroller end (side)

(code includes 2 leds for pin 33 and pin 34)

/*
* LAB Number: 17
* LAB Name: Bluetooth Module HC-05 Interfacing (Smartphone -> MCU)
* Author: Khaled Magdy
* For More Information Visit My Website @ DeepBlueMbedded.com
*
*/

#include <xc.h>
#include <stdint.h>
#include "config.h"
#define _XTAL_FREQ 4000000
//--[ Control Data ]--
#define Blue_LED_ON    49
#define Blue_LED_OFF   50
#define Yellow_Toggle  51
//--------------------------------
// Functions Declarations
void UART_RX_Init(void);
// Globals
uint8_t UART_Buffer = 0;
//--------------------------------

// Main Routine
void main(void)
{
  //--[ Peripherals & IO Configurations ]--
  UART_RX_Init(); // Initialize The UART in Master Mode @ 9600bps
  TRISB0 = 0;     // Blue LED  (Switch)
  TRISB1 = 0;     // Yellow LED (Toggle)
  RB0 = 0;        // Initially OFF
  RB1 = 0;        // Initially OFF
  //---------------------------
  while(1) 
  {

  }
  return;
}
//--------------------------------
// Functions Definitions

void UART_RX_Init()
{
  BRGH = 1; // Set For High-Speed Baud Rate
  SPBRG = 25; // Set The Baud Rate To Be 9600 bps
  // Enable The Ascynchronous Serial Port
  SYNC = 0;
  SPEN = 1;
  // Set The RX-TX Pins to be in UART mode (not io)
  TRISC6 = 1; // As stated in the datasheet
  TRISC7 = 1; // As stated in the datasheet
  //--[ Enable UART Receiving Interrupts ]--
  RCIE = 1; // UART Receving Interrupt Enable Bit
  PEIE = 1; // Peripherals Interrupt Enable Bit
  GIE = 1; // Global Interrupt Enable Bit
  //------------------
  CREN = 1; // Enable Data Continous Reception
}

void interrupt ISR (void)
{
  if (RCIF == 1)
  {
    UART_Buffer = RCREG; // Read The Received Data Buffer

    // This could have been done within the main loop. Since it's not
    // Excessive processing, so it's OK to do it here below
    if(UART_Buffer == Blue_LED_ON)
      RB0 = 1; // Blue LED ON
    if(UART_Buffer == Blue_LED_OFF)
      RB0 = 0; // Blue LED OFF
    if(UART_Buffer == Yellow_Toggle)
      RB1 = ~RB1; // Toggle Yellow LED 

    RCIF = 0; // Clear The Interrupt Flag
  }
}

NOTE The Data Bytes (49, 50, and 51) are the ASCII equivalents for the numeric characters (1, 2, and 3 respectively).

4. Download this apk to send commands to your HC05: APK

For more info follow Reference: LINK

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM