Site icon Renzo Mischianti

EByte LoRa e32 not working on esp32: sends a random number, the other reads

Hello, I can't get my LoRa e32 modules working. I have developed two sketch. One of them generates and sends a random number. The other reads the packet sent by writer. I am working with ESP32. Thanks in advance for your advice. Sketch A, write

#include "Arduino.h"
#define E32_TTL_1W
#define FREQUENCY_915
#include 
#include 


#define RX 16
#define TX 17
#define M0 35
#define M1 32

HardwareSerial serial1(2);

LoRa_E32 e32ttl1w(&serial1,RX,TX, UART_BPS_RATE_9600,SERIAL_8N1);
void printParameters(struct Configuration configuration);
void printModuleInformation(struct ModuleInformation moduleInformation);

// Variables globales
unsigned long interval = 15000;          // interval between sends
unsigned long lastSendTime = 0;        // last send time
byte msgCount = 0;            // count of outgoing messages
long randNumber;
void setup() {

  pinMode(M0, OUTPUT);
  pinMode(M1, OUTPUT);
  
  //Inicio comunicacion serie con monitor
  Serial.begin(9600);
  delay(500);
  
  // Establezco M0 y M1 en alto para configurar LoRa
  digitalWrite(M0, HIGH);
  digitalWrite(M1, HIGH);


// Startup all pins and UART
	e32ttl1w.begin();
  //Configuro el nodo LoRa
  nodeConfig();

  // Establezco M0 y M1 en bajo para trabajar con LoRa
  digitalWrite(M0, LOW);
  digitalWrite(M1, LOW);
}

void loop() {
  // Wait a few seconds between measurements.
  
  if (millis() - lastSendTime > interval) {
    // print a random number from 10 to 19
    randNumber = random(10, 20);
    String trama = String(randNumber);
    e32ttl1w.sendFixedMessage(0, 3, 0x10,trama);
    Serial.println("Sending " + trama);
    lastSendTime = millis();            // timestamp the message
    msgCount++;
  }
  delay(100);
}

void nodeConfig(){
  
  ResponseStructContainer c;
  ModuleInformation modInfo;
  c = e32ttl1w.getConfiguration();
  Configuration configuration = *(Configuration*) c.data;

  configuration.ADDH        = 0x0;
  configuration.ADDL        = 0x1;
  configuration.CHAN        = 0x10;
    
  configuration.SPED.airDataRate           = AIR_DATA_RATE_010_24;
  configuration.SPED.uartBaudRate          = UART_BPS_1200;
  configuration.SPED.uartParity            = MODE_00_8N1;
  configuration.OPTION.fec                 = FEC_0_OFF;
  configuration.OPTION.fixedTransmission   = FT_TRANSPARENT_TRANSMISSION;
  configuration.OPTION.ioDriveMode         = IO_D_MODE_PUSH_PULLS_PULL_UPS;
  configuration.OPTION.transmissionPower   = POWER_30;
  configuration.OPTION.wirelessWakeupTime  = WAKE_UP_1250;
  //printParameters(configuration);

// Set configuration changed and set to not hold the configuration
  ResponseStatus rs = e32ttl1w.setConfiguration(configuration, WRITE_CFG_PWR_DWN_LOSE);
}
Sketch B

#include "Arduino.h"
#define E32_TTL_1W
#define FREQUENCY_915
#include 
#include 



#define RX 16
#define TX 17
#define M0 35
#define M1 32

HardwareSerial lora(2);
LoRa_E32 e32ttl1w(&lora,RX,TX, UART_BPS_RATE_9600,SERIAL_8N1);

void setup() {

  pinMode(M0, OUTPUT);
  pinMode(M1, OUTPUT);
 
  
  //Inicio comunicacion serie con monitor
  Serial.begin(9600);
  delay(500);
  
  // Establezco M0 y M1 en alto para configurar LoRa
  digitalWrite(M0, HIGH);
  digitalWrite(M1, HIGH);
  
// Startup all pins and UART
	e32ttl1w.begin();
  //Configuro el nodo LoRa
  nodeConfig();

  // Establezco M0 y M1 en bajo para trabajar con LoRa
  digitalWrite(M0, LOW);
  digitalWrite(M1, LOW);
}

void loop() {
  
  if (e32ttl1w.available() > 0) {
    Serial.println("----------");
    ResponseContainer rc = e32ttl1w.receiveMessage();
    Serial.println(rc.data);
    // Is something goes wrong print error
    if (rc.status.code != 1) {
      rc.status.getResponseDescription();
    } else {
    // Print the data received
      Serial.println(rc.data);
    }
  }
  delay(500);
}

void nodeConfig(){
  
  ResponseStructContainer c;
  c = e32ttl1w.getConfiguration();
  Configuration configuration = *(Configuration*) c.data;

    configuration.ADDH        = 0x0;
    configuration.ADDL        = 0x3;
    configuration.CHAN        = 0x10;
    
    configuration.SPED.airDataRate           = AIR_DATA_RATE_010_24;
    configuration.SPED.uartBaudRate          = UART_BPS_1200;
    configuration.SPED.uartParity            = MODE_00_8N1;
    configuration.OPTION.fec                 = FEC_0_OFF;
    configuration.OPTION.fixedTransmission   = FT_TRANSPARENT_TRANSMISSION;
    configuration.OPTION.ioDriveMode         = IO_D_MODE_PUSH_PULLS_PULL_UPS;
    configuration.OPTION.transmissionPower   = POWER_30;
    configuration.OPTION.wirelessWakeupTime  = WAKE_UP_1250;

  //printParameters(configuration);

// Set configuration changed and set to not hold the configuration
  ResponseStatus rs = e32ttl1w.setConfiguration(configuration, WRITE_CFG_PWR_DWN_LOSE);

}
Exit mobile version