首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >低功耗ESP32 + LoRa,支持深度睡眠模式(TTGO LoRa32 OLED板V1.0)

低功耗ESP32 + LoRa,支持深度睡眠模式(TTGO LoRa32 OLED板V1.0)
EN

Stack Overflow用户
提问于 2019-06-12 01:10:59
回答 3查看 5.9K关注 0票数 3

我正在尝试在低功耗模式下从一个ESP32 LoRa节点传输到另一个节点,并且符合欧洲法规。

TTGO OLED板:TTGO LoRa32 OLED板V1.0 ( (herehere).

下面是我写的LoRa发送者草图:

代码语言:javascript
复制
/*
 * LoRa (low-power) sender for IoT projects
 *  
 * Tested on a TTGO LoRa32 OLED Board V1.0 
 * 
 * Based on the LoRa examples and the board 
 * documentation
 * 
 * More on the deep sleep with timer wake up: 
 *  
 *    Examples > ESP32 > Deep Sleep > TimerWakeUp sketch
 *    
 *    
 * ERC Recommendation
 * h1.4 frequency band requires <= 1% duty cycle and 25mW (14 db) maximum power
 * => 36 seconds every hour (so: 1 sec transmitting, 99 secs idle) 
 * 
 * 
 * Created 11 June 2019
 * by DP 
 *    
 */
 
#include    // allows communication with SPI devices 
#include 
#include    // provides API to work with OLED displays

// defines the pins used by the transceiver module
#define SS 18   // GPIO18 - SX1278's CS   - LoRa radio chip select
#define RST 14   // GPIO14 - SX1278's RESET   - LoRa radio reset
#define DI0 26   // GPIO26 - SX1278's IRQ   - IRQ pin

#define BAND 868E6   // EU   - Italy

// deep sleep 
#define uS_TO_S_FACTOR 1000000  // conversion factor for micro seconds to seconds 
#define TIME_TO_SLEEP  5        // time ESP32 will go to sleep (in seconds)   - 99 for (about) 1% duty cycle  


// an object of class SSD1306 
// first parameter: the I2C address of the display
// second parameter: the number of the SDA
// third parameter: the SCL pin
SSD1306 display(0x3c, 4, 15);

// stores the data on the RTC memory so that it will not be deleted during the deep sleep
RTC_DATA_ATTR int bootCount = 0; 
RTC_DATA_ATTR int pckCounter = 0;   // sending packet number...

 
void setup() {   
  Serial.begin(115200);   // initializes serial data transmission  
  while(!Serial);   // waits for serial port to connect 

  Serial.println("LoRa low-power Sender");
  
  pinMode(16, OUTPUT);
  digitalWrite(16, LOW);   // sets GPIO16 low to reset the OLED
  delay(50);
  digitalWrite(16, HIGH);   // while the OLED is running, GPIO16 must go to high  
  pinMode(2, OUTPUT);
  digitalWrite(2, LOW);   // sets the onboard LED low 
  
  // LoRa transceiver module setup 
  LoRa.setPins(SS, RST, DI0);   // overrides the default CS, reset, and IRQ pins used by the library

  // initializes the transceiver module with a specified frequency
  while (!LoRa.begin(BAND)) {   // LoRa.begin returns 1 on success, 0 on failure
    Serial.println(".");
  }

  // changes the spreading factor to 12 -> slower speed but better noise immunity
  LoRa.setSpreadingFactor(12);   // ranges from 6-12, default is 7 

  // changes the sync word (0xF3) to match the receiver
  // the sync word assures you don't get LoRa messages from other LoRa transceivers  
  LoRa.setSyncWord(0xF3);   // ranges from 0-0xFF     
 
  // LoRa.setTxPower(txPower);   // defaults to 17

  // initializes the display by calling the init method of the display object 
  display.init();   // receives no arguments and returns void

  // display.flipScreenVertically();   // LCD is broken!
  display.setFont(ArialMT_Plain_16);   // sets the current font
  display.drawString(0, 0, "Initialization");   // x, y, message to show
  display.drawString(0, 16, "completed");
  display.display();
  delay(1500);   // small delay so that the user can read it  

  Serial.println("LoRa init completed");    

  //Increments boot number and prints it every reboot
  bootCount++;
  Serial.println("Boot number: " + String(bootCount));

  sendData();   // sends the data...

  // deep sleep
  esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
  Serial.println("Setup ESP32 to sleep for every " + String(TIME_TO_SLEEP) + " Seconds");
  Serial.println("Going to sleep now");
  Serial.flush();   // waits for the transmission of outgoing serial data to complete 
  esp_deep_sleep_start();   // enters deep sleep with the configured wakeup options
}

void loop(){
  // this is not going to be called
}

// sends the data to the receiver
void sendData() {
  
  Serial.print("Sending packet: ");
  Serial.println(pckCounter);

  display.clear();   // clears the display
  display.setTextAlignment(TEXT_ALIGN_LEFT);
  display.drawString(0, 0, "Sending ");
  display.drawString(0, 16, "packet: " + String(pckCounter, DEC));
  display.display();
  
  digitalWrite(2, HIGH);   // LED is ON during transmission

  // sends the LoRa packet to the receiver
  LoRa.beginPacket();
  LoRa.print("hello ");
  LoRa.print(pckCounter);
  LoRa.endPacket();
  
  digitalWrite(2, LOW);   // turns the LED off after transmission

  pckCounter++;
}

草图运行时没有错误(商店页面上的代码包含一些错误,所以我鼓励您使用这个代码)。我的问题:

我忘记初始化SPI通信:

SPI.begin (SCK, MISO, MOSI, SS);

但尽管如此,它还是奏效了。我没想到会这样。我的第一个问题是:我错过了什么?

我住在欧洲。ERC推荐文件说,h1.4频段(我正在以868兆赫的频率传输)需要<=1%占空比和25‘m (14db)的最大功率。这意味着我可以每小时传输36秒(假设我传输了1秒,然后ESP32‘休眠’了99秒)。我可以实现这样的写作(这不是更准确的方法,但它应该是有效的):

#define TIME_TO_SLEEP 99

那么erp呢?假设天线有2db的增益,所以我可以将发射功率设置为12db (12db + 2db -> 14db,很好。没关系!):

LoRa.setTxPower(12);

我的第二个问题:我说的对吗(关于两个设置)?我是不是漏掉了什么?

最后一个问题:请随时给我任何(如果你有)反馈/建议来改进这个草图!

EN

回答 3

Stack Overflow用户

发布于 2019-06-12 01:48:52

看起来不错,你测试过深度睡眠时的功耗吗?我有相同的电路板(TTGO ESP32 LORA ),在清醒时得到38-50 38,在睡眠时得到10 38。你可以试试LoRa.end()LoRa.sleep()

在您完成发送后,将芯片发送到睡眠状态,但我不确定这样可以节省多少电量。

有一些讨论在这里进行关于进一步降低功率的方法,但我还没能将TTGO的功率降到10 it以下。

票数 4
EN

Stack Overflow用户

发布于 2021-02-27 18:05:01

一般来说,我使用LilyGo产品的经验很差,电流很小。我测试了其中的几个(不是LoRa的),通常它们最小的电流是1 1mA。我认为真正省电的传感器可以由Atmel LoRa node制造,如下所示this.

票数 1
EN

Stack Overflow用户

发布于 2019-12-15 18:45:06

非常漂亮,看起来很像我的素描。我认为电池连接器使用的是低降稳压器,但这仍然会消耗毫安。因为我目前正在评估一个测试替代方案:你有没有尝试过用GND/3V3连接器直接给电路板供电?使用标准的3.7V LiPo电池和一些合适的肖特基二极管来产生约0.2V的电压降,即使在充满电池的情况下,也可以很好地保持在3.6V以下。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56548700

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档