原作者:renzo mischianti - 2019年12月28日发表 - 2021年6月21日更新
我们已经看到这个设备(基于流行的SX1276/SX1278无线模块的E32 UART LoRa)是如何管理省电的,但是如果我们只对e32使用省电,微控制器就会继续保持活跃,但是我们可以使用AUX引脚来解决这个问题。
![](https://i-blog.csdnimg.cn/blog_migrate/1cb3531da18eaca4ad3ec13c10564520.png)
如果你有像冻结设备的麻烦,你必须把一个上拉的4.7k电阻或更好的连接到设备AUX引脚。
首先,我们必须从原来的连接模式中改变一些连接,因为在原来的连接模式中,AUX针脚没有连接到中断的针脚上,我们要把AUX针脚放到Arduino的第3针脚上,并把所有其他的针脚转移。
![](https://i-blog.csdnimg.cn/blog_migrate/cce235d25700f0651f2bfbffaecde0f5.png)
因此,新的连接模式变成这样:
![](https://i-blog.csdnimg.cn/blog_migrate/3f81b9327c8947bd546ee7db31eedbdf.png)
现在有了AUX的中断引脚,我们可以用它来唤醒Arduino。
当你处于睡眠模式时,e32把接收到的数据放在缓冲器上,并立即转为低电平,当数据准备好时,返回高电平,低电平,这是唤醒微控制器的完美方法。
![](https://i-blog.csdnimg.cn/blog_migrate/30e9ede4de5ad4c591ab4013505a8345.png)
1.Arduino唤醒
作为e32设备,Arduino有一些睡眠类型,但对于这个测试,我们将使用断电模式。
1.1.库中的PowerDown
为了管理Arduino设备的节电和睡眠,有一个漂亮的库叫LowPower。
你可以去Git仓库直接下载它。
(rocketscream/Low-Power: Low Power Library for Arduino (github.com))
你必须下载这个库并把它放在Arduino库的文件夹中。
1.2.如何使Arduino进入睡眠状态
使微控制器断电的命令非常简单
// Enter power down state with ADC and BOD module disabled.
// Wake up when wake up pin is low.
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
但我们必须规定,当AUX引脚为低电平时,设备必须被唤醒。
// Allow wake up pin to trigger interrupt on low.
attachInterrupt(1, AUX_PIN, LOW);
// Enter power down state with ADC and BOD module disabled.
// Wake up when wake up pin is low.
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
// Disable external pin interrupt on wake up pin.
detachInterrupt(1);
因此,接收传输的代码就变成了这样。
/*
* LoRa E32-TTL-100
* Receive fixed transmission message on channel.
* https://www.mischianti.org/2019/12/28/lora-e32-device-for-arduino-esp32-or-esp8266-wor-wake-on-radio-the-microcontroller-also-and-new-arduino-shield-part-6/
*
* E32-TTL-100----- Arduino UNO or esp8266
* M0 ----- 3.3v (To config) GND (To send) 7 (To dinamically manage)
* M1 ----- 3.3v (To config) GND (To send) 6 (To dinamically manage)
* TX ----- RX PIN 3 (PullUP)
* RX ----- TX PIN 4 (PullUP & Voltage divider)
* AUX ----- PIN 2 (PullUP)
* VCC ----- 3.3v/5v
* GND ----- GND
*
*/
#include "Arduino.h"
#include "LowPower.h"
#include "LoRa_E32.h"
// ---------- Arduino pins --------------
//LoRa_E32 e32ttl(4, 5, 3, 7, 6);
LoRa_E32 e32ttl(4, 5, 3); // Config without connect M0 M1
// Use pin 2 as wake up pin
const int wakeUpPin = 3;
//#include <SoftwareSerial.h>
//SoftwareSerial mySerial(4, 5); // Arduino RX <-- e32 TX, Arduino TX --> e32 RX
//LoRa_E32 e32ttl(&mySerial, 3, 7, 6);
// -------------------------------------
void printParameters(struct Configuration configuration);
void printModuleInformation(struct ModuleInformation moduleInformation);
void wakeUp()
{
Serial.println("WAKE!");
}
//The setup function is called once at startup of the sketch
void setup()
{
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB
}
delay(100);
e32ttl.begin();
// e32ttl.resetModule();
// After set configuration comment set M0 and M1 to low
// and reboot if you directly set HIGH M0 and M1 to program
// ResponseStructContainer c;
// c = e32ttl.getConfiguration();
// Configuration configuration = *(Configuration*) c.data;
// configuration.ADDL = 3;
// configuration.ADDH = 0;
// configuration.CHAN = 0x04;
// configuration.OPTION.fixedTransmission = FT_FIXED_TRANSMISSION;
// configuration.OPTION.wirelessWakeupTime = WAKE_UP_250;
//
// configuration.OPTION.fec = FEC_1_ON;
// configuration.OPTION.ioDriveMode = IO_D_MODE_PUSH_PULLS_PULL_UPS;
// configuration.OPTION.transmissionPower = POWER_20;
//
// configuration.SPED.airDataRate = AIR_DATA_RATE_010_24;
// configuration.SPED.uartBaudRate = UART_BPS_9600;
// configuration.SPED.uartParity = MODE_00_8N1;
//
// e32ttl.setConfiguration(configuration, WRITE_CFG_PWR_DWN_SAVE);
// printParameters(configuration);
// ---------------------------
Serial.println();
Serial.println("Start listening!");
e32ttl.setMode(MODE_2_POWER_SAVING);
// Allow wake up pin to trigger interrupt on low.
attachInterrupt(1, wakeUp, LOW);
// Enter power down state with ADC and BOD module disabled.
// Wake up when wake up pin is low.
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
// Disable external pin interrupt on wake up pin.
detachInterrupt(1);
Serial.println("OK listening!");
}
// The loop function is called in an endless loop
void loop()
{
if (e32ttl.available() > 1){
ResponseContainer rs = e32ttl.receiveMessage();
// First of all get the data
String message = rs.data;
Serial.print("Received --> ");
Serial.print(rs.status.getResponseDescription());
Serial.print(" - ");
Serial.println(message);
}
delay(125);
}
void printParameters(struct Configuration configuration) {
Serial.println("----------------------------------------");
Serial.print(F("HEAD : ")); Serial.print(configuration.HEAD, BIN);Serial.print(" ");Serial.print(configuration.HEAD, DEC);Serial.print(" ");Serial.println(configuration.HEAD, HEX);
Serial.println(F(" "));
Serial.print(F("AddH : ")); Serial.println(configuration.ADDH, DEC);
Serial.print(F("AddL : ")); Serial.println(configuration.ADDL, DEC);
Serial.print(F("Chan : ")); Serial.print(configuration.CHAN, DEC); Serial.print(" -> "); Serial.println(configuration.getChannelDescription());
Serial.println(F(" "));
Serial.print(F("SpeedParityBit : ")); Serial.print(configuration.SPED.uartParity, BIN);Serial.print(" -> "); Serial.println(configuration.SPED.getUARTParityDescription());
Serial.print(F("SpeedUARTDatte : ")); Serial.print(configuration.SPED.uartBaudRate, BIN);Serial.print(" -> "); Serial.println(configuration.SPED.getUARTBaudRate());
Serial.print(F("SpeedAirDataRate : ")); Serial.print(configuration.SPED.airDataRate, BIN);Serial.print(" -> "); Serial.println(configuration.SPED.getAirDataRate());
Serial.print(F("OptionTrans : ")); Serial.print(configuration.OPTION.fixedTransmission, BIN);Serial.print(" -> "); Serial.println(configuration.OPTION.getFixedTransmissionDescription());
Serial.print(F("OptionPullup : ")); Serial.print(configuration.OPTION.ioDriveMode, BIN);Serial.print(" -> "); Serial.println(configuration.OPTION.getIODroveModeDescription());
Serial.print(F("OptionWakeup : ")); Serial.print(configuration.OPTION.wirelessWakeupTime, BIN);Serial.print(" -> "); Serial.println(configuration.OPTION.getWirelessWakeUPTimeDescription());
Serial.print(F("OptionFEC : ")); Serial.print(configuration.OPTION.fec, BIN);Serial.print(" -> "); Serial.println(configuration.OPTION.getFECDescription());
Serial.print(F("OptionPower : ")); Serial.print(configuration.OPTION.transmissionPower, BIN);Serial.print(" -> "); Serial.println(configuration.OPTION.getTransmissionPowerDescription());
Serial.println("----------------------------------------");
}
void printModuleInformation(struct ModuleInformation moduleInformation) {
Serial.println("----------------------------------------");
Serial.print(F("HEAD BIN: ")); Serial.print(moduleInformation.HEAD, BIN);Serial.print(" ");Serial.print(moduleInformation.HEAD, DEC);Serial.print(" ");Serial.println(moduleInformation.HEAD, HEX);
Serial.print(F("Freq.: ")); Serial.println(moduleInformation.frequency, HEX);
Serial.print(F("Version : ")); Serial.println(moduleInformation.version, HEX);
Serial.print(F("Features : ")); Serial.println(moduleInformation.features, HEX);
Serial.println("----------------------------------------");
}
结果是串口在第91行停止,当我们收到信息时,e32自己唤醒并把AUX置于低位,所以Arduino用AUX引脚的中断唤醒。
这里是发送端代码:
/*
* LoRa E32-TTL-100
* Send fixed broadcast transmission message to a specified channel.
* https://www.mischianti.org/2019/12/28/lora-e32-device-for-arduino-esp32-or-esp8266-wor-wake-on-radio-the-microcontroller-also-and-new-arduino-shield-part-6/
*
*/
#include "Arduino.h"
#include "LoRa_E32.h"
// ---------- esp8266 pins --------------
LoRa_E32 e32ttl(D2, D3, D5, D7, D6); //, D5); //, D7, D6); // Config without connect AUX and M0 M1
// -------------------------------------
void printParameters(struct Configuration configuration);
void printModuleInformation(struct ModuleInformation moduleInformation);
//The setup function is called once at startup of the sketch
void setup()
{
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB
}
delay(100);
while (!e32ttl.begin()) {
delay(2000); // wait for serial port to connect. Needed for native USB
}
e32ttl.setMode(MODE_1_WAKE_UP);
// e32ttl.resetModule();
// After set configuration comment set M0 and M1 to low
// and reboot if you directly set HIGH M0 and M1 to program
ResponseStructContainer c;
c = e32ttl.getConfiguration();
Configuration configuration = *(Configuration*) c.data;
printParameters(configuration);
// configuration.SPED.uartBaudRate = UART_BPS_9600;
// configuration.SPED.airDataRate = AIR_DATA_RATE_010_24;
configuration.ADDL = 0x01;
configuration.ADDH = 0x00;
configuration.CHAN = 0x04;
configuration.OPTION.fixedTransmission = FT_FIXED_TRANSMISSION;
configuration.OPTION.wirelessWakeupTime = WAKE_UP_750;
configuration.OPTION.fec = FEC_1_ON;
configuration.OPTION.ioDriveMode = IO_D_MODE_PUSH_PULLS_PULL_UPS;
configuration.OPTION.transmissionPower = POWER_20;
configuration.SPED.airDataRate = AIR_DATA_RATE_010_24;
configuration.SPED.uartBaudRate = UART_BPS_9600;
configuration.SPED.uartParity = MODE_00_8N1;
e32ttl.setConfiguration(configuration, WRITE_CFG_PWR_DWN_SAVE);
printParameters(configuration);
// ---------------------------
}
int i = 0;
// The loop function is called in an endless loop
void loop()
{
i++;
String mess = "Message to 00 03 04 deviceMessage to ";
String compMEss = mess+i;
Serial.print(compMEss);
Serial.print(" - ");
ResponseStatus rs = e32ttl.sendFixedMessage(0, 3, 0x04, compMEss);
Serial.println(rs.getResponseDescription());
delay(8000);
}
void printParameters(struct Configuration configuration) {
Serial.println("----------------------------------------");
Serial.print(F("HEAD : ")); Serial.print(configuration.HEAD, BIN);Serial.print(" ");Serial.print(configuration.HEAD, DEC);Serial.print(" ");Serial.println(configuration.HEAD, HEX);
Serial.println(F(" "));
Serial.print(F("AddH : ")); Serial.println(configuration.ADDH, DEC);
Serial.print(F("AddL : ")); Serial.println(configuration.ADDL, DEC);
Serial.print(F("Chan : ")); Serial.print(configuration.CHAN, DEC); Serial.print(" -> "); Serial.println(configuration.getChannelDescription());
Serial.println(F(" "));
Serial.print(F("SpeedParityBit : ")); Serial.print(configuration.SPED.uartParity, BIN);Serial.print(" -> "); Serial.println(configuration.SPED.getUARTParityDescription());
Serial.print(F("SpeedUARTDatte : ")); Serial.print(configuration.SPED.uartBaudRate, BIN);Serial.print(" -> "); Serial.println(configuration.SPED.getUARTBaudRate());
Serial.print(F("SpeedAirDataRate : ")); Serial.print(configuration.SPED.airDataRate, BIN);Serial.print(" -> "); Serial.println(configuration.SPED.getAirDataRate());
Serial.print(F("OptionTrans : ")); Serial.print(configuration.OPTION.fixedTransmission, BIN);Serial.print(" -> "); Serial.println(configuration.OPTION.getFixedTransmissionDescription());
Serial.print(F("OptionPullup : ")); Serial.print(configuration.OPTION.ioDriveMode, BIN);Serial.print(" -> "); Serial.println(configuration.OPTION.getIODroveModeDescription());
Serial.print(F("OptionWakeup : ")); Serial.print(configuration.OPTION.wirelessWakeupTime, BIN);Serial.print(" -> "); Serial.println(configuration.OPTION.getWirelessWakeUPTimeDescription());
Serial.print(F("OptionFEC : ")); Serial.print(configuration.OPTION.fec, BIN);Serial.print(" -> "); Serial.println(configuration.OPTION.getFECDescription());
Serial.print(F("OptionPower : ")); Serial.print(configuration.OPTION.transmissionPower, BIN);Serial.print(" -> "); Serial.println(configuration.OPTION.getTransmissionPowerDescription());
Serial.println("----------------------------------------");
}
void printModuleInformation(struct ModuleInformation moduleInformation) {
Serial.println("----------------------------------------");
Serial.print(F("HEAD BIN: ")); Serial.print(moduleInformation.HEAD, BIN);Serial.print(" ");Serial.print(moduleInformation.HEAD, DEC);Serial.print(" ");Serial.println(moduleInformation.HEAD, HEX);
Serial.print(F("Freq.: ")); Serial.println(moduleInformation.frequency, HEX);
Serial.print(F("Version : ")); Serial.println(moduleInformation.version, HEX);
Serial.print(F("Features : ")); Serial.println(moduleInformation.features, HEX);
Serial.println("----------------------------------------");
}
1.3.Arduino UNO拓展板
我还创建了一个非常有用的Arduino拓展板来使用。
![](https://i-blog.csdnimg.cn/blog_migrate/6b8d1eeacc20443954db0d205a3073f2.png)
有了这块板子,你可以直接使用这个设备,而不需要问题或分压器。
其配置是这样的:
LoRa_E32 e32ttl(4, 5, 3, 7, 6);
你可以使用库中的所有例子,你可以使用第6和第7针来做一个完整的连接,或者禁用它们,用拨码开关把M0和M1放在你想要的地方。
![](https://i-blog.csdnimg.cn/blog_migrate/e9dfc16a5c5afd35a78d31f444a8d423.png)
![](https://i-blog.csdnimg.cn/blog_migrate/38d03c3c4b0d87d25793c54c66d81df0.png)
![](https://i-blog.csdnimg.cn/blog_migrate/736d2f81ac8f6f18de36f0f27355f365.png)
![](https://i-blog.csdnimg.cn/blog_migrate/c16237716d70234d9194e0689c201b29.png)
这里是第一次测试,似乎一切正常。
![](https://i-blog.csdnimg.cn/blog_migrate/5e8cbdbc872d88113127bea440a3a85c.png)
1.3.1.现在我们要做一个大规模的生产
Ready to go
![](https://i-blog.csdnimg.cn/blog_migrate/b96b949af86b87995e34006c8ad5d01a.png)
防护罩有一些跳线和拨码开关来配置M0和M1。
如果你想把M0和M1设置成一个固定的值,你必须把跳线放到F,如果你想通过引脚来控制,就把跳线放到P。
如果你设置为F,你必须把拨码开关放在属性值低或高。
![](https://i-blog.csdnimg.cn/blog_migrate/0120023fc142c282861f8e48369cb4dd.png)
1.3.2.购物清单
You can find here AliExpress (433MHz 3Km) (LoRa SX1278 433 MHz Wireless rf Module iot Transceiver CDSENET E32 433T20DT UART Long Range 433MHz rf Transmitter Receiver|receiver 433mhz|receiver transmitterreceiver wireless - AliExpress)
- AliExpress (433MHz 8Km) (LoRa SX1278 SX1276 433MHz Module Transmitter Receiver 8000m E32 433T30D V2.0 UART Long Range 433 MHz 1W Wireless rf Transceiver|transceiver 433|transceiver module 433transceiver module - AliExpress)
- AliExpress (868MHz 3Km) (1pc 868MHz LoRa SX1276 rf Transmitter Receiver Wireless rf Module CDSENET E32 868T20D UART Long Range 868 mhz rf Transceiver|transceiver|transceiver module - AliExpress)
- AliExpress (868MHz 8Km) (1pc 868MHz LoRa SX1276 rf Module Long Range E32 868T30D UART 1W iot rf Transceiver 868 MHz Ebyte rf Transmitter and Receiver|receiver 868|receiver transmitterreceiver wireless - AliExpress)
- AliExpress (915MHz 3Km) (LoRa 915MHz SX1276 rf TCXO E32 915T20D Transceiver Wireless Module ebyte Long Range iot UART 915 Mhz rf Transmitter Receiver|Fixed Wireless Terminals| - AliExpress)
- AliExpress (915MHz 8Km)(E32 915T30D Lora Long Range UART SX1276 915mhz 1W SMA Antenna IoT uhf Wireless Transceiver Transmitter Receiver Module|module|module lora - AliExpress)
你可以从PCBWay这里获得不需要额外费用的pcb。
这是我的圣诞礼物
![](https://i-blog.csdnimg.cn/blog_migrate/667b7069814110c8a6213b2e63556609.png)
我选择这个制造商是因为在同样的成本下,它提供了优秀的质量,在第一个屏幕上,它可以做出无数的选择,适合每一个需求。
正如你在各种照片上看到的那样,这个板子非常漂亮,而且很容易焊接。
1.3.3.组装
Here the result
![](https://i-blog.csdnimg.cn/blog_migrate/316f87e69a4b74b820221ab348846d26.png)
2.Thanks