目录
一.前期材料准备
1.安装vs-code、准备好esp32 开发环境
2.一个电路板。一台电脑
3.一台已下载好spp蓝牙串口的手机
二.具体操作
1.spp蓝牙串口app下载
可在应用商店搜索下载,参照如下图
下载完成之后就可以进行链接啦
1.先打开APP,进行注册
2.注册完成之后将进行程序写入
2.具体操作流程
1.使用VS-code打开Espressif中提供的文件,此处本人使用了指导老师提供的代码文件
先使用vs-code对该段程序进行编译、并写入单片机
2.打开蓝牙,使用spp蓝牙串口搜索,找到自己编写的蓝牙名称,JFBike,点击连接
连接成功之后如下图所示,与此同时,单片机蜂鸣器响
3.同时可发送数据,发送成功,蜂鸣器响
esp32单片机图例
测试代码
以下代码段由指导老师提供,有些许改动,仅供参考。
/* Hello World Example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
/* GPIO Example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "driver/gpio.h"
#include "lvgl_init.h"
#include "soc/rtc.h"
#include "driver/mcpwm.h"
#include "soc/mcpwm_periph.h"
#include "time.h"
#include "sys/time.h"
#include "sys/unistd.h"
#include "driver/adc.h"
#include "esp_adc_cal.h"
#include "esp_log.h"
#define _SUPPORT_BT_ 1
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
uint8_t DebugOn = 1;
#define DEBUG_CODE if(DebugOn)
#define GPIO_OUTPUT_IO_BEEP 19
#define START_BEEP {mcpwm_start(MCPWM_UNIT_0, MCPWM_TIMER_0);}
#define STOP_BEEP {mcpwm_stop(MCPWM_UNIT_0, MCPWM_TIMER_0);}
// #define POWER_ON {mcpwm_start(MCPWM_UNIT_0, MCPWM_TIMER_2);}
// #define POWER_OFF {mcpwm_stop(M