xreef / EByte_LoRa_E220_Series_Library

Arduino LoRa EBYTE E220 LLCC68 device library complete and tested with Arduino, esp8266, esp32, STM32 and Raspberry Pi Pico (rp2040 boards)..
https://www.mischianti.org/category/my-libraries/lora-e220-llcc68-devices/
Other
94 stars 24 forks source link

Transmission does not work on UART_BPS greater 9600 #17

Open jiargei opened 1 year ago

jiargei commented 1 year ago

I tried to set different UART_BPS rates. It works fine as long as the UART_BPS is not greater than 9600 Baud rate! Do I miss something here?

TTL UART baud rate(bps) Constant value
1200 UART_BPS_1200 (works)
2400 UART_BPS_2400 (works)
4800 UART_BPS_4800 (works)
9600 (default) UART_BPS_9600 (works)
19200 UART_BPS_19200 (doesn't work)
38400 UART_BPS_38400 (doesn't work)

Here is the code i'm using. I just combined the examples 01_setConfiguration and 05_sendFixedTransmissionStructure.

What I'm doing wrong?

/*
   EBYTE LoRa E220
   send a structured message to the device that have ADDH ADDL CHAN -> 0 DESTINATION_ADDL 23

   write the int humidity value on serial (or reset device that send default message)

   You must configure 2 device: one as SENDER (with FIXED SENDER config) and uncomment the relative
   define with the correct DESTINATION_ADDL, and one as RECEIVER (with FIXED RECEIVER config)
   and uncomment the relative define with the correct DESTINATION_ADDL.

   Write a string on serial monitor or reset to resend default value.

   Pay attention e220 support RSSI, if you want use that functionality you must enable RSSI on configuration
   configuration.TRANSMISSION_MODE.enableRSSI = RSSI_ENABLED;

   and uncomment #define ENABLE_RSSI true in this sketch

   You must uncommend the correct constructor and set the correct AUX_PIN define.

   by Renzo Mischianti <https://www.mischianti.org>

   https://www.mischianti.org

   E220       ----- WeMos D1 mini   ----- esp32         ----- Arduino Nano 33 IoT   ----- Arduino MKR   ----- Raspberry Pi Pico   ----- stm32               ----- ArduinoUNO
   M0         ----- D7 (or GND)     ----- 19 (or GND)   ----- 4 (or GND)            ----- 2 (or GND)    ----- 10 (or GND)         ----- PB0 (or GND)        ----- 7 Volt div (or GND)
   M1         ----- D6 (or GND)     ----- 21 (or GND)   ----- 6 (or GND)            ----- 4 (or GND)    ----- 11 (or GND)         ----- PB10 (or GND)       ----- 6 Volt div (or GND)
   TX         ----- D3 (PullUP)     ----- TX2 (PullUP)  ----- TX1 (PullUP)          ----- 14 (PullUP)   ----- 8 (PullUP)          ----- PA2 TX2 (PullUP)    ----- 4 (PullUP)
   RX         ----- D4 (PullUP)     ----- RX2 (PullUP)  ----- RX1 (PullUP)          ----- 13 (PullUP)   ----- 9 (PullUP)          ----- PA3 RX2 (PullUP)    ----- 5 Volt div (PullUP)
   AUX        ----- D5 (PullUP)     ----- 18  (PullUP)  ----- 2  (PullUP)           ----- 0  (PullUP)   ----- 2  (PullUP)         ----- PA0  (PullUP)       ----- 3 (PullUP)
   VCC        ----- 3.3v/5v         ----- 3.3v/5v       ----- 3.3v/5v               ----- 3.3v/5v       ----- 3.3v/5v             ----- 3.3v/5v             ----- 3.3v/5v
   GND        ----- GND             ----- GND           ----- GND                   ----- GND           ----- GND                 ----- GND                 ----- GND

*/

// If you want use RSSI uncomment //#define ENABLE_RSSI true
// and use relative configuration with RSSI enabled
//#define ENABLE_RSSI true

#define LoRa_E220_DEBUG 1
#define E220_22
#define FREQUENCY_868

#include "Arduino.h"
#include "LoRa_E220.h"

#define DESTINATION_ADDL_RCV 3
#define DESTINATION_ADDL_SND 2
#define DESTINATION_CHAN 23

// With FIXED SENDER configuration
//#define DESTINATION_ADDL 3
// With FIXED RECEIVER configuration
#define DESTINATION_ADDL 2

const int ASBRU_LORA_MSG_SIZE = 120; 

char ASBRU_LORA_MSG_TYPE = 'A';

struct Message {
  char type;
  char body[ASBRU_LORA_MSG_SIZE];
};

// ---------- esp8266 pins --------------
#include <SoftwareSerial.h>
SoftwareSerial mySerial(4, 5); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX
LoRa_E220 e220ttl(&mySerial, 14, 12, 13 ); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX AUX M0 M1
// -------------------------------------------------

char chunk[ASBRU_LORA_MSG_SIZE];

void printParameters(struct Configuration configuration);
void printModuleInformation(struct ModuleInformation moduleInformation);

void setup() {

  Serial.begin(19200);
  Serial.setTimeout(100);
  delay(500);

  // Startup all pins and UART
  e220ttl.begin();

  ResponseStructContainer c;
  c = e220ttl.getConfiguration();
  // It's important get configuration pointer before all other operation
  Configuration configuration = *(Configuration*) c.data;
  Serial.println(c.status.getResponseDescription());
  Serial.println(c.status.code);

  printParameters(configuration);

  //  ----------------------- FIXED SENDER -----------------------
  if (DESTINATION_ADDL == DESTINATION_ADDL_RCV) {
    Serial.println("Configuring Sender");
    configuration.ADDL = DESTINATION_ADDL_SND;
  }
  //  ----------------------- FIXED RECEIVER -----------------------
  if (DESTINATION_ADDL == DESTINATION_ADDL_SND) {
    Serial.println("Configuring Receiver");
    configuration.ADDL = DESTINATION_ADDL_RCV;
  }
  configuration.ADDH = 0x00;

  configuration.CHAN = DESTINATION_CHAN;

  configuration.SPED.uartBaudRate = UART_BPS_38400;
  configuration.SPED.airDataRate = AIR_DATA_RATE_101_192;
  configuration.SPED.uartParity = MODE_00_8N1;

  configuration.OPTION.subPacketSetting = SPS_128_01;
  configuration.OPTION.RSSIAmbientNoise = RSSI_AMBIENT_NOISE_DISABLED;
  configuration.OPTION.transmissionPower = POWER_22;

#ifdef ENABLE_RSSI
  configuration.TRANSMISSION_MODE.enableRSSI = RSSI_ENABLED;
#else
  configuration.TRANSMISSION_MODE.enableRSSI = RSSI_DISABLED;
#endif
  configuration.TRANSMISSION_MODE.fixedTransmission = FT_FIXED_TRANSMISSION;
  configuration.TRANSMISSION_MODE.enableLBT = LBT_DISABLED;
  configuration.TRANSMISSION_MODE.WORPeriod = WOR_2000_011;

  e220ttl.setConfiguration(configuration, WRITE_CFG_PWR_DWN_SAVE);
  c.close();

  printParameters(configuration);

  Serial.println("Hi, I'm going to send message!");

  struct Message message = {'T', "HELLO"};

  // Send message
  ResponseStatus rs = e220ttl.sendFixedMessage(0, DESTINATION_ADDL, DESTINATION_CHAN, &message, sizeof(Message));
  // Check If there is some problem of succesfully send
  Serial.println(rs.getResponseDescription());
}

void loop() {
  // If something available
  if (e220ttl.available() > 1) {
    // read the String message
#ifdef ENABLE_RSSI
    ResponseStructContainer rsc = e220ttl.receiveMessageRSSI(sizeof(Message));
#else
    ResponseStructContainer rsc = e220ttl.receiveMessage(sizeof(Message));
#endif

    // Is something goes wrong print error
    if (rsc.status.code != 1) {
      Serial.println(rsc.status.getResponseDescription());
    } else {
      // Print the data received
      // Serial.println(rsc.status.getResponseDescription());
      struct Message message = *(Message*) rsc.data;
      //Serial.println(message.type);
      Serial.print(message.body);
#ifdef ENABLE_RSSI
      Serial.print("RSSI: ");
      Serial.println(rsc.rssi, DEC);
#endif
    }
  }
  if (Serial.available()) {
    memset(&(chunk[0]), 0, ASBRU_LORA_MSG_SIZE);
    int chunk_size = Serial.readBytes(chunk, ASBRU_LORA_MSG_SIZE);
    struct Message message = {};
    message.type = 'X';
    memcpy(message.body, chunk, chunk_size + 1);

    // Send message
    ResponseStatus rs = e220ttl.sendFixedMessage(0, DESTINATION_ADDL, DESTINATION_CHAN, &message, sizeof(Message));
    if (rs.code != 1) {
      // Check If there is some problem of succesfully send
      Serial.println(rs.getResponseDescription());
    }
  }
}

void printParameters(struct Configuration configuration) {
  DEBUG_PRINTLN("----------------------------------------");

  DEBUG_PRINT(F("HEAD : "));  DEBUG_PRINT(configuration.COMMAND, HEX); DEBUG_PRINT(" "); DEBUG_PRINT(configuration.STARTING_ADDRESS, HEX); DEBUG_PRINT(" "); DEBUG_PRINTLN(configuration.LENGHT, HEX);
  DEBUG_PRINTLN(F(" "));
  DEBUG_PRINT(F("AddH : "));  DEBUG_PRINTLN(configuration.ADDH, HEX);
  DEBUG_PRINT(F("AddL : "));  DEBUG_PRINTLN(configuration.ADDL, HEX);
  DEBUG_PRINTLN(F(" "));
  DEBUG_PRINT(F("Chan : "));  DEBUG_PRINT(configuration.CHAN, DEC); DEBUG_PRINT(" -> "); DEBUG_PRINTLN(configuration.getChannelDescription());
  DEBUG_PRINTLN(F(" "));
  DEBUG_PRINT(F("SpeedParityBit     : "));  DEBUG_PRINT(configuration.SPED.uartParity, BIN); DEBUG_PRINT(" -> "); DEBUG_PRINTLN(configuration.SPED.getUARTParityDescription());
  DEBUG_PRINT(F("SpeedUARTDatte     : "));  DEBUG_PRINT(configuration.SPED.uartBaudRate, BIN); DEBUG_PRINT(" -> "); DEBUG_PRINTLN(configuration.SPED.getUARTBaudRateDescription());
  DEBUG_PRINT(F("SpeedAirDataRate   : "));  DEBUG_PRINT(configuration.SPED.airDataRate, BIN); DEBUG_PRINT(" -> "); DEBUG_PRINTLN(configuration.SPED.getAirDataRateDescription());
  DEBUG_PRINTLN(F(" "));
  DEBUG_PRINT(F("OptionSubPacketSett: "));  DEBUG_PRINT(configuration.OPTION.subPacketSetting, BIN); DEBUG_PRINT(" -> "); DEBUG_PRINTLN(configuration.OPTION.getSubPacketSetting());
  DEBUG_PRINT(F("OptionTranPower    : "));  DEBUG_PRINT(configuration.OPTION.transmissionPower, BIN); DEBUG_PRINT(" -> "); DEBUG_PRINTLN(configuration.OPTION.getTransmissionPowerDescription());
  DEBUG_PRINT(F("OptionRSSIAmbientNo: "));  DEBUG_PRINT(configuration.OPTION.RSSIAmbientNoise, BIN); DEBUG_PRINT(" -> "); DEBUG_PRINTLN(configuration.OPTION.getRSSIAmbientNoiseEnable());
  DEBUG_PRINTLN(F(" "));
  DEBUG_PRINT(F("TransModeWORPeriod : "));  DEBUG_PRINT(configuration.TRANSMISSION_MODE.WORPeriod, BIN); DEBUG_PRINT(" -> "); DEBUG_PRINTLN(configuration.TRANSMISSION_MODE.getWORPeriodByParamsDescription());
  DEBUG_PRINT(F("TransModeEnableLBT : "));  DEBUG_PRINT(configuration.TRANSMISSION_MODE.enableLBT, BIN); DEBUG_PRINT(" -> "); DEBUG_PRINTLN(configuration.TRANSMISSION_MODE.getLBTEnableByteDescription());
  DEBUG_PRINT(F("TransModeEnableRSSI: "));  DEBUG_PRINT(configuration.TRANSMISSION_MODE.enableRSSI, BIN); DEBUG_PRINT(" -> "); DEBUG_PRINTLN(configuration.TRANSMISSION_MODE.getRSSIEnableByteDescription());
  DEBUG_PRINT(F("TransModeFixedTrans: "));  DEBUG_PRINT(configuration.TRANSMISSION_MODE.fixedTransmission, BIN); DEBUG_PRINT(" -> "); DEBUG_PRINTLN(configuration.TRANSMISSION_MODE.getFixedTransmissionDescription());

  DEBUG_PRINTLN("----------------------------------------");
}

void printModuleInformation(struct ModuleInformation moduleInformation) {
  Serial.println("----------------------------------------");
  DEBUG_PRINT(F("HEAD: "));  DEBUG_PRINT(moduleInformation.COMMAND, HEX); DEBUG_PRINT(" "); DEBUG_PRINT(moduleInformation.STARTING_ADDRESS, HEX); DEBUG_PRINT(" "); DEBUG_PRINTLN(moduleInformation.LENGHT, DEC);

  Serial.print(F("Model no.: "));  Serial.println(moduleInformation.model, HEX);
  Serial.print(F("Version  : "));  Serial.println(moduleInformation.version, HEX);
  Serial.print(F("Features : "));  Serial.println(moduleInformation.features, HEX);
  Serial.println("----------------------------------------");

}
CcKefa commented 8 months ago

Hello, at least for e220 900T30D it's recommended to have same baud rates across the devices. Have you tried matching your Serial baud rate as well as the baud rate from the recieving end?

xreef commented 8 months ago

Hi, the configuration works only at 9600; you must split the sketch in 2. Bye Renzo