国民技术
直播中

jf_87001978

1年用户 23经验值
擅长:嵌入式技术 控制/MCU
私信 关注

【国民技术N32项目移植】智能温湿度监测系统项目移植: 支持蓝牙模块

1

1 综述

本项目选择的蓝牙模块为HC-08,其详细介绍如下:

1671805142473.png

具体参数请登录:广州汇承信息科技有限公司 (hc01.com)

2 硬件接口

该蓝牙模块可通过UART 接口与MCU连接,本程序选择N32G45x UART-2 接口

1671804761620.png

3 代码实现

3.1 需求

1、应用N32G45XVL-STB连接蓝牙模块

2、通过蓝牙模块发送温湿度值

3、手机端,通过蓝牙模块小程序,接收数据

3.2 代码实现

如下只展示核心代码,详细代码参考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 );
    }
}

4 测试

硬件测试

微信图片_20230109230253.jpg

微信小程序接收数据

微信图片_20230109225959.jpg

更多回帖

发帖
×
20
完善资料,
赚取积分