Enable Lora SX1278 wakeup pin for ESP32CAM

Hi,
I'm using the SX127XLT library to using the LORA SX1278 module and image transferring . As far as I know, in the LORA module, using DIO0, a wake-up source can be used when receiving a message. I have used ESP pin 14 to wake up ESP32CAM and receiving data. But when the transmitter sends a message, there is no change in pin 14 level to wake up the board. please guide me.
The code I use to wake up the board is as follows. The module settings are as follows:

settings.h file:

/*******************************************************************************************************
  Programs for Arduino - Copyright of the author Stuart Robinson - 20/03/22

  This program is supplied as is, it is up to the user of the program to decide if the program is
  suitable for the intended purpose and free from errors.
*******************************************************************************************************/

#define NSS 12                //select on LoRa device
#define NRESET 15             //reset pin on LoRa device
#define SCK 4                 //SCK on SPI3
#define MISO 13               //MISO on SPI3 
#define MOSI 2                //MOSI on SPI3
#define REDLED 33             //pin number for ESP32CAM on board red LED, set logic level low for on
#define IRQPIN 14  //ASD 

#define LORA_DEVICE DEVICE_SX1278               //this is the device we are using

//*******  Setup LoRa modem parameters here ! ***************
const uint32_t Frequency = 434000000;           //frequency of transmissions in hertz
const uint32_t Offset = 0;                      //offset frequency for calibration purposes

const uint8_t Bandwidth = LORA_BW_500;          //LoRa bandwidth
const uint8_t SpreadingFactor = LORA_SF7;       //LoRa spreading factor
const uint8_t CodeRate = LORA_CR_4_5;           //LoRa coding rate
const uint8_t Optimisation = LDRO_AUTO;         //low data rate optimisation setting, normally set to auto

const int8_t TXpower = 15;                      //LoRa transmit power in dBm

const uint32_t TXtimeoutmS = 5000;              //mS to wait for TX to complete
const uint32_t RXtimeoutmS = 3000000;           //mS to wait for receiving a packet
const uint32_t ACKdelaymS = 0;                  //ms delay after general packet actioned and ack sent
const uint32_t ACKdelaystartendmS = 25;         //ms delay before ack sent at array start wrie and end write
const uint32_t ACKsegtimeoutmS = 75;            //mS to wait for receiving an ACK before re-trying transmit segment
const uint32_t ACKopentimeoutmS = 250;          //mS to wait for receiving an ACK before re-trying transmit file open
const uint32_t ACKclosetimeoutmS = 250;         //mS to wait for receiving an ACK before re-trying transmit file close
const uint32_t DuplicatedelaymS = 25;           //ms delay if there has been an duplicate segment or command receipt
const uint32_t NoAckCountLimit = 250;           //if no NoAckCount exceeds this value - restart transfer

const uint32_t FunctionDelaymS = 0;             //delay between functions such as open file, send segments etc
const uint32_t PacketDelaymS = 1000;            //mS delay between transmitted packets such as DTInfo etc

const uint32_t ReceiveTimeoutmS = 60000;        //mS waiting for array transfer before timeout
const uint8_t HeaderSizeMax = 12;               //max size of header in bytes, minimum size is 6 bytes
const uint8_t DataSizeMax = 245;                //max size of data array in bytes
const uint8_t ARDTfilenamesize = 32;            //size of DTfilename buffer used by array transfer functions
const uint32_t ARDTarraysize = 0x20000;         //maximum file\array size to receive
const uint16_t NetworkID = 0x3210;              //a unique identifier to go out with packet

const uint8_t StartAttempts = 2;                //number of attempts to start transfer before a fail
const uint8_t SendAttempts = 5;                 //number of attempts carrying out a process before a restart
const uint8_t SegmentSize = 245;                //number of bytes in each segment, 245 is maximum value for LoRa

Reciever Code :

#include <SPI.h>
#include "FS.h"                            //SD Card ESP32
#include "SD_MMC.h"                        //SD Card ESP32
#include "soc/soc.h"                       //disable brownout problems
#include "soc/rtc_cntl_reg.h"              //disable brownout problems
#include "driver/rtc_io.h"
#include <SX127XLT.h>                      //SX12XX-LoRa library
#include <ProgramLT_Definitions.h>         //part of SX12XX-LoRa library
#include "Settings.h"                      //LoRa settings etc.

#define ENABLEMONITOR                      //enable this define to monitor data transfer information, needed for ARtransferIRQ.h
#define ENABLEARRAYCRC                     //enable this define to check and print CRC of sent array                   
#define PRINTSEGMENTNUM                    //enable this define to print segment numbers during data transfer
//#define DISABLEPAYLOADCRC                //enable this define if you want to disable payload CRC checking
//#define DEBUG                            //enable more detail of transfer progress


SX127XLT LoRa;                             //create an SX127XLT library instance called LoRa
#include <ARtransferIRQ.h>

uint8_t *PSRAMptr;                         //create a global pointer to the array to send, so all functions have access
bool SDOK;
bool savedtoSDOK;


void loop()
{
  uint32_t arraylength;
  SDOK = false;
  Serial.println(F("LoRa file transfer receiver ready"));
  setupLoRaDevice();

  delay(3000);
  digitalWrite(NSS, LOW);
  delay(100);
  esp_sleep_enable_ext0_wakeup(GPIO_NUM_14,1); //1 = High, 0 = Low
  Serial.println("Going to sleep now");
  esp_deep_sleep_start();


  
}


bool setupLoRaDevice()
{
  SPI.begin(SCK, MISO, MOSI, NSS);

  if (LoRa.begin(NSS, NRESET,IRQPIN, LORA_DEVICE))
  {
    Serial.println(F("LoRa device found"));
  }
  else
  {
    Serial.println(F("LoRa Device error"));
    return false;
  }

  LoRa.setupLoRa(Frequency, Offset, SpreadingFactor, Bandwidth, CodeRate, Optimisation);

#ifdef DISABLEPAYLOADCRC
  LoRa.setReliableConfig(NoReliableCRC);
#endif

  if (LoRa.getReliableConfig(NoReliableCRC))
  {
    Serial.println(F("Payload CRC disabled"));
  }
  else
  {
    Serial.println(F("Payload CRC enabled"));
  }
  return true;
}




void led_Flash(uint16_t flashes, uint16_t delaymS)
{
  uint16_t index;
  for (index = 1; index <= flashes; index++)
  {
    digitalWrite(REDLED, HIGH);
    delay(delaymS);
    digitalWrite(REDLED, LOW);
    delay(delaymS);
  }
}


void setup()
{
  uint32_t available_PSRAM_size;
  uint32_t new_available_PSRAM_size;

  //WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);      //disable brownout detector
  pinMode(REDLED, OUTPUT);                       //setup pin as output for indicator LED
  led_Flash(2, 125);                             //two quick LED flashes to indicate program start
  ARsetDTLED(REDLED);                            //setup LED pin for data transfer indicator

  digitalWrite(NSS, HIGH);
  pinMode(NSS, OUTPUT);                          //disable LoRa device for now

  Serial.begin(115200);  
  Serial.println();
  Serial.println(__FILE__);

  if (psramInit())
  {
    Serial.println("PSRAM is correctly initialised");
    available_PSRAM_size = ESP.getFreePsram();
    Serial.println((String)"PSRAM Size available: " + available_PSRAM_size);
  }
  else
  {
    Serial.println("PSRAM not available");
    while (1);
  }

  Serial.println("Allocate array in PSRAM");
  uint8_t *byte_array = (uint8_t *) ps_malloc(ARDTarraysize * sizeof(uint8_t));
  PSRAMptr = byte_array;                              //save the pointe to byte_array to global pointer

  new_available_PSRAM_size = ESP.getFreePsram();
  Serial.println((String)"PSRAM Size available: " + new_available_PSRAM_size);
  Serial.print("PSRAM array bytes allocated: ");
  Serial.println(available_PSRAM_size - new_available_PSRAM_size);
  Serial.println();

 
 Serial.println("Hi .......... ..");
 setupLoRaDevice();   
  

}

Which ESP32CAM board are you using?

The AI Thinker board uses GPIO14 for the SD card clock line...
image

If you're using that board there are not many interrupt pins free - you can use GPIO13, but only if you use the SD card in "1-bit" bus mode.

Hi,
I don't use SD Card in ESP32CAM , My problem is DIO0 is not activated when receiving a message to Wake up ESP.

What do you mean?

You have set the interrupt on D14.

Do you realise that when the ESP32 wakes up from sleep it starts again... it does not start from where it went to sleep.

Oi!

External Wake Up (ext0)

This wake up source allows you to use a pin to wake up the ESP32.

The ext0 wake up source option uses RTC GPIOs to wake up. So, RTC peripherals will be kept on during deep sleep if this wake up source is requested.

To use this wake up source, you use the following function:

esp_sleep_enable_ext0_wakeup(GPIO_NUM_X, level)

This function accepts as first argument the pin you want to use, in this format GPIO_NUM_X, in which X represents the GPIO number of that pin.

The second argument, level, can be either 1 or 0. This represents the state of the GPIO that will trigger wake up.

Note: with this wake up source, you can only use pins that are RTC GPIOs.

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/gpio.html

Hi red_car,
I first defined GPIO_NUM_14 to wake up the micro. After I found that the micro does not wake up, I changed pin 14 as an ADC to make sure that the voltage level of DIO0 changes when the message arrives, but no change in the voltage level was occurred.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.