与STM32F103C8T6的HC-05接口HC-05蓝牙|STM32蓝色药丸

在此项目中,我将向您展示如何与STM32F103C8T6蓝色药丸板接口HC-05蓝牙。通过将HC-05或HC-06(例如HC-06)的蓝牙模块与STM32连接,您可以从其他蓝牙设备(例如智能手机)中与STM32 MCU无线通信。

As a demonstration of this project, I will control the on-board LED connected to Pin PC13 of the MCU from a Bluetooth App installed on an Android Phone.

HC-05 Bluetooth Module

介绍

Bluetooth is one of the most popular wireless communication protocols used in embedded systems. Even in consumer electronics like mobile phones and laptops, it is commonly used for data transfer and audio functionalities.

In fact, with the development of BLE (Bluetooth Low Energy), the development and implementation of Bluetooth based wireless headsets is at its peak (sorry 3.5mm headphone jack fanboys, myself included!).

Coming to the Embedded World, the HC-05 Bluetooth Module is the most popular Bluetooth Modules being used for a long time. It is a simple UART based module that runs at the traditional 2.4GHz wireless frequency for a range up to 10m.

我已经实施了基于HC-05的几个基于HC-05的项目。例如,在“ HC-05蓝牙模块”教程中,我讨论了有关HC-05蓝牙模块的一些基本信息,其布局在板上的布局,其引脚描述,并演示了如何接口HC-05 Bluetooth bluetooth带有Arduino的模块。

HC-05蓝牙模块销和组件

因此,我建议您参考该教程以获取有关HC-05蓝牙模块的其他信息。在这个项目中,我将专注于将HC-05蓝牙与STM32F103C8T6蓝色药丸板接口。

重要的提示

在上一个STM32教程中,我讨论了STM32F103C8T6蓝色药丸板的基础知识,以及如何通过板的USB端口上传程序。我不会再讨论这些主题。因此,我建议您在进行此项目之前完全仔细阅读下面提到的先前教程。

介绍to STM32F103C8T6– “Getting Started with STM32F103C8T6 Blue Pill

使用USB端口程序STM32蓝色药丸– “How to Upload STM32F103C8T6 USB Bootloader?

同样,您可以使用的编程方法s i.e. the traditional UART based programming using USB to Serial Adapter or the USB Bootloader based programming through the on-board microUSB Port.

如果您打算使用uart,然后请注意,相同的引脚用于与蓝牙模块(PINS PA9和PA10)进行通信。

而且,如果您使用的是USB编程,请断开蓝牙模块形式的STM32板,上传程序并重新连接蓝牙模块。此外,请确保您设置正确的引导引脚配置。

Circuit Diagram

下图显示了与STM32F103C8T6 MCU接口HC-05蓝牙模块的电路图。

Interfacing HC-05 Bluetooth with STM32F103C8T6 Circuit Diagram

Components Required

硬件

  • STM32F103C8T6蓝色药板
  • HC-05 Bluetooth Module
  • 连接电线
  • USB to Serial Adapter (if programming STM32 via UART)
  • USB电缆
  • 基于Android的智能手机

软件

  • Any Bluetooth Terminal App for Android Phone

我没有对蓝牙应用程序提出任何建议,并且可以随意使用任何蓝牙终端应用程序。为了展示该项目,我使用了Kai Morich的“串行蓝牙终端”。如果要使用相同的话,请使用这个link.

Connections Explained

The connections between STM32F103C8T6 Blue Pill Board and the HC-05 Bluetooth Module are very simple. The RX pin of the Bluetooth Module is connected to PA9 pin of the MCU and the TX pin of the Bluetooth Module is connected to PA10 pin of the MCU.

VCC and GND of the HC-05 Bluetooth Module can be connected to 5V and GND pins of the Blue Pill board. The on-board LED, which is connected to PC13, is used for demonstration.

Interfacing HC-05 Bluetooth with STM32F103C8T6

现在,我们已经看到了电路和连接,让我们继续进行HC-05蓝牙与STM32F103C8T6的实际接口。由于HC-05蓝牙模块基于UART上的串行通信,因此我们必须使用蓝色药丸板的UART引脚与蓝牙模块进行通信。

To make things simpler, I have used the UART1 pins i.e. PA9 (TX) and PA10 (RX) pins for interfacing with HC-05 Bluetooth Module. Be careful when uploading the program.

如果您是通过USB将STM32编程为UART转换器,那么您也没有问题,因为您也必须使用相同的引脚进行编程。这意味着无论如何都必须断开蓝牙模块。

The problem is if you chose to upload the program via the USB Port. In this case, you have to disconnect the Bluetooth Module’s Communication connections with STM32 i.e. PA9 and PA10.

Another important thing to remember is the connection of the on-board LED. The following image shows how the LED is connected to PC13 pin of the MCU.

LED Connection to STM32F103C8T6

From this image, it is clear that when the PC13 pin is LOW, the LED will be turned ON and when the PC13 pin is HIGH, the LED will be turned OFF. Hence, in the code, I will using the same configuration to turn ON and OFF the LED.

Code

The code for the project is given below. It is very simple and if you already implemented an Arduino HC-05 Bluetooth Module interface, then the code is very easy to understand.

const int LEDPin = PC13;
char inputData = 0;

void setup()
{
Serial1.Begin(9600);
serial1.println(“电子中心”);
serial1.println(“带有STM32的HC-05蓝牙”);
pinMode(LEDPin, OUTPUT);
}

void loop()
{
if(Serial1.available() > 0)
{
inputData = serial1.read();

if(inputData == ‘0’)
{
DigitalWrite(Ledpin,高);
Serial1.println(“LED is turned OFF”);
}

否则(inputData =='1')
{
DigitalWrite(Ledpin,Low);
Serial1.println(“LED is turned ON”);
}
}
}

上面的Serial1表示我正在使用UART1进行通信。您也可以使用STM32F103C8T6的UART2或UART3,前提是您建立适当的连接并在代码中提供适当的初始化。

Working

该项目的工作非常简单。首先,将程序上传到STM32蓝色药丸,然后根据电路图进行连接。然后转到Android智能手机上的蓝牙设置,然后配对HC-05蓝牙模块。

第一次配对时,它将要求销钉。在这种情况下,输入1234或0000。在我的情况下,它是1234。配对完成后,在Android手机上打开蓝牙终端应用程序,然后搜索蓝牙设备。选择HC-05蓝牙模块。

现在,将应用程序配置为传输“ 1”和“ 0”。当传输“ 1”时,LED将被打开,并且在传输“ 0”时,LED将被关闭。

HC-05带有STM32应用的蓝牙模块

结论

In this project, I have talked about one of the commonly used Communication Modules by beginners and hobbyists i.e. the HC-05 Bluetooth Module. Also, I have demonstrated a simple project by Interfacing HC-05 Bluetooth with STM32F103C8T6 Blue Pill Board.

A simple Bluetooth terminal App on an Android Smart Phone is used to communicate with HC-05 Bluetooth Module to transmit some data. The STM32 will then decode the data and turn the on-board LED ON or OFF.

一个回应

  1. 声音箱设备蓝色牙齿始终出现问题

    Hi, I need advice please,
    Wish to disconnect the Bluetooth Circuit so it cannot send or accept wireless transmission without damaging other operations the board may be doing, such as the Charge control…as I cannot control its BT-On BT-Off operation,
    希望能够通过当前的3.5mm连接器(仅有线)连接扬声器,并继续通过扬声器通过USB PC连接器充电。

    Reason: Voice communication security with BT always On.

发表评论

Your email address will not be published.

Electronicshub Favicon
<\/i>","library":""}}" data-widget_type="nav-menu.default">
Baidu