用于Arduino、esp32或esp8266的Ebyte LoRa E32(SX1278)设备:规格和基本用法 - 第一部分

作者:renzo mischianti - 2019年10月15日出版 - 2021年6月21日更新

图 1LoRa EBYTE E32-TTL-100 Arduino基础知识题

 LoRa或长距离无线数据遥测是Semtech开创的一项技术,其工作频率低于NRF24L01(433 MHz、868 MHz或916 MHz,而NRF24L01的频率为2.4 GHz),但工作距离是其三倍(从3000米到8000米)。

图 2LoRa E32-TTL-100题

我们要测试的是E32-TTL-100。它是一个无线收发模块,工作在410 441 MHz,基于SEMTECH的原始RFIC SX1278,可以透明传输,TTL级别。该模块采用了LORA扩频技术。

该模块采用FEC前向纠错算法,保证了其高的编码效率和良好的纠错性能。在突发干扰的情况下,它可以自动纠正受干扰的数据包,从而使可靠性和传输范围得到相应的改善。 但如果没有FEC,这些数据包只能被丢弃。

通过严格的加密和解密,数据拦截变得毫无意义。数据压缩的功能可以减少传输时间和受干扰的概率,同时提高可靠性和传输效率。

0.1.操作和传输类型

这个装置有一些有趣的功能

0.1.1.传输

图 3LoRa E32的传输场景题

0.1.1.1.透明传输

这可以被认为是一个 "演示模式",默认情况下,你可以向同一配置的地址和通道的所有设备发送信息。

0.1.1.2.固定传输

这种类型的传输,你可以指定一个地址和一个通道,在那里发送你想发送的信息。
你可以发送消息到一个 a:

·指定的设备有一个预先确定的地址低、地址高和通道

图 4向指定设备发送LoRa E32固定信息

·在预先确定的频道上广播一条信息。

图 5向一组通道设备广播信息

0.1.2.正常模式

只需发送消息。

0.1.3. 唤醒模式和省电模式

正如你所想的那样,如果一个设备处于唤醒模式,就可以通过前奏通信 "唤醒 "一个或多个处于省电模式的设备。

唤醒模式

 省电模式

 0.1.4.程序/睡眠模式

通过这个配置,你可以改变设备的配置。

 0.1.5.规格参数

以下是该模块的规格

  • 模块尺寸:21*36mm
  • 天线类型:SMA-K (50Ω阻抗)
  • 传输距离: 3000m(max)
  • 最大功率: 2dB(100mW)
  • 空中速率: 2.4Kbps (6 种可选配置 (0.3, 1.2, 2.4, 4.8, 9.6, 19.2kbps)
  • 缓存容量: 512Byte
  • 分包方式: 58Byte
  • 通信接口UART - 8N1、8E1、8O1,八种UART波特率,从1200到115200bps(默认:9600)。
  • 支持RSSI不支持(内置智能处理)
  • 工作频率: 410MHz-441MHz (默认 433MHz), 通道数: 32

 你必须注意与电源不同的通信水平,第二种可以接收3.3v(esp8266和esp32)和5v(Arduino)的电压,但第一种需要3.3v,所以要连接到Arduino,你必须使用分压器以防止损坏设备。

0.1.6.引脚分布

图 6E32 TTL 100

  

如你所见,你可以通过M0和M1引脚设置各种模式。

在接下来的简单测试中,我们将使用正常模式。

0.2.连接Wemos D1 mini (esp8266)的基本用法

esp8266的优点是有相同电压的通信接口,所以连接方案比Arduino更简单。

图 7LoRa E32-TTL-100 Wemos D1面包板

 重要的是添加上拉电阻(4.7)以获得良好的稳定性。

 0.3.连接Arduino的基本用法

Arduino的工作电压是5V,所以我们需要在LoRa模块的RX引脚上加一个分压器以防止损坏,

你可以用一个2KΩ的电阻到GND,然后从信号中分出1KΩ,然后放在RX上。

图 8LoRa E32-TTL-100 Arduino面包板

 0.4.简单的通信草图

如果你把M1和M0引脚设为0,你就进入了 "正常 "模式,那么你就可以接收和传输所有从设备A到B的数据,这种模式被定义为 "母体传输"。

你可以使用2个Arduinos或2个Wemos D1 mini或其中一个。

在开始时发送一个信息,如果你从一个设备上写下串口,文本就会被传送到另一个设备上。你可以使用2个Arduinos或2个Wemos或一个和一个,随你喜欢。

Arduino代码

/*
 * LoRa E32-TTL-100
 * Start device or reset to send a message
 * https://www.mischianti.org
 *
 * E32-TTL-100----- Arduino UNO
 * M0         ----- GND
 * M1         ----- GND
 * TX         ----- PIN 2 (PullUP)
 * RX         ----- PIN 3 (PullUP & Voltage divider)
 * AUX        ----- Not connected
 * VCC        ----- 3.3v/5v
 * GND        ----- GND
 *
 */
#include "Arduino.h"
 
#include <SoftwareSerial.h>
 
SoftwareSerial mySerial(2, 3); // e32 TX e32 RX
 
void setup() {
  Serial.begin(9600);
  delay(500);
 
  Serial.println("Hi, I'm going to send message!");
 
  mySerial.begin(9600);
  mySerial.println("Hello, world?");
}
 
void loop() {
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }
}

Wemos D1 mini 代码:

/*
 * LoRa E32-TTL-100
 * Start device or reset to send a message
 * https://www.mischianti.org
 *
 * E32-TTL-100----- Wemos D1 mini
 * M0         ----- GND
 * M1         ----- GND
 * TX         ----- PIN D2 (PullUP)
 * RX         ----- PIN D3 (PullUP)
 * AUX        ----- Not connected
 * VCC        ----- 3.3v/5v
 * GND        ----- GND
 *
 */
#include "Arduino.h"
#include <SoftwareSerial.h>
 
SoftwareSerial mySerial(D2, D3); // e32 TX e32 RX
 
void setup() {
  Serial.begin(9600);
  delay(500);
 
  Serial.println("Hi, I'm going to send message!");
 
  mySerial.begin(9600);
  mySerial.println("Hello, world?");
}
 
void loop() {
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }

但这一基本用法很不寻常,所以在下一章,我们将使用我的库,深入研究设备的功能。

0.5.库

Here the last example with my library:这里是我的库的最一个例子

xreef/LoRa_E32_Series_Library: Arduino LoRa EBYTE E32 device library complete and tested with Arduino, esp8266 and esp32. sx1278/sx1276 (github.com)

Arduino 代码:

/*
 * LoRa E32-TTL-100
 * Write on serial to transfer a message to other device
 * https://www.mischianti.org
 *
 * E32-TTL-100----- Arduino UNO
 * M0         ----- GND
 * M1         ----- GND
 * TX         ----- PIN 2 (PullUP)
 * RX         ----- PIN 3 (PullUP & Voltage divider)
 * AUX        ----- Not connected
 * VCC        ----- 3.3v/5v
 * GND        ----- GND
 *
 */
#include "Arduino.h"
#include "LoRa_E32.h"
 
LoRa_E32 e32ttl100(2, 3); // e32 TX e32 RX
 
void setup() {
  Serial.begin(9600);
  delay(500);
 
  Serial.println("Hi, I'm going to send message!");
 
  // Startup all pins and UART
  e32ttl100.begin();
 
  // Send message
  ResponseStatus rs = e32ttl100.sendMessage("Hello, world?");
  // Check If there is some problem of succesfully send
  Serial.println(rs.getResponseDescription());
}
 
void loop() {
    // If something available
  if (e32ttl100.available()>1) {
      // read the String message
    ResponseContainer rc = e32ttl100.receiveMessage();
    // Is something goes wrong print error
    if (rc.status.code!=1){
        rc.status.getResponseDescription();
    }else{
        // Print the data received
        Serial.println(rc.data);
    }
  }
  if (Serial.available()) {
      String input = Serial.readString();
      e32ttl100.sendMessage(input);
  }
}

Wemos D1 (esp8266) 草图:

/*
 * LoRa E32-TTL-100
 * Start device or reset to send a message
 * https://www.mischianti.org
 *
 * E32-TTL-100----- Wemos D1 mini
 * M0         ----- GND
 * M1         ----- GND
 * TX         ----- PIN D2 (PullUP)
 * RX         ----- PIN D3 (PullUP)
 * AUX        ----- Not connected
 * VCC        ----- 3.3v/5v
 * GND        ----- GND
 *
 */
#include "Arduino.h"
#include "LoRa_E32.h"
 
LoRa_E32 e32ttl100(D2, D3); // e32 TX e32 RX
 
void setup() {
  Serial.begin(9600);
  delay(500);
 
  Serial.println("Hi, I'm going to send message!");
 
  // Startup all pins and UART
  e32ttl100.begin();
 
  // Send message
  ResponseStatus rs = e32ttl100.sendMessage("Hello, world?");
  // Check If there is some problem of succesfully send
  Serial.println(rs.getResponseDescription());
}
 
void loop() {
    // If something available
  if (e32ttl100.available()>1) {
      // read the String message
    ResponseContainer rc = e32ttl100.receiveMessage();
    // Is something goes wrong print error
    if (rc.status.code!=1){
        rc.status.getResponseDescription();
    }else{
        // Print the data received
        Serial.println(rc.data);
    }
  }
  if (Serial.available()) {
      String input = Serial.readString();
      e32ttl100.sendMessage(input);
  }
}

如果你已经改变了配置,你必须恢复基本参数:

//  If you have ever change configuration you must restore It
    ResponseStructContainer c;
    c = e32ttl100.getConfiguration();
    Configuration configuration = *(Configuration*) c.data;
    Serial.println(c.status.getResponseDescription());
    configuration.CHAN = 0x17;
    configuration.OPTION.fixedTransmission = FT_TRANSPARENT_TRANSMISSION;
    e32ttl100.setConfiguration(configuration, WRITE_CFG_PWR_DWN_SAVE);

但我们将在下一篇文章中更好地了解它。

0.6.Thanks

但这种用法是非常非常简化的,在接下来的文章中,我们将更深入地研究,我们开始大量使用库来简化复杂的配置和设置。

  • 3
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值