本项目选择的蓝牙模块为HC-08,其详细介绍如下:
具体参数请登录:广州汇承信息科技有限公司 (hc01.com)
该蓝牙模块可通过UART 接口与MCU连接,本程序选择N32G45x UART-2 接口
1、应用N32G45XVL-STB连接蓝牙模块
2、通过蓝牙模块发送温湿度值
3、手机端,通过蓝牙模块小程序,接收数据
如下只展示核心代码,详细代码参考gitee项目:
源代码和开发文档地址
https://gitee.com/mftang/n32-g45-xvl-stb.git
void bluetooth_action( void )
{
uint32_t time_count;
time_count = get_timer1_countMs();
if( time_count%1000 == 0 ) // 1000 ms scan the bluetooth port
{
bluetooth_senglog();
}
}
static void bluetooth_senglog( void )
{
uint8_t dataBuff[36];
double _outVal;
shtOpt *shtOpt = sht2xdrv_getResult();
// tempeture
if(shtOpt->st_Temp.dataValid)
{
memset((char*)dataBuff, '\0', sizeof(dataBuff));
_outVal = shtOpt->st_Temp.outValue;
shtOpt->st_Temp.dataValid = 0;
sprintf((char*)dataBuff, "TM(C): %.2f ", _outVal*0.01);
bluetooth_sendString( dataBuff );
}
// humidity
if(shtOpt->st_RH.dataValid)
{
memset((char*)dataBuff, '\0', sizeof(dataBuff));
_outVal = shtOpt->st_RH.outValue;
shtOpt->st_RH.dataValid = 0;
sprintf((char*)dataBuff, "HM: %.2f \r\n", _outVal*0.01);
bluetooth_sendString( dataBuff );
}
}
硬件测试
微信小程序接收数据
更多回帖