excalidraw 📖 阅读信息
阅读时间:11 分钟 | 中文字符:4501 | 有效代码行数:1374
介绍 软件使用 vscode 和 esp-idf 插件(让 vs 认识芯片)进行编写
芯片,模,开发板 三者关系 esp 32 s 3 简介 一个 MCU(自带蓝牙和 wifi)芯片
但是芯片 外围需要外围电路通电才能工作,接入之后——模组 (芯片 + 外围电路)(芯片能正常工作的最小单位),将模组焊接在地板上,再搭配电路——开发板
不推荐直接将芯片放在开发板上,优势 (模组的)如下
QFN-56 封装引脚,需要良好的焊接水平,否则容易短路 射频电路需要专门设计,设计不好 WIFI、蓝牙的信号强度 EMC 问题,某些行业 (医疗器械、铁路等) 需要电磁兼容性认证,要求电路板有良好的抗干扰能力和较低的对外辐射,这就需要电路板信号进行分析,在电路板设计时做专门的处理。 esp 32 内部结构
flash:ROM(储存部分,硬盘) RAM(内存)
命名:
代码:
s 3 r 8 参数如下:
模组系列 在芯片的基础上变为模组(下图为通信)
外设 指内核以外的某些部分:
对于芯片来说,外设是指内核以外的部分,对于开发板来说,外设指主控芯片以外的部分
交换矩阵
交换矩阵:公路网(引脚配置灵活)
IO MUX:直连(相当于高速公路)
esp 32 开发板 前置知识 高电平(供电电压 )和低电平
我们现在芯片使用的供电电压为 3.3 V
IO 口的上拉和下拉
上拉电阻的阻值越小,上拉的能力越强
正式软件开发 教程:https://geeksman.com/series/esp32-arduino/
常用的开放方式:
MicroPython,常用的开发软件为 Thonny,支持 Python 语法,容易上手 Arduino,便捷灵活、方便上手的开源电子原型平台,支持 ESP32、ESP8266 等,可以使用 Arduino IDE 或者 VSCode/Clion + PlatformIO 进行项目开发。 ESP-IDF,是乐鑫官方的物联网开发框架,基于 C/C++ 语言提供了一个自给自足的 SDK,方便用户在这些平台上开发通用应用程序。 最常用的为上面的两种 arduino 基于 c++ 的
说明 Arduino 是一款开源电子原型平台,由意大利的开发者 Massimo Banzi 和 David Cuartielles 共同开发。它由硬件和软件两部分组成,硬件部分包括一个控制器和一些电子元件,软件部分则是基于简单易学的 C++ 编程语言的 Arduino IDE。
Arduino 的最大优势就是它简单易学,开发门槛低,所以成为了电子制作、物联网等领域的热门选择。在 Arduino 的官方网站上,你可以找到各种各样的项目示例,从简单的 LED 闪烁到复杂的机器人控制都有。同时,Arduino 社区非常活跃,有很多志同道合的开发者分享自己的作品和经验,可以帮助新手更快地入门。
开发板功能 序号 功能 1 复位按键 2 MicroUSB 接口,用于程序下载、电源输入等 3 BOOT 按键:启动模式选择,按下表示下载模式,放开表示运行模式 4 ESP32-WROOM-32 模组:通用型 Wi-Fi + BT + BLEMCU 模组,模组集成了传统蓝牙、低功耗蓝牙和 Wi-Fi,具有广泛的用途:Wi-Fi 支持极大范围的通信连接,也支持通过路由器直接连接互联网。 5 GPIO(general purpose input output)是通用输入输出端口的简称,可以通过软件来控制其输入和输出。
在开发板管理器中安装 esp 32 板子
安装下面的那个
语法和使用 相当于 c++ //: 单行注释
数据类型的声明 int a = float b = char c = bool d =
C++ void loop () {
// put your main code here, to run repeatedly:
int a ;
float b = 3.14 ;
char c = 'A' ;
bool d = 0 ;
}
变量在程序中也可以赋值或者修改
语句 条件语句 if / else 根据条件是否成立执行不同分支:条件为真执行 if 后的代码块,否则执行 else 后的代码块。
C++ int a = 10 ;
if ( a > 5 ) {
// 条件为真时执行
} else if ( a == 5 ) {
// 另一个分支
} else {
// 条件为假时执行
}
switch 分支语句 根据整型或字符表达式的值跳转到对应的 case 分支,每个分支通常以 break 结束,default 用于处理所有未匹配的情况。
C++ int mode = 1 ;
switch ( mode ) {
case 1 :
// 模式 1
break ;
case 2 :
// 模式 2
break ;
default :
// 其他情况
break ;
}
for 循环 已知循环次数时使用,依次执行初始化、条件判断和更新表达式,条件成立时重复执行循环体。
C++ for ( int i = 0 ; i < 10 ; i ++ ) {
// 循环体,共执行 10 次
}
while 循环 条件为真时反复执行循环体,进入循环前先判断条件,若一开始就不成立则一次也不执行。
C++ int i = 0 ;
while ( i < 10 ) {
// 循环体
i ++ ;
}
do...while 循环 先执行一次循环体,再判断条件是否继续,因此循环体至少会执行一次。
C++ int i = 0 ;
do {
// 循环体
i ++ ;
} while ( i < 10 );
break 与 continue break 立即跳出当前循环或 switch;continue 跳过本次循环中剩余的语句,直接进入下一次循环判断。
C++ for ( int i = 0 ; i < 10 ; i ++ ) {
if ( i == 5 ) break ; // 结束整个循环
if ( i % 2 == 0 ) continue ; // 跳过偶数
// 处理奇数
}
函数 把一段可复用的代码封装成函数,需要指定返回类型、函数名和参数列表,用 return 返回结果;返回类型为 void 表示不返回值。
C++ int add ( int x , int y ) {
return x + y ;
}
void setup () { //没有返回值时的,这个在编写程序时很常见
int sum = add ( 3 , 5 );
}
一些结构 数组 用同一类型的一组连续变量保存多个数据,通过下标(从 0 开始)访问元素,声明时给出长度或初始化列表。
C++ int nums [ 5 ] = { 1 , 2 , 3 , 4 , 5 };
nums [ 0 ] = 10 ; // 访问第一个元素
for ( int i = 0 ; i < 5 ; i ++ ) {
// 遍历数组
}
还有多维的数组:
结构体 用 struct 把多个不同类型的变量组合成一个整体,适合描述一个对象的多个属性,通过 . 访问成员。
C++ struct Point {
int x ;
int y ;
};
Point p = { 1 , 2 };
p . x = 10 ;
指针 指针保存变量的内存地址,用 & 取地址、用 * 解引用,从而访问或修改该地址上的值。
C++ int a = 10 ;
int * p = & a ; // p 指向 a
* p = 20 ; // 通过指针修改 a 的值
类与对象 class 把数据和操作数据的函数封装在一起,通过创建对象来使用;public 成员可在类外访问,private 成员只能在类内部访问。
C++ class LED {
public :
void on () {
// 点亮 LED
}
private :
int pin ;
};
LED led ;
led . on ();
初始的程序: C++ void setup () {
// put your setup code here, to run once:初始化函数(通电复位)
}
void loop () {
// put your main code here, to run repeatedly:setup之后的循环程序,采集数据
int a ;
float b = 3.14 ;
char c = 'A' ;
bool d = 0 ;
}
常用程序 pinMode(pin, mode):用于配置数字引脚的输入或输出模式。pin 是数字引脚的编号,mode 是要设置的模式(输入或输出)。 digitalWrite(pin, value):用于在数字引脚上写入 数字值(HIGH 或 LOW)。pin 是数字引脚的编号,value 是要写入的值。 digitalRead(pin):用于读取 数字引脚上的数字值(HIGH 或 LOW)。pin 是数字引脚的编号。 analogRead(pin):用于读取模拟引脚上的模拟值 (0-1023)。pin 是模拟引脚的编号。 analogWrite(pin, value):用于在支持 PWM 输出的数字引脚上输出模拟值 (0-255)。pin 是数字引脚的编号,value 是要输出的值。 delay(ms):用于在程序中创建暂停(延迟)时间。ms 是要延迟的毫秒数。 Serial.begin(baud):用于初始化串口通信,其中 baud 是波特率。 Serial.println(data):用于将数据打印到串口监视器。data 可以是数字,字符串或其他数据类型。 面包板、杜邦线 面包板
上下的窄条:上下不连通,左右联通 中间部分宽条: 杜邦线
三类:看有没有插头
如图所示,红色标注的部分,表示这个在面包板上时相连的 (竖相连)
连接 使用 5 v 的供电和左侧的 gnd 与电源相连使用红线,gnd 为黑线 然后按图接着 同时点亮多个 led:使用面包板的窄排 ![[ESP32-1792393196454.webp|633]]
点亮 led esp 32 引脚的四种模式: 引脚工作模式 芯片内部接通的模块 引脚上的真实物理电压 变化速度(频率) 典型用途 数字输出/输入(GPIO) GPIO 寄存器 只有 3.3V(高)或 0V(低)两种状态 极慢(按需变化,通常几毫秒到几秒) 点亮 LED 灯、控制继电器、读取按键按下 PWM 脉冲输出 LEDC / MCPWM 定时器 依然只有 3.3V 和 0V,但按固定比例周期性交替闪烁 中高速(通常 50Hz ~ 20,000Hz) 调节 LED 亮度、控制机器人电机转速与舵机角度 模拟输入(ADC) ADC 模数转换器 接收外部 0V ~ 3.3V 之间任意连续电压(如 1.65V) 取决于外部传感器变化速度 读取电池剩余电压、摇杆位置、光线强弱 通信端口(UART/I2C/SPI) 硬件通信控制器 依然只有 3.3V 和 0V,但严格按照编码协议和节拍跳变 极高速(每秒几万次到几千万次) 向电脑打印文字日志、给上位机 Jetson 发传感器数据包
gpio 引脚 负责输出/输入电压,开发板上 d 开头的引脚都是这种引脚
电平:高于某个数值的就是高电平;低于某个数值就是低电平 led 发光二极管,具有单向导电性 长脚为阳极,短脚为阴极(GND)
代码 C++ int led_pin = 12 ; // 定义led引脚
void setup () {
// put your setup code here, to run once:
// 设定引脚为输出模式
pinMode ( led_pin , OUTPUT );
// 点亮led,高电平
digitalWrite ( led_pin , HIGH );
}
void loop () {
// put your main code here, to run repeatedly:
}
然后烧录代码的时候要按住开发板上的 boot 按键
实现闪烁
使用 loop 函数
C++ int led_pin = 12 ; // 定义led引脚
void setup () {
// put your setup code here, to run once:
// 设定引脚为输出模式
pinMode ( led_pin , OUTPUT );
}
void loop () {
// put your main code here, to run repeatedly:
// 点亮led,高电平
digitalWrite ( led_pin , HIGH );
// 延时一秒
delay ( 1000 );
// 熄灭
digitalWrite ( led_pin , LOW );
// 延时1s;
delay ( 1000 );
}
然后按住 boot 键进行烧录
流水灯实验 ![[image.png]]
也可以只使用一个电阻(即阴极都连到一个电阻上)
我们要使用多个 gpio 引脚,使用数组的方式
C++ //定义dpio引脚数组
int pin_list [ 5 ] = { 13 , 12 , 14 , 27 , 26 };
int num = sizeof ( pin_list / sizeof ( pin_list [ 0 ]);
void setup () {
// put your setup code here, to run once:
for ( int i = 0 ; i < num ; i ++ ){
pinMode ( pin_list [ i ], OUTPUT ); //设置为输出的模式
}
}
void loop () {
// put your main code here, to run repeatedly:
// 设为高电平
for ( int i = 0 ; i < num ; i ++ ){
digitalWrite ( pin_list [ i ], HIGH );
delay ( 50 );
}
// 设为低电平
for ( int i = 0 ; i < num ; i ++ ){
digitalWrite ( pin_list [ i ], LOW );
delay ( 50 );
}
}
平移效果:
C++ //定义dpio引脚数组
int pin_list [ 5 ] = { 13 , 12 , 14 , 27 , 26 };
int num = sizeof ( pin_list / sizeof ( pin_list [ 0 ]);
void setup () {
// put your setup code here, to run once:
for ( int i = 0 ; i < num ; i ++ ){
pinMode ( pin_list [ i ], OUTPUT );
}
}
void loop () {
// put your main code here, to run repeatedly:
// 设为平移效果
for ( int i = 0 ; i < num ; i ++ ){
digitalWrite ( pin_list [ i ], HIGH );
if ( i > 0 ) {
digitalWrite ( pin_list [ i -1 ], LOW );
} //解决第一颗时,要熄灭的是最后一颗
else {
digitalWrite ( pin_list [ mun -1 ], LOW );
}
delay ( 50 );
}
}
数码管显示 共阳极数码管:高电平不良(因为另一段接的为高点平) 共阴极数码管 ![[image-1.png]]
判断共阴极还是共阳极 型号 esp 32 进行读取 如果一个输入的引脚,没有接入高或者低电平,就处于悬空 的状态(极易产生波动)
![[image-2.png]]
使用这种方式
图中是 ESP32-S3-WROOM-1 模组的两个引脚:上面的引脚通过一个 10K 电阻接到 +3.3V,叫上拉电阻 ;下面的引脚通过 10K 电阻接到 GND,叫下拉电阻 。
为什么需要 :输入引脚什么都不接时处于“悬空”状态,电压不确定,容易受干扰,读到的值会随机跳变。上拉/下拉就是给引脚一个确定的默认电平。 上拉电阻 :把引脚通过电阻接到电源(+3.3V),没有外部信号时默认读到高电平 。按键一端接 GND、一端接引脚时,按下就读到低电平。 下拉电阻 :把引脚通过电阻接到地(GND),没有外部信号时默认读到低电平 。按键一端接 +3.3V、一端接引脚时,按下就读到高电平。 阻值 :图中 10K 是常见值。阻值越小,上拉/下拉能力越强、抗干扰越好,但静态耗电也越大;阻值越大越省电,但更容易受干扰。 ESP32 的 GPIO 内部也有可配置的上拉/下拉电阻,很多场合可以不外接:
C++ pinMode ( buttonPin , INPUT_PULLUP ); // 启用内部上拉
int state = digitalRead ( buttonPin ); // 未按下为 HIGH,按下为 LOW
实践 C++ const int buttonPin = 8 ; // 定义按钮连接的引脚
void setup () {
Serial . begin ( 9600 ); // 初始化串口通信,波特率 9600
while ( ! Serial ) {} // 等待串口连接建立
pinMode ( buttonPin , INPUT_PULLUP ); // 设置按钮引脚为上拉输入模式
}
void loop () {
int buttonState = digitalRead ( buttonPin ); // 读取按钮当前状态
Serial . println ( buttonState ); // 串口输出按钮状态值
}
不按时为高电平(因为为上拉输入模式,被内部的电阻上拉为高电平,按下按键之后接到 gnd,读取低电平) ![[image-3.png]]
记录按下的次数 C++ const int buttonPin = 8 ;
int lastButtonState = 1 ; // 上一次按钮状态
int currentButtonState ; // 当前按钮状态
int count = 0 ; // 计数器
void setup () {
Serial . begin ( 9600 ); // 初始化串口通信
while ( ! Serial ) {} // 等待串口连接
pinMode ( buttonPin , INPUT_PULLUP ); // 设置按钮引脚为上拉输入
}
void loop () {
currentButtonState = digitalRead ( buttonPin ); // 读取当前按钮状态
if ( lastButtonState == HIGH && currentButtonState == LOW ) {
// 按钮被按下(不是必要的,帮助理解而已)
} else if ( lastButtonState == LOW && currentButtonState == HIGH ) {
// 按钮被释放
count = count + 1 ; // 计数器加 1
Serial . println ( count ); // 串口输出当前计数值
}
lastButtonState = currentButtonState ; // 保存当前按钮状态
}
实际上是看松开的次数: ![[image-4.png]]
但是可能会有抖动的现象出现,加入 delay 的函数;(防止小的高频抖动)
C++ const int buttonPin = 8 ;
int lastButtonState = 1 ; // 上一次按钮状态
int currentButtonState ; // 当前按钮状态
int count = 0 ; // 计数器
void setup () {
Serial . begin ( 9600 ); // 初始化串口通信
while ( ! Serial ) {} // 等待串口连接
pinMode ( buttonPin , INPUT_PULLUP ); // 设置按钮引脚为上拉输入
}
void loop () {
currentButtonState = digitalRead ( buttonPin ); // 读取当前按钮状态
if ( lastButtonState == HIGH && currentButtonState == LOW ) {
// 按钮被按下
} else if ( lastButtonState == LOW && currentButtonState == HIGH ) {
// 按钮被释放
count = count + 1 ; // 计数器加 1
Serial . println ( count ); // 串口输出当前计数值
delay ( 100 ); // 延时 100 毫秒防抖
}
lastButtonState = currentButtonState ; // 保存当前按钮状态
}
两个挑战 ![[image-5.png]]
led 在 gpio 7(设置其为输出的模式),按钮在 gpio 8(上拉输入模式)
1 按下亮起:8 本身是高,按下变成低电平,所以让 7 和 8 的状态相反即可 C++ const int ledPin = 7 ; // LED 连接的引脚号
const int buttonPin = 8 ; // 按钮连接的引脚号
int buttonState ; // 存储按钮状态
void setup () {
pinMode ( ledPin , OUTPUT ); // 设置 LED 引脚为输出模式
pinMode ( buttonPin , INPUT_PULLUP ); // 设置按钮引脚为上拉输入模式
}
void loop () {
buttonState = digitalRead ( buttonPin ); // 读取按钮状态
if ( buttonState == LOW ) { // 按钮按下时(LOW)
digitalWrite ( ledPin , HIGH ); // 点亮 LED
} else { // 按钮未按下时(HIGH)
digitalWrite ( ledPin , LOW ); // 熄灭 LED
}
}
2 按下切换状态(开关):就需要计数了,利用上述的计数代码,计数 +1,切换 7 状态 C++ const int ledPin = 7 ; // LED 连接的引脚号
const int buttonPin = 8 ; // 按钮连接的引脚号
int lastButtonState = HIGH ; // 上一次按钮状态
int ledState = LOW ; // LED 当前状态(LOW=灭,HIGH=亮)
int currentButtonState ; // 当前按钮状态
void setup () {
pinMode ( ledPin , OUTPUT ); // 设置 LED 引脚为输出模式
pinMode ( buttonPin , INPUT_PULLUP ); // 设置按钮引脚为上拉输入模式
}
void loop () {
currentButtonState = digitalRead ( buttonPin ); // 读取当前按钮状态
// 检测按钮从按下变为松开的瞬间
if ( lastButtonState == LOW && currentButtonState == HIGH ) {
ledState = ! ledState ; // 切换 LED 状态(亮变灭,灭变亮)
digitalWrite ( ledPin , ledState ); // 应用新的 LED 状态
delay ( 100 ); // 防抖延时
}
lastButtonState = currentButtonState ; // 保存当前状态,用于下次比较
}
模拟信号部分 ADC:模数转换器(将输入的模拟电压信号转换为离散的信号,对应着来) ![[image-6.png]]
![[image-7.png]]
标注有 adc 字样的引脚才能输入模拟信号
实践 ![[image-8.png|386]]
C++ const int potentiometerPin = 7 ; // 定义电位器连接的引脚
void setup () {
Serial . begin ( 9600 ); // 初始化串口通信,波特率 9600
}
void loop () {
int analogValue = analogRead ( potentiometerPin ); // 读取电位器模拟值 (0-4095),不需要初始化
int analogVolts = analogReadMilliVolts ( potentiometerPin ); // 读取引脚上的电压值,单位是毫伏 (mV)
// 打印第一个标签和数值
Serial . print ( "ADC_Value:" );
Serial . print ( analogValue );
// 打印分隔符
Serial . print ( "," );
// 打印第二个标签和数值,并用 println() 结束
Serial . print ( "Voltage_mV:" ); //打印之后不换行
Serial . println ( analogVolts ); //打印之后自动添加换行符
delay ( 100 ); // 延时 0.1 秒,避免串口刷屏太快
}
解析代码 图中电位器是一个可变的分压器:两个外侧引脚分别接 3.3V 和 GND(红、黑线),中间的滑动端接到 GPIO7(紫线)。转动旋钮时,滑动端在电阻上的位置改变,输出到 GPIO7 的电压就在 0~3.3V 之间连续变化,这就是模拟信号 。
ESP32 的引脚不能直接“读懂”电压,需要由 ADC(模数转换器)采样:ADC 把 0~3.3V 的电压量化成 0~4095 的数字量(12 位),所以:
analogRead(pin) 返回 ADC 转换后的数字量 (0~4095); analogReadMilliVolts(pin) 把同一个采样结果换算成电压值 (毫伏),方便直接读数; 两者读的是同一个引脚、同一个电压,只是一个给原始数字量,一个给换算后的电压,所以看起来像同时读到了“数字信号”和“模拟信号”。 注意:只有标注 ADC 的引脚才能这样读,普通数字引脚只能用 digitalRead() 读 HIGH/LOW。Serial.begin(9600) 只是把结果输出到串口监视器或绘图仪。
绘图仪 绘图仪能够识别出打印出来的数据格式进行绘图
![[image-9.png]]
现在我们的测量范围为 0~3100 mv
对噪声的滤波 接入电容实现滤波 ![[image-10.png]]
软件滤波:多次采样,去除最大最小值,取得平均值作为滤波
解释:
对应前面 image-10 的接线:
电位器的两个外脚,一端接 3.3V (红线),另一端接 GND (黑线); 中间的滑动端(紫线)接 GPIO7 ,同时接 100nF 电容 的一端; 电容的另一端接 GND 。 原理简要说明:
电位器是一个分压器,转动旋钮改变滑动端的位置,GPIO7 上的电压在 0~3.3V 之间变化,ADC 再把它转换成 0~4095 的数字量。 100nF 电容与电位器的等效源电阻组成 RC 低通滤波器 ,把高频干扰和毛刺滤掉,并在 ADC 采样瞬间提供电荷,使读数更稳定。 截止频率约为 f = 1 / (2πRC)。10kΩ 电位器在中点位置时等效电阻最大,约 2.5kΩ,对应 f ≈ 1 / (2π × 2500 × 100nF) ≈ 640Hz;越靠近两端,等效电阻越小,截止频率越高。 电容只滤除交流波动,不改变直流分压值,所以不会影响 analogRead 测到的实际电压;代价只是响应变慢,而旋钮转动很慢,基本没有影响。 陶瓷电容无极性,两端可以互换,耐压选 10V 以上即可。注意它是接在滑动端与 GND 之间;如果接在 3.3V 与 GND 之间,那是电源去耦,不作用于 ADC 信号。 脉冲宽度调制 PWM:脉冲宽度调制
控制占空比 (高电平时间占总时间的比例)来调节 ![[image-11.png]] 通过占空比控制平均电压
编程使用方式 analogWrite : 快捷 ledc api:更加丰富(可以精确控制频率和分辨率) ![[image-12.png|453]] analogWrite C++ const int ledPin = 7 ; // LED 连接的引脚号
void setup () {
}
void loop () {
// 亮度增加 (占空比值从 0 到 255)
for ( int dutyCycle = 0 ; dutyCycle <= 255 ; dutyCycle ++ ) {
analogWrite ( ledPin , dutyCycle ); // 设置 PWM 占空比值
delay ( 10 ); // 延时以控制变化速度
}
// 亮度减少 (占空比值从 255 到 0)
for ( int dutyCycle = 255 ; dutyCycle >= 0 ; dutyCycle -- ) {
analogWrite ( ledPin , dutyCycle ); // 设置 PWM 占空比值
delay ( 10 ); // 延时以控制变化速度
}
}
使用的就是:analogWrite 函数,控制 ledPin(使用的就是驼峰命名) 的占空比,使用两个 for 循环实现了呼吸灯的效果
ledc api 实现 C++ const int ledPin = 7 ; // LED 连接的 GPIO 引脚
const int frequency = 5000 ; // PWM 频率 5kHz
const int resolution = 8 ; // PWM 分辨率 8 位(0-255)
const int ledChannel = 0 ; // PWM 通道号
void setup () {
// 初始化 LED PWM 功能
ledcAttach ( ledPin , frequency , resolution );
// 如果你想指定通道
// ledcAttachChannel(ledPin, frequency,resolution,ledChannel)
}
void loop () {
// 逐渐增加占空比,LED 变亮
for ( int dutyCycle = 0 ; dutyCycle <= 255 ; dutyCycle ++ ) {
ledcWrite ( ledPin , dutyCycle ); // 设置 PWM 占空比值
delay ( 10 ); // 延时 10ms,控制变化速度
}
// 逐渐减少占空比,LED 变暗
for ( int dutyCycle = 255 ; dutyCycle >= 0 ; dutyCycle -- ) {
ledcWrite ( ledPin , dutyCycle ); // 设置 PWM 占空比值
delay ( 10 ); // 延时 10ms,控制变化速度
}
}
![[image-13.png|403]]
练习 使用电位器控制灯的亮度
![[image-14.png|328]]
C++ const int ledPin = 7 ; // LED 连接的引脚
const int potentiometerPin = 8 ; // 电位器连接的引脚
int potentiometerValue ; // 存储电位器读取值
int brightness ; // 存储映射后的亮度值
void setup () {
}
void loop () {
// 1. 读取电位器的模拟值 (范围 0-4095)
potentiometerValue = analogRead ( potentiometerPin );
// 2. 将 ADC 读数映射到 PWM 的范围 (0-255)
brightness = map ( potentiometerValue , 0 , 4095 , 0 , 255 );
// 3. 用映射后的值设置 LED 亮度
analogWrite ( ledPin , brightness );
delay ( 20 );
}
对照前面 image-14 的接线:
电位器的两个外脚:一端接 3.3V ,另一端接 GND (红线、黑线),组成一个分压器; 中间的滑动端是输出:一路接 ESP32 的模拟输入引脚 (代码里的 potentiometerPin,可以用 analogRead 读出电压),另一路经 330Ω 限流电阻 接 LED 正极 ,LED 负极接 GND ; 转动旋钮,滑动端的电压在 0~3.3V 之间变化,LED 的亮度也随之变化。 简要说明:
电位器把 3.3V 分成两段,滑动端电压约为 V = 3.3V × R下 / (R上 + R下),旋钮位置改变两段电阻的比例,所以电压可以连续调节。 LED 的正向压降约为 2V,滑动端电压要高于这个值才会明显发光,因此亮度主要在电压较高的一段区间内变化,转到低电压端时 LED 会熄灭。 330Ω 是限流电阻,把 LED 电流限制在几毫安以内,防止烧坏 LED;它不负责“调压”,亮度变化来自滑动端电压的变化。 LED 有极性:长脚(正极)接 330Ω 一侧,短脚(负极)接 GND ,接反了不会亮。 照片里是“电位器直接调光”的接法;如果按上面的示例代码用 ADC + PWM 调光,则把 LED 改接到 ledPin(示例为 GPIO7),把电位器滑动端接到 potentiometerPin(示例为 GPIO8),两者分开接。 UART 串行通信 介绍 两个核心的线: TX:发送数据 RX:用于接收数据 ![[image-15.png]] 设备可以同时进行发送和接收,互不干扰 并且两者还异步:无需始终信号线 所以必须约定好相同的通信参数 传输速度(波特率)和数据格式 esp 中的这个 有多个 uart serial
串口监视器控制 led 通过电脑的串口发送指令控制连接的 LED 灯 ![[image-16.png|411]]
C++ const int ledPin = 7 ; // 定义 LED 连接的引脚
void setup () {
pinMode ( ledPin , OUTPUT ); // 设置 LED 引脚为输出模式
Serial . begin ( 115200 ); // 初始化串口通信,波特率 115200
while ( ! Serial ) {}; // 等待串口准备好
}
void loop () {
if ( Serial . available () > 0 ) { // 如果串口收到数据
String msg = Serial . readStringUntil ( '\n' ); // 读取一行输入(以换行结束)
msg . trim (); // 去除首尾占用空间但不可见的字符,比如空格和换行符
if ( msg == "on" ) {
// 如果输入为"on", 点亮 LED
digitalWrite ( ledPin , HIGH );
Serial . println ( "LED 已打开" );
} else if ( msg == "off" ) {
// 如果输入为"off", 关闭 LED
digitalWrite ( ledPin , LOW );
Serial . println ( "LED 已关闭" ); //向串口监视器发送反馈
} else {
Serial . println ( "请输入 'on' 或 'off'" ); // 提示有效输入
}
}
}
![[image-17.png]]
esp 32 之间串口通信 ![[image-18.png|500]]
有两份代码:
发送端:A C++ #define UART1_RX_PIN 11 // 定义 UART1 的接收引脚(RX)
#define UART1_TX_PIN 12 // 定义 UART1 的发送引脚(TX)
const int buttonPin = 7 ; // 按钮连接的引脚
int lastButtonState = LOW ; // 初始状态为未按下
void setup () {
// 启动默认串口,用于调试输出到电脑
Serial . begin ( 115200 );
// while(!Serial){};
// 启动 Serial1,并指定 RX 和 TX 引脚,用于设备间通信
Serial1 . begin ( 9600 , SERIAL_8N1 , UART1_RX_PIN , UART1_TX_PIN );
pinMode ( buttonPin , INPUT_PULLUP ); // 配置按钮引脚为上拉输入模式
Serial . println ( "Sender Ready. Press the button." );
}
void loop () {
int currentButtonState = digitalRead ( buttonPin );
// 如果按钮状态发生变化
if ( currentButtonState != lastButtonState ) {
if ( currentButtonState == HIGH ) {
Serial1 . write ( '0' ); // 按钮松开时发送'0'
Serial . println ( "Sent: 0 (Button Released)" );
} else {
Serial1 . write ( '1' ); // 按钮按下时发送'1'
Serial . println ( "Sent: 1 (Button Pressed)" );
}
lastButtonState = currentButtonState ; // 更新按钮状态
delay ( 50 ); // 简单的防抖动
}
}
接收端 B C++ #define UART1_RX_PIN 1 // 定义 UART1 的接收引脚(RX)
#define UART1_TX_PIN 2 // 定义 UART1 的发送引脚(TX)
const int ledPin = 7 ;
void setup () {
// 启动默认串口,用于调试输出到电脑
Serial . begin ( 115200 );
// while(!Serial){};
// 启动 Serial1,并指定 RX 和 TX 引脚,用于设备间通信
Serial1 . begin ( 9600 , SERIAL_8N1 , UART1_RX_PIN , UART1_TX_PIN );
pinMode ( ledPin , OUTPUT ); // 配置 LED 引脚为输出模式
Serial . println ( "Receiver Ready. Waiting for commands..." );
}
void loop () {
// 检查是否从 UART1 串口接收到数据
if ( Serial1 . available ()) {
char command = Serial1 . read (); // 读取一个字节(字符)
// 根据接收到的命令控制 LED
if ( command == '1' ) {
// 接收到'1'时点亮 LED
digitalWrite ( ledPin , HIGH );
Serial . println ( "Received: 1 -> LED ON" );
} else if ( command == '0' ) {
// 接收到'0'时熄灭 LED
digitalWrite ( ledPin , LOW );
Serial . println ( "Received: 0 -> LED OFF" );
}
}
}
![[image-19.png]]
双方都初始化 serial 1 进行板间通信:
C++ // 启动 Serial1,并指定 RX 和 TX 引脚,用于设备间通信
Serial1 . begin ( 9600 , SERIAL_8N1 , UART1_RX_PIN , UART1_TX_PIN );
I 2 C 通信 介绍 I 2 C 协议 I 2 C 总线:一种广泛使用的两线制串行总线 ![[image-20.png|812]]
主设备通过设备的地址与从设备进行通信
主设备发出信息时会广播一个地址,从设备中只有地址符合的设备会做出响应
esp 32 上使用这个 wire :I 2 C 0 wire1 :I 2 C 1
两路独立的 i 2 c 通信
i 2 c scanner 首要任务就是确定其地址
![[image-21.png|652]]
C++ #include <Wire.h>
#define SDA_PIN 1 // 可以选择任何可用的 GPIO,与实际接线对应
#define SCL_PIN 2 // 可以选择任何可用的 GPIO,与实际接线对应
void setup () {
Serial . begin ( 9600 );
Wire . begin ( SDA_PIN , SCL_PIN );
}
void loop () {
byte error , address ;
int nDevices = 0 ;
delay ( 5000 );
Serial . println ( "Scanning for I2C devices ..." );
for ( address = 0x01 ; address < 0x7f ; address ++ ) {
Wire . beginTransmission ( address );
error = Wire . endTransmission ();
if ( error == 0 ) {
Serial . printf ( "I2C device found at address 0x%02X \n " , address );
nDevices ++ ;
} else if ( error != 2 ) {
Serial . printf ( "Error %d at address 0x%02X \n " , error , address );
}
}
if ( nDevices == 0 ) {
Serial . println ( "No I2C devices found" );
}
}
![[image-22.png|634]]
与模块进行交互 与模块交互时,厂家有自己的库,所以我们要做的是让其和我们指定的 esp i 2 c 引脚通信
安装好 ssd 1327 这个我们需要的库 文件——>示例——>第三方示例——>打开就是我们的这个了 ![[image-23.png]]
C++ // I2C
Adafruit_SSD1327 display ( 128 , 128 , & Wire , OLED_RESET , 1000000 );
通过传入 wire 对象使用 i 2 c
怎么使用呢
定义两个引脚:
C++ # define SDA_PIN 1
# define SCL_PIN 2
在 setup 函数中调用 wire.begin 指定引脚
C++ Wire . begin ( SDA_PIN , SCL_PIN );
之后编译上传代码就行
![[image-24.png]]
esp 32 之间使用 i 2 c 通信 ![[image-25.png]]
主设备读取从设备数据 C++ #include <Wire.h>
#define SDA 1 // 定义 SDA 引脚
#define SCL 2 // 定义 SCL 引脚
void setup () {
Serial . begin ( 9600 );
Wire . begin ( SDA , SCL , 100000 ); // 初始化 I2C 主设备,频率 100 kHz
}
void loop () {
int dataLength = Wire . requestFrom ( 8 , 5 ); // 向地址为 8 的从设备请求 5 个字节,返回实际收到的字节数
Serial . print ( "收到 " + String ( dataLength ) + " 个字符:" );
while ( Wire . available ()) { // 逐个读取接收到的数据
char c = Wire . read ();
Serial . print ( c );
}
Serial . println ();
delay ( 500 );
}
C++ #include <Wire.h>
#define SDA 12 // 定义 SDA 引脚
#define SCL 11 // 定义 SCL 引脚
void setup () {
Wire . begin ( 8 , SDA , SCL , 100000 ); // 初始化 I2C 从设备,地址为 8,频率 100 kHz
Wire . onRequest ( requestEvent ); // 注册请求事件回调函数
}
void loop () {
delay ( 100 );
}
// 当主设备请求数据时自动调用此函数
void requestEvent () {
Wire . write (( const uint8_t * ) "hello" , 5 ); // 向主设备发送 5 个字节,内容为 “hello”
}
回调函数 普通函数是“我调用它”;回调是“我把它交出去,别人在合适的时候调用它”。执行几次由调用它的循环或事件源决定,函数自己并不会“不断执行”。
主设备发送数据给从设备 C++ #include <Wire.h>
#define SDA 1 // 定义 SDA 引脚
#define SCL 2 // 定义 SCL 引脚
byte x = 0 ; // 定义计数器变量
void setup () {
Wire . begin ( SDA , SCL , 100000 ); // 初始化 I2C 主设备,频率 100kHz
}
void loop () {
Wire . beginTransmission ( 8 ); // 开始向地址为 8 的从设备发送数据
Wire . write (( const uint8_t * ) "x is " , 5 ); // 发送字符串 "x is "(5 个字节)
Wire . write ( x ); // 发送数字 x
Wire . endTransmission (); // 结束传输
x ++ ; // 计数器递增
delay ( 500 ); // 延时 500 毫秒
}
C++ #include <Wire.h>
#define SDA 12 // 定义 SDA 引脚
#define SCL 11 // 定义 SCL 引脚
void setup () {
Wire . begin ( 8 , SDA , SCL , 100000 ); // 初始化 I2C 从设备,地址为 8,频率 100kHz
Wire . onReceive ( receiveEvent ); // 注册接收事件回调函数
Serial . begin ( 9600 ); // 初始化串口通信
}
void loop () {
delay ( 100 );
}
// 当收到主设备数据时自动调用此函数
void receiveEvent ( int len ) {
while ( Wire . available () > 1 ) { // 读取除最后一个字节外的所有数据(字符串部分)
char c = Wire . read ();
Serial . print ( c );
}
int x = Wire . read (); // 读取最后一个字节(数字)
Serial . println ( x ); // 换行打印数字
}
回调函数:
C++ #include <iostream>
using namespace std ;
// 普通函数:由我的代码直接调用
void ordinaryFunction () {
cout << "普通函数:被 main 里的代码直接调用" << endl ;
}
// 回调函数:我不直接调用它,只是把它的名字交给别人
void onButtonPressed () {
cout << "回调函数:被事件源在“按钮按下”时调用" << endl ;
}
// 模拟一个事件源(库),参数是函数指针
void listenButton ( int pressCount , void ( * callback )()) {
for ( int i = 1 ; i <= pressCount ; i ++ ) {
cout << " 事件源:检测到第 " << i << " 次按下" << endl ;
callback (); // 真正调用回调函数的地方
}
}
int main () {
ordinaryFunction (); // 直接调用
ordinaryFunction (); // 想再执行一次,就得再写一次
cout << "---- 以下交给事件源 ----" << endl ;
listenButton ( 3 , onButtonPressed ); // 只登记一次,事件源触发 3 次
return 0 ;
}
SPI 通信 通常有更高的传输速度,通常用在快速的信息交换的场景
采用主从架构进行通信
![[png/新旧术语对应关系.png]]
我们使用 soih 库来实现这样的功能
驱动显示屏 ![[image-26.png|665]]
代码 C++ #include <SPI.h>
#include <Adafruit_SSD1327.h>
#define OLED_SCK 13 // 时钟线
#define OLED_MOSI 11 // 数据输出线
#define OLED_CS 10 // 片选线
#define OLED_DC 8 // 数据/命令选择线
#define OLED_RESET -1 // 复位引脚(未使用)
// 创建显示器对象
Adafruit_SSD1327 display ( 128 , 128 , & SPI , OLED_DC , OLED_RESET , OLED_CS );
void setup () {
Serial . begin ( 9600 );
// 初始化 SPI 总线
SPI . begin ( OLED_SCK , -1 , OLED_MOSI , OLED_CS );
Serial . println ( "SSD1327 OLED test" );
// 初始化显示器
if ( ! display . begin ()) {
Serial . println ( "Unable to initialize OLED" );
while ( 1 ) yield ();
}
// 显示设置
display . clearDisplay ();
display . setRotation ( 3 );
display . setTextSize ( 2 );
display . setTextColor ( SSD1327_WHITE );
// 显示文本
display . setCursor ( 10 , 10 );
display . println ( "Hello," );
display . setCursor ( 40 , 30 );
display . setTextColor ( SSD1327_BLACK , SSD1327_WHITE );
display . println ( " World!" );
display . display ();
display . setCursor ( 15 , 60 );
display . setTextColor ( SSD1327_WHITE );
display . println ( "SPI TEST" );
display . display ();
delay ( 1000 );
}
void loop () {
}
为什么没有 MISO 因为是单向通信的场景,此时的 MISO 可以省略
使用多个 SPI C++ #include <SPI.h>
SPIClass hspi ( HSPI );
void setup () {
// 初始化 HSPI 总线,并指定其引脚
hspi . begin ( HSPI_SCLK , HSPI_MISO , HSPI_MOSI , HSPI_CS );
// ...
}
void loop () {
// ...
}
使用多个 spi 的方法
wifi 的基础用法 功能 STA 模式:连接 wifi AP 模式:会自己开个热点 AP+STA 复合模式:同时作为客户端和接入点 扫描周围的 wifi 网络 C++ #include "WiFi.h"
void setup () {
Serial . begin ( 115200 );
// 将 Wi-Fi 设置为站点模式,并断开任何已有的连接
WiFi . mode ( WIFI_STA );
WiFi . disconnect ();
delay ( 100 );
Serial . println ( "Setup done" );
}
void loop () {
Serial . println ( "Scan start" );
// WiFi.scanNetworks() 将返回找到的网络数量。
int n = WiFi . scanNetworks ();
Serial . println ( "Scan done" );
if ( n == 0 ) {
Serial . println ( "no networks found" );
} else {
Serial . print ( n );
Serial . println ( " networks found" );
Serial . println ( "Nr | SSID | RSSI | CH | Encryption" );
for ( int i = 0 ; i < n ; ++ i ) {
// 打印找到的每个网络的 SSID 和 RSSI
Serial . printf ( "%2d" , i + 1 );
Serial . print ( " | " );
Serial . printf ( "%-32.32s" , WiFi . SSID ( i ). c_str ());
Serial . print ( " | " );
Serial . printf ( "%4ld" , WiFi . RSSI ( i ));
Serial . print ( " | " );
Serial . printf ( "%2ld" , WiFi . channel ( i ));
Serial . print ( " | " );
switch ( WiFi . encryptionType ( i )) {
case WIFI_AUTH_OPEN : Serial . print ( "open" ); break ;
case WIFI_AUTH_WEP : Serial . print ( "WEP" ); break ;
case WIFI_AUTH_WPA_PSK : Serial . print ( "WPA" ); break ;
case WIFI_AUTH_WPA2_PSK : Serial . print ( "WPA2" ); break ;
case WIFI_AUTH_WPA_WPA2_PSK : Serial . print ( "WPA+WPA2" ); break ;
case WIFI_AUTH_WPA2_ENTERPRISE : Serial . print ( "WPA2-EAP" ); break ;
case WIFI_AUTH_WPA3_PSK : Serial . print ( "WPA3" ); break ;
case WIFI_AUTH_WPA2_WPA3_PSK : Serial . print ( "WPA2+WPA3" ); break ;
case WIFI_AUTH_WAPI_PSK : Serial . print ( "WAPI" ); break ;
default : Serial . print ( "unknown" );
}
Serial . println ();
delay ( 10 );
}
}
Serial . println ( "" );
// 删除扫描结果以释放内存
WiFi . scanDelete ();
// 在再次扫描之前等待一下。
delay ( 5000 );
}
连接指定的 wifi C++ #include <WiFi.h>
// 请替换为你的 Wi-Fi 网络信息
const char * ssid = "yourssid" ; // 替换为你的 Wi-Fi 名称
const char * password = "yourpasswd" ; // 替换为你的 Wi-Fi 密码
void setup () {
Serial . begin ( 115200 );
delay ( 10 );
Serial . print ( "Connecting to " );
Serial . println ( ssid );
WiFi . mode ( WIFI_STA );
WiFi . begin ( ssid , password );
while ( WiFi . status () != WL_CONNECTED ) {
delay ( 500 );
Serial . print ( "." );
}
Serial . println ( "" );
Serial . println ( "WiFi connected." );
Serial . println ( "IP address: " );
Serial . println ( WiFi . localIP ());
}
void loop () {
}
支持频段的 wifi
管理不同的 wifi C++ #include <WiFi.h>
#include <WiFiMulti.h>
WiFiMulti wifiMulti ;
void setup () {
Serial . begin ( 115200 );
delay ( 10 );
// 添加多个候选 Wi-Fi 网络
wifiMulti . addAP ( "ssid_from_AP_1" , "your_password_for_AP_1" );
wifiMulti . addAP ( "ssid_from_AP_2" , "your_password_for_AP_2" );
wifiMulti . addAP ( "ssid_from_AP_3" , "your_password_for_AP_3" );
Serial . println ( "Connecting Wifi..." );
if ( wifiMulti . run () == WL_CONNECTED ) {
Serial . println ( "" );
Serial . println ( "WiFi connected" );
Serial . print ( "SSID: " );
Serial . println ( WiFi . SSID ());
Serial . print ( "IP address: " );
Serial . println ( WiFi . localIP ());
}
}
void loop () {
// 检查连接状态,如果断开则尝试重连
if ( wifiMulti . run () != WL_CONNECTED ) {
Serial . println ( "WiFi not connected!" );
delay ( 1000 );
}
}
使用 wifiMulti.run():函数:核心函数。它会扫描、选择信号最强的可用网络并尝试连接。返回当前的连接状态,类似 WiFi.status()。在 loop 中持续调用可实现断线自动重连。
创建 wifi 热点 C++ #include <WiFi.h>
const char * ssid = "ESP32-S3-TEST" ; // 设置热点名称
const char * password = "12345678" ; // 设置热点密码(至少 8 位)
void setup () {
Serial . begin ( 115200 );
Serial . println ();
Serial . println ( "Configuring access point..." );
// 设置 Wi-Fi 事件回调函数
WiFi . onEvent ( WiFiStationConnected , WiFiEvent_t :: ARDUINO_EVENT_WIFI_AP_STACONNECTED );
WiFi . onEvent ( WiFiStationGotIP , WiFiEvent_t :: ARDUINO_EVENT_WIFI_AP_STAIPASSIGNED );
WiFi . onEvent ( WiFiStationDisconnected , WiFiEvent_t :: ARDUINO_EVENT_WIFI_AP_STADISCONNECTED );
// 创建 Wi-Fi 热点
if ( ! WiFi . softAP ( ssid , password )) {
Serial . println ( "Soft AP creation failed." );
while ( 1 )
;
}
IPAddress myIP = WiFi . softAPIP ();
Serial . print ( "AP IP address: " );
Serial . println ( myIP );
}
void loop () {
}
// 设备连接事件
void WiFiStationConnected ( WiFiEvent_t event , WiFiEventInfo_t info ) {
Serial . print ( "Device connected, MAC: " );
Serial . println ( macToString ( info . wifi_ap_staconnected . mac ));
}
// 设备获取 IP 事件
void WiFiStationGotIP ( WiFiEvent_t event , WiFiEventInfo_t info ) {
Serial . print ( "Device IP address: " );
Serial . println ( IPAddress ( info . got_ip . ip_info . ip . addr ));
}
// 设备断开连接事件
void WiFiStationDisconnected ( WiFiEvent_t event , WiFiEventInfo_t info ) {
Serial . print ( "Device disconnected, MAC: " );
Serial . println ( macToString ( info . wifi_ap_stadisconnected . mac ));
}
// MAC 地址转换为字符串辅助函数
String macToString ( const uint8_t * mac ) {
char buf [ 18 ];
snprintf ( buf , sizeof ( buf ), "%02x:%02x:%02x:%02x:%02x:%02x" ,
mac [ 0 ], mac [ 1 ], mac [ 2 ], mac [ 3 ], mac [ 4 ], mac [ 5 ]);
return String ( buf );
}
使用回调函数的方式比在 loop 中查询状态的方式更加高效
配置静态 IP 在特定应用场景下,为 ESP 32 设置一个固定的 IP 地址(而非通过 DHCP 动态获取)是一种常见需求,便于设备被稳定访问。
STA 模式 C++ #include <WiFi.h>
const char * ssid = "Maker" ; // Wi-Fi 名称
const char * password = "12345678" ; // Wi-Fi 密码
// 设置静态 IP 地址、网关和子网掩码
// 根据你的局域网配置进行修改
IPAddress ip ( 192 , 168 , 137 , 100 ); // 设定静态 IP 地址
IPAddress gateway ( 192 , 168 , 137 , 1 ); // 设定网关
IPAddress subnet ( 255 , 255 , 255 , 0 ); // 设定子网掩码
void setup () {
Serial . begin ( 115200 );
delay ( 10 );
WiFi . mode ( WIFI_STA );
// 在连接之前配置静态 IP,必须在 WiFi.begin() 之前调用
WiFi . config ( ip , gateway , subnet );
Serial . print ( "Connecting to " );
Serial . println ( ssid );
WiFi . begin ( ssid , password );
while ( WiFi . status () != WL_CONNECTED ) {
delay ( 500 );
Serial . print ( "." );
}
Serial . println ( "" );
Serial . println ( "WiFi connected." );
Serial . println ( "IP address: " );
Serial . println ( WiFi . localIP ());
}
void loop () {
}
AP 模式 C++ #include <WiFi.h>
const char * ssid = "ESP32S3-TEST" ; // 设置热点名称
const char * password = "12345678" ; // 设置热点密码(至少 8 位)
IPAddress ip ( 192 , 168 , 5 , 1 ); // 设定静态 IP 地址
IPAddress gateway ( 192 , 168 , 5 , 1 ); // 设定网关
IPAddress subnet ( 255 , 255 , 255 , 0 ); // 设定子网掩码
void setup () {
Serial . begin ( 115200 );
Serial . println ();
Serial . println ( "Configuring access point..." );
// 设置 Wi-Fi 事件回调函数
WiFi . onEvent ( WiFiStationConnected , WiFiEvent_t :: ARDUINO_EVENT_WIFI_AP_STACONNECTED );
WiFi . onEvent ( WiFiStationGotIP , WiFiEvent_t :: ARDUINO_EVENT_WIFI_AP_STAIPASSIGNED );
WiFi . onEvent ( WiFiStationDisconnected , WiFiEvent_t :: ARDUINO_EVENT_WIFI_AP_STADISCONNECTED );
// 在 WiFi.softAP() 创建热点之前调用
WiFi . softAPConfig ( ip , gateway , subnet );
// 创建 Wi-Fi 热点
if ( ! WiFi . softAP ( ssid , password )) {
Serial . println ( "Soft AP creation failed." );
while ( 1 )
;
}
Serial . print ( "AP IP address: " );
Serial . println ( WiFi . softAPIP ());
}
void loop () {
}
// 设备连接事件
void WiFiStationConnected ( WiFiEvent_t event , WiFiEventInfo_t info ) {
Serial . print ( "Device connected, MAC: " );
Serial . println ( macToString ( info . wifi_ap_staconnected . mac ));
}
// 设备获取 IP 事件
void WiFiStationGotIP ( WiFiEvent_t event , WiFiEventInfo_t info ) {
Serial . print ( "Device IP address: " );
Serial . println ( IPAddress ( info . got_ip . ip_info . ip . addr ));
}
// 设备断开连接事件
void WiFiStationDisconnected ( WiFiEvent_t event , WiFiEventInfo_t info ) {
Serial . print ( "Device disconnected, MAC: " );
Serial . println ( macToString ( info . wifi_ap_stadisconnected . mac ));
}
// MAC 地址转换为字符串辅助函数
String macToString ( const uint8_t * mac ) {
char buf [ 18 ];
snprintf ( buf , sizeof ( buf ), "%02x:%02x:%02x:%02x:%02x:%02x" ,
mac [ 0 ], mac [ 1 ], mac [ 2 ], mac [ 3 ], mac [ 4 ], mac [ 5 ]);
return String ( buf );
}
将 esp 32 设置为网页服务器 基础网页服务(sTA 模式) C++ #include <WiFi.h>
#include <WebServer.h>
const char * ssid = "Maker" ; // 替换为你的 Wi-Fi 名称
const char * password = "12345678" ; // 替换为你的 Wi-Fi 密码
WebServer server ( 80 );
void setup () {
Serial . begin ( 115200 );
delay ( 10 );
// 连接 WiFi 网络
Serial . print ( "Connecting to " );
Serial . println ( ssid );
WiFi . begin ( ssid , password );
// 等待连接成功
while ( WiFi . status () != WL_CONNECTED ) {
delay ( 500 );
Serial . print ( "." );
}
Serial . println ();
Serial . println ( "WiFi connected." );
Serial . println ( "IP address: " );
Serial . println ( WiFi . localIP ());
// 配置路由和启动服务器
server . on ( "/" , handleRoot );
server . begin ();
}
void loop () {
server . handleClient ();
}
// 处理根路径请求
void handleRoot () {
server . send ( 200 , "text/html" , generateHTML ());
}
// 生成 HTML 页面内容
String generateHTML () {
String htmlContent = "<!DOCTYPE html> <html> \n " ;
htmlContent += "<head><meta charset= \" utf-8 \" name= \" viewport \" content= \" width=device-width \" > \n " ;
htmlContent += "<title>ESP32S3 Test</title> \n " ;
htmlContent += "</head><body> \n " ;
htmlContent += "<h1>Hello World!</h1> \n " ;
htmlContent += "<p>Hello from ESP32</p> \n " ;
htmlContent += "</body> \n " ;
htmlContent += "</html> \n " ;
return htmlContent ;
}
通过网页控制 led(STA 模式) ![[image-27.png|288]]
C++ #include <WiFi.h>
#include <WebServer.h>
const int ledPin = 7 ;
const char * ssid = "Maker" ; // 替换为你的 Wi-Fi 名称
const char * password = "12345678" ; // 替换为你的 Wi-Fi 密码
WebServer server ( 80 );
void setup () {
pinMode ( ledPin , OUTPUT );
Serial . begin ( 115200 );
// 连接 WiFi 网络
Serial . print ( "Connecting to " );
Serial . println ( ssid );
WiFi . begin ( ssid , password );
// 等待连接成功
while ( WiFi . status () != WL_CONNECTED ) {
delay ( 500 );
Serial . print ( "." );
}
Serial . println ();
Serial . println ( "WiFi connected." );
Serial . println ( "IP address: " );
Serial . println ( WiFi . localIP ());
// 配置路由和启动服务器
server . on ( "/" , handleRoot );
server . on ( "/ledon" , handleLedOn );
server . on ( "/ledoff" , handleLedOff );
server . begin ();
}
void loop () {
server . handleClient ();
}
// 处理根路径请求
void handleRoot () {
server . send ( 200 , "text/html" , generateHTML ( digitalRead ( ledPin )));
}
// 开启 LED
void handleLedOn () {
digitalWrite ( ledPin , HIGH );
server . send ( 200 , "text/html" , generateHTML ( true ));
}
// 关闭 LED
void handleLedOff () {
digitalWrite ( ledPin , LOW );
server . send ( 200 , "text/html" , generateHTML ( false ));
}
// 生成 HTML 页面内容
String generateHTML ( bool ledState ) {
String htmlContent = "<!DOCTYPE html> <html> \n " ;
htmlContent += "<head><meta charset= \" utf-8 \" name= \" viewport \" content= \" width=device-width \" > \n " ;
htmlContent += "<title>ESP32S3 Test</title> \n " ;
htmlContent += "</head><body> \n " ;
htmlContent += "<h1>Hello World!</h1> \n " ;
if ( ledState ) {
htmlContent += "<p>LED Status: ON</p>" ;
htmlContent += "<a href= \" /ledoff \" >Turn off the LED</a> \n " ;
} else {
htmlContent += "<p>LED Status: OFF</p>" ;
htmlContent += "<a href= \" /ledon \" >Turn on the LED</a> \n " ;
}
htmlContent += "</body> \n " ;
htmlContent += "</html> \n " ;
return htmlContent ;
}
通过网页控制 LED(AP 模式) 让 esp 32 创建热点
C++ #include <WiFi.h>
#include <WebServer.h>
const int ledPin = 7 ;
const char * ssid = "ESP32S3-TEST" ; // 设置热点名称
const char * password = "12345678" ; // 设置热点密码(至少 8 位)
WebServer server ( 80 );
String generateHTML ( bool ledState = false );
void setup () {
pinMode ( ledPin , OUTPUT );
Serial . begin ( 115200 );
// 创建 Wi-Fi 热点
Serial . println ( "Configuring access point..." );
if ( ! WiFi . softAP ( ssid , password )) {
Serial . println ( "Soft AP creation failed." );
while ( 1 )
;
}
IPAddress myIP = WiFi . softAPIP ();
Serial . print ( "AP IP address: " );
Serial . println ( myIP );
// 配置路由和启动服务器
server . on ( "/" , handleRoot );
server . on ( "/ledon" , handleLedOn );
server . on ( "/ledoff" , handleLedOff );
server . begin ();
}
void loop () {
server . handleClient ();
}
// 处理根路径请求
void handleRoot () {
server . send ( 200 , "text/html" , generateHTML ( digitalRead ( ledPin )));
}
// 开启 LED
void handleLedOn () {
digitalWrite ( ledPin , HIGH );
server . send ( 200 , "text/html" , generateHTML ( true ));
}
// 关闭 LED
void handleLedOff () {
digitalWrite ( ledPin , LOW );
server . send ( 200 , "text/html" , generateHTML ( false ));
}
// 生成 HTML 页面内容
String generateHTML ( bool ledState ) {
String htmlContent = "<!DOCTYPE html> <html> \n " ;
htmlContent += "<head><meta charset= \" utf-8 \" name= \" viewport \" content= \" width=device-width \" > \n " ;
htmlContent += "<title>ESP32S3 Test</title> \n " ;
htmlContent += "</head><body> \n " ;
htmlContent += "<h1>Hello World!</h1> \n " ;
if ( ledState ) {
htmlContent += "<p>LED Status: ON</p>" ;
htmlContent += "<a href= \" /ledoff \" >Turn off the LED</a> \n " ;
} else {
htmlContent += "<p>LED Status: OFF</p>" ;
htmlContent += "<a href= \" /ledon \" >Turn on the LED</a> \n " ;
}
htmlContent += "</body> \n " ;
htmlContent += "</html> \n " ;
return htmlContent ;
}
我们学习了如何搭建网页服务器
蓝牙 esp 32 通过蓝牙进行通信
基础概念 gap:负责蓝牙设备的发现与连接(通用访问) ![[image-28.png|542]] GATT:负责设备连接成功之后的数据交换 采用客户端服务器架构 ![[image-29.png]] 使用 ble 发送数据 ![[image-30.png|372]]
C++ #include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
// 全局变量
BLEServer * pServer = NULL ;
BLECharacteristic * pPotentiometerCharacteristic = NULL ;
bool deviceConnected = false ;
// 电位器相关的定义
const int potentiometerPin = 7 ; // 电位器连接到 GPIO 7
uint16_t lastPotValue ; // 用于存储上一次的电位器读数 (0-4095)
// 为服务和特征定义 UUID
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define POTENTIOMETER_CHARACTERISTIC_UUID "1b9a473a-4493-4536-8b2b-9d4133488256"
// 服务器回调类,用于处理连接和断开事件
class MyServerCallbacks : public BLEServerCallbacks {
void onConnect ( BLEServer * pServer ) {
deviceConnected = true ;
Serial . println ( "Device Connected" );
}
void onDisconnect ( BLEServer * pServer ) {
deviceConnected = false ;
Serial . println ( "Device Disconnected, restarting advertising..." );
// 当设备断开连接时,立即重新开始广播
pServer -> getAdvertising () -> start ();
}
};
void setup () {
Serial . begin ( 115200 );
Serial . println ( "Starting BLE Potentiometer example..." );
// 初始化电位器输入
lastPotValue = analogRead ( potentiometerPin );
// 1. 初始化 BLE 设备
BLEDevice :: init ( "ESP32_Potentiometer" );
// 2. 创建 BLE 服务器并设置回调
pServer = BLEDevice :: createServer ();
pServer -> setCallbacks ( new MyServerCallbacks ());
// 3. 创建 BLE 服务
BLEService * pService = pServer -> createService ( SERVICE_UUID );
// 4. 创建 BLE 特征
pPotentiometerCharacteristic = pService -> createCharacteristic (
POTENTIOMETER_CHARACTERISTIC_UUID ,
BLECharacteristic :: PROPERTY_READ | // 可读
BLECharacteristic :: PROPERTY_NOTIFY // 可订阅通知
);
pPotentiometerCharacteristic -> addDescriptor ( new BLE2902 ()); // 添加 2902 描述符,用于接收启用订阅的指令
// 设置初始值
pPotentiometerCharacteristic -> setValue ( lastPotValue );
// 5. 启动服务
pService -> start ();
// 6. 启动广播
pServer -> getAdvertising () -> start ();
Serial . println ( "BLE Server started, waiting for a client connection..." );
}
void loop () {
// 只有当设备连接时,才需要检查电位器状态
if ( deviceConnected ) {
uint16_t currentPotValue = analogRead ( potentiometerPin );
// 为了防止模拟信号抖动导致的数据泛滥,只有当值变化超过一个阈值时才发送
if ( abs ( currentPotValue - lastPotValue ) > 30 ) {
lastPotValue = currentPotValue ;
// 更新特征的值并通过 notify 发送给客户端
pPotentiometerCharacteristic -> setValue ( currentPotValue );
pPotentiometerCharacteristic -> notify ();
Serial . print ( "Potentiometer value changed to: " );
Serial . println ( currentPotValue );
}
delay ( 50 );
}
}
反向操作 C++ #include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
// 全局变量
BLEServer * pServer = NULL ;
BLECharacteristic * pBrightnessCharacteristic = NULL ;
bool deviceConnected = false ;
bool newDataAvailable = false ;
uint8_t brightness = 0 ;
// LED 相关定义
const int ledPin = 7 ; // LED 连接到 GPIO 7
// 为服务和特征定义唯一的 UUID
#define SERVICE_UUID "458063a1-02bf-4664-857e-16c1030be066"
#define BRIGHTNESS_CHARACTERISTIC_UUID "a5209632-66a9-411d-9353-9be5507790fa"
// 服务器回调类,用于处理连接和断开事件
class MyServerCallbacks : public BLEServerCallbacks {
void onConnect ( BLEServer * pServer ) {
deviceConnected = true ;
Serial . println ( "Client connected successfully" );
}
void onDisconnect ( BLEServer * pServer ) {
deviceConnected = false ;
Serial . println ( "Client disconnected, restarting advertisement" );
// 立即重新开始广播,以便客户端可以重新连接
pServer -> getAdvertising () -> start ();
}
};
// 特征回调类,用于处理客户端的写入请求
class MyBrightnessCallbacks : public BLECharacteristicCallbacks {
// 当客户端向该特征写入数据时,此函数被调用
void onWrite ( BLECharacteristic * pCharacteristic ) {
String value_str = pCharacteristic -> getValue ();
if ( value_str . length () > 0 ) {
// 从接收的数据中获取亮度值
brightness = value_str [ 0 ];
newDataAvailable = true ;
}
}
};
void setup () {
Serial . begin ( 115200 );
Serial . println ( "Starting ESP32 BLE LED Controller" );
// 设置引脚为输出
pinMode ( ledPin , OUTPUT );
// 1. 初始化 BLE 设备
BLEDevice :: init ( "ESP32_LED" );
// 2. 创建 BLE 服务器并设置回调
pServer = BLEDevice :: createServer ();
pServer -> setCallbacks ( new MyServerCallbacks ());
// 3. 创建 BLE 服务
BLEService * pService = pServer -> createService ( SERVICE_UUID );
// 4. 创建 BLE 特征
pBrightnessCharacteristic = pService -> createCharacteristic (
BRIGHTNESS_CHARACTERISTIC_UUID ,
BLECharacteristic :: PROPERTY_WRITE // 只允许写入
);
// 为特征设置写入回调
pBrightnessCharacteristic -> setCallbacks ( new MyBrightnessCallbacks ());
// 5. 启动服务
pService -> start ();
Serial . println ( "BLE service started" );
// 6. 启动广播
BLEAdvertising * pAdvertising = BLEDevice :: getAdvertising ();
pAdvertising -> addServiceUUID ( SERVICE_UUID );
pAdvertising -> setScanResponse ( true );
pServer -> getAdvertising () -> start ();
Serial . println ( "Advertisement started, ready for connections" );
}
void loop () {
if ( newDataAvailable ) {
// 重置标志位,防止重复处理
newDataAvailable = false ;
Serial . print ( "Brightness received: " );
Serial . println ( brightness );
// 设置 LED 亮度
analogWrite ( ledPin , brightness );
}
}
使用 ble 进行 esp 32 之间的通信 外围设备: C++ #include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
// 全局变量
BLEServer * pServer = NULL ;
BLECharacteristic * pBrightnessCharacteristic = NULL ;
bool deviceConnected = false ;
bool newDataAvailable = false ;
uint8_t brightness = 0 ;
// LED 相关定义
const int ledPin = 7 ; // LED 连接到 GPIO 7
// 为服务和特征定义唯一的 UUID
#define SERVICE_UUID "458063a1-02bf-4664-857e-16c1030be066"
#define BRIGHTNESS_CHARACTERISTIC_UUID "a5209632-66a9-411d-9353-9be5507790fa"
// 服务器回调类,用于处理连接和断开事件
class MyServerCallbacks : public BLEServerCallbacks {
void onConnect ( BLEServer * pServer ) {
deviceConnected = true ;
Serial . println ( "Client connected successfully" );
}
void onDisconnect ( BLEServer * pServer ) {
deviceConnected = false ;
Serial . println ( "Client disconnected, restarting advertisement" );
// 立即重新开始广播,以便客户端可以重新连接
pServer -> getAdvertising () -> start ();
}
};
// 特征回调类,用于处理客户端的写入请求
class MyBrightnessCallbacks : public BLECharacteristicCallbacks {
// 当客户端向该特征写入数据时,此函数被调用
void onWrite ( BLECharacteristic * pCharacteristic ) {
String value_str = pCharacteristic -> getValue ();
if ( value_str . length () > 0 ) {
// 从接收的数据中获取亮度值
brightness = value_str [ 0 ];
newDataAvailable = true ;
}
}
};
void setup () {
Serial . begin ( 115200 );
Serial . println ( "Starting ESP32 BLE LED Controller" );
// 设置引脚为输出
pinMode ( ledPin , OUTPUT );
// 1. 初始化 BLE 设备
BLEDevice :: init ( "ESP32_LED" );
// 2. 创建 BLE 服务器并设置回调
pServer = BLEDevice :: createServer ();
pServer -> setCallbacks ( new MyServerCallbacks ());
// 3. 创建 BLE 服务
BLEService * pService = pServer -> createService ( SERVICE_UUID );
// 4. 创建 BLE 特征
pBrightnessCharacteristic = pService -> createCharacteristic (
BRIGHTNESS_CHARACTERISTIC_UUID ,
BLECharacteristic :: PROPERTY_WRITE // 只允许写入
);
// 为特征设置写入回调
pBrightnessCharacteristic -> setCallbacks ( new MyBrightnessCallbacks ());
// 5. 启动服务
pService -> start ();
Serial . println ( "BLE service started" );
// 6. 启动广播
BLEAdvertising * pAdvertising = BLEDevice :: getAdvertising ();
pAdvertising -> addServiceUUID ( SERVICE_UUID );
pAdvertising -> setScanResponse ( true );
pServer -> getAdvertising () -> start ();
Serial . println ( "Advertisement started, ready for connections" );
}
void loop () {
if ( newDataAvailable ) {
// 重置标志位,防止重复处理
newDataAvailable = false ;
Serial . print ( "Brightness received: " );
Serial . println ( brightness );
// 设置 LED 亮度
analogWrite ( ledPin , brightness );
}
}
中央设备 C++ #include <BLEDevice.h>
// 要连接的服务器的服务和特征 UUID (必须与服务器代码一致)
#define SERVICE_UUID "458063a1-02bf-4664-857e-16c1030be066"
#define BRIGHTNESS_CHARACTERISTIC_UUID "a5209632-66a9-411d-9353-9be5507790fa"
// 全局变量
static boolean doConnect = false ;
static boolean connected = false ;
static BLEAddress * pServerAddress ;
static BLERemoteCharacteristic * pRemoteCharacteristic ;
// 电位器相关定义
const int potentiometerPin = 7 ; // 电位器连接到 GPIO 7
uint8_t lastBrightness = 0 ; // 存储上一次发送的亮度值 (0-255)
class MyClientCallbacks : public BLEClientCallbacks {
void onConnect ( BLEClient * pclient ) {}
void onDisconnect ( BLEClient * pclient ) {
connected = false ;
Serial . println ( "onDisconnect: Client Disconnected" );
}
};
// 扫描回调类,当发现 BLE 设备时被调用
class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks {
void onResult ( BLEAdvertisedDevice advertisedDevice ) {
// 找到设备,检查它是否包含正在寻找的服务。
if ( advertisedDevice . isAdvertisingService ( BLEUUID ( SERVICE_UUID ))) {
Serial . print ( "Found target server by Service UUID: " );
Serial . println ( advertisedDevice . getAddress (). toString (). c_str ());
// 停止扫描
advertisedDevice . getScan () -> stop ();
// 保存服务器地址,并设置连接标志
pServerAddress = new BLEAddress ( advertisedDevice . getAddress ());
doConnect = true ;
}
}
};
// 连接服务器的函数
bool connectToServer ( BLEAddress pAddress ) {
Serial . print ( "Connecting to " );
Serial . println ( pAddress . toString (). c_str ());
// 创建 BLE 客户端
BLEClient * pClient = BLEDevice :: createClient ();
Serial . println ( " - Client created" );
pClient -> setClientCallbacks ( new MyClientCallbacks ());
// 连接到远程 BLE 服务器
if ( ! pClient -> connect ( pAddress )) {
Serial . println ( " - Connection failed" );
return false ;
}
Serial . println ( " - Connected to server" );
// 获取服务器上的服务
BLERemoteService * pRemoteService = pClient -> getService ( SERVICE_UUID );
if ( pRemoteService == nullptr ) {
Serial . print ( "Failed to find service UUID: " );
Serial . println ( SERVICE_UUID );
pClient -> disconnect ();
return false ;
}
Serial . println ( " - Service found" );
// 获取服务中的特征
pRemoteCharacteristic = pRemoteService -> getCharacteristic ( BRIGHTNESS_CHARACTERISTIC_UUID );
if ( pRemoteCharacteristic == nullptr ) {
Serial . print ( "Failed to find characteristic UUID: " );
Serial . println ( BRIGHTNESS_CHARACTERISTIC_UUID );
pClient -> disconnect ();
return false ;
}
Serial . println ( " - Characteristic found" );
connected = true ;
return true ;
}
void setup () {
Serial . begin ( 115200 );
Serial . println ( "Starting BLE LED Brightness Controller (Client)..." );
// 初始化 BLE, 作为客户端时, 设备名称不是必需的,因为它只扫描而不广播自己。
BLEDevice :: init ( "" );
// 获取扫描对象并设置回调
BLEScan * pBLEScan = BLEDevice :: getScan ();
pBLEScan -> setAdvertisedDeviceCallbacks ( new MyAdvertisedDeviceCallbacks ());
pBLEScan -> setActiveScan ( true ); // 主动扫描
pBLEScan -> start ( 30 , false ); // 开始扫描,持续 30 秒
}
void loop () {
// 如果我们收到了连接指令并且尚未连接,则尝试连接
if ( doConnect == true ) {
if ( connectToServer ( * pServerAddress )) {
Serial . println ( "Successfully connected to the server!" );
doConnect = false ; // 清除连接指令
} else {
Serial . println ( "Failed to connect to the server. Rescanning after 3 seconds..." );
delay ( 3000 );
BLEDevice :: getScan () -> start ( 5 , false ); // 重新开始扫描 5 秒
}
}
// 如果已连接,则读取电位器并发送数据
if ( connected ) {
// 读取电位器的模拟值 (ESP32 ADC 是 12 位的,范围 0-4095)
int potValue = analogRead ( potentiometerPin );
// 将 0-4095 的值映射到 0-255 的亮度范围
uint8_t brightness = map ( potValue , 0 , 4095 , 0 , 255 );
// 只有当亮度值发生一定变化,以减少不必要的通信
if ( abs ( brightness - lastBrightness ) > 2 ) {
Serial . print ( "Potentiometer value: " );
Serial . print ( potValue );
Serial . print ( " -> Sending brightness: " );
Serial . println ( brightness );
// 将单个字节的亮度值写入服务器的特征
pRemoteCharacteristic -> writeValue ( & brightness , 1 );
lastBrightness = brightness ;
}
delay ( 100 ); // 每 100 毫秒检查一次
} else {
// 如果断开连接,则重新扫描
if ( ! doConnect ) {
Serial . println ( "Disconnected. Rescanning..." );
BLEDevice :: getScan () -> start ( 5 , false );
}
}
}
教程网址
⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠ You can decompress Drawing data with the command palette: 'Decompress current Excalidraw file'. For more info check in plugin settings under 'Saving'
新的 ## 目的 Excalidraw Data Text Elements %%
Drawing Text Only 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=
%%