ESP32-LORA通信
文章目录
好久没更新博客了,今天清明节,写个LORA通信。在此记念在天堂的外婆。祝她安好
LORA通信简介
oRa就是远距离无线电(Long Range Radio),是semtech公司创建的低功耗局域网无线标准,它最大特点就是在同样的功耗条件下比其他无线方式传播的距离更远,实现了低功耗和远距离的统一,它在同样的功耗下比传统的无线射频通信距离扩大3-5倍。
一、模块
ESP32开发板1块
SA32型LORA模块2块
USB转串口模块1个
二、使用步骤
1.电脑通过USB串口模块联接LORA模块
2.ESP32连接LORA通信进行收发通信
代码如下(示例):
'''
ESP32串口通信-字符串数据自发实验接线 将开发板的 16号引脚与17号引脚用杜邦线相连接。'''
from machine import UART,Pin
import utime# 初始化一个UART对象
uart = UART(2, baudrate=9600, rx=16,tx=17)count = 1while True:print('\\n\\n===============CNT {}==============='.format(count))# 发送一条消息#test = 'hello {}\\n'.format(count)test = 'heloo windows {}\\n'.format(count)uart.write(test)print('Send: {}'.format(test))if uart.any():# 如果有数据 读入一行数据返回数据为字节类型# 例如 b'hello 1\\n'bin_data = uart.readline()# 将手到的信息打印在终端print('Echo Byte: {}'.format(bin_data))# 将字节数据转换为字符串 字节默认为UTF-8编码print('Echo String: {}'.format(bin_data.decode()))# 计数器+1count += 1print('---------------------------------------')# 等待1s钟utime.sleep_ms(5000)
3.电脑运行调试助手,ESP32运行代码。实现LORA通信测试
运行如下(示例):
总结
提示:M0、M1要接地
物联网通信首选LORA,稳定