Ebyte LoRa E32 device for Arduino, esp32 or esp8266: library – 2

Spread the love

I created a library to manage EBYTE E32 based on the Semtech series of LoRa devices, a potent, simple, and cheap device.

LoRa E32-TTL-100

You can find here AliExpress (433MHz 5Km) - AliExpress (433MHz 8Km) - AliExpress (433MHz 16Km) - AliExpress (868MHz 915MHz 5.5Km) - AliExpress (868MHz 915MHz 8Km)

They can work over a distance of 3000m to 8000m, and they have many features and parameters.

So I create this library to simplify the usage.

Library

You can find my library here.

And It’s available on Arduino IDE library manager.

EByte LoRa E22 E32 Arduino library manager
EByte LoRa E22 E32 Arduino library manager

To download.

Click the DOWNLOADS button in the top right corner rename the uncompressed folder LoRa_E32.

Check that the LoRa_E32 folder contains LoRa_E32.cpp and LoRa_E32.h.

Place the LoRa_E32 library folder in your /libraries/ folder.

You may need to create the libraries subfolder if it’s your first library.

Restart the IDE.

Pinout

sx1278 sx1276 wireless lora uart module serial 3000m arduino 433 rf
Pin No.Pin itemPin directionPin application
1M0Input(weak pull-up)Work with M1 & decide the four operating modes. Floating is not allowed. It can be ground.
2M1Input(weak pull-up)Work with M0 & decide the four operating modes. Floating is not allowed. It can be ground.
3RXDInputTTL UART inputs, connect to external (MCU, PC) TXD output pin. It can be configured as open-drain or pull-up input.
4TXDOutputTTL UART outputs, connect to external RXD (MCU, PC) input pin. Can be configured as open-drain or push-pull output

5

AUX

Output
To indicate the module’s working status & wake up the external MCU. During the procedure of self-check initialization, the pin outputs a low level. It can be configured as open-drain or push-pull output (floating is allowed). If you have trouble with the device’s freezeyou must put a pull-up 4.7k resistor or better connect to the device.
6VCCPower supply 2.3V~5.5V DC
7GNDGround

As you can see, you can set various modes via M0 and M1 pins.

ModeM1M0Explanation
Normal00UART and the wireless channel is good to go
Wake-Up01Same as standard, but a preamble code is added to transmitted data for waking up the receiver.
Power-Saving10UART is disabled, and wireless is on WOR(wake on radio) mode, which means the device will turn on when data is received. Transmission is not allowed.
Sleep11Used in setting parameters. Transmitting and receiving are disabled.

Some pins can be used statically, but If you connect Them to the microcontroller and configure them in the library, you gain in performance, and you can control all modes via software, but we will explain better next.

Fully connected schema

As I already said, It’s not essential to connect all pins to the output of the microcontroller, you can put M0 and M1 pins to HIGH or LOW to get the desired configuration, and if you don’t connect AUX, the library sets a reasonable delay to be sure that the operation is complete (If you have trouble like freeze device, you must put a pull-up 4.7k resistor or better connect to the device. ).

AUX pin

When transmitting data can be used to wake up external MCU and return HIGH on data transfer finish.

LoRa E32 AUX Pin on transmission

When receiving, AUX goes LOW and returns HIGH when the buffer is empty.

LoRa e32 AUX pin on reception

It’s also used for self-checking to restore regular operation (on power-on and sleep/program mode).

LoRa e32 AUX pin on self-check

esp8266 connection schema is more straightforward because It works at the same voltage of logical communications (3.3v).

LoRa E32 TTL 100 Wemos D1 fully connected.

It’s essential to add a pull-up resistor (4,7Kohm) to get good stability.

M0D7
M1D6
TXPIN D2 (PullUP 4,7KΩ)
RXPIN D3 (PullUP 4,7KΩ)
AUXD5 (Input)
VCC5v (or 3.3v but less power)
GNDGND

Arduino’s working voltage is 5v, so we need to add a voltage divider on RX pin M0 and M1 of the LoRa module to prevent damage. You can get more information here Voltage divider: calculator and application.

You can use a 2Kohm resistor to GND and 1Kohm from the signal, then put it together on RX.

LoRa E32 TTL 100 Arduino fully connected
M07 (Voltage divider)
M16 (Voltage divider)
TXPIN 2 (PullUP 4,7KΩ)
RXPIN 3 (PullUP 4,7KΩ & Voltage divider)
AUX5 (Input)
VCC5v
GNDGND
Ebyte LoRa E22 device esp32 dev kit v1 breadboard full connection
Ebyte LoRa E22 device esp32 dev kit v1 breadboard full connection
M0D21
M1D19
TXPIN RX2 (PullUP 4,7KΩ)
RXPIN TX3 (PullUP 4,7KΩ)
AUXPIN D18 (PullUP 4,7KΩ) (D15 to wake up)
VCC5V (but work with less power in 3.3v)
GNDGND
Ebyte LoRa Exx Arduino MKR WiFi 1010 Fully connected breadboard
Ebyte LoRa Exx Arduino MKR WiFi 1010 Fully connected breadboard
M02 (voltage divider)
M13 (voltage divider)
TXPIN 14 Tx (PullUP 4,7KΩ)
RXPIN 13 Rx (PullUP 4,7KΩ)
AUXPIN 1 (PullUP 4,7KΩ)
VCC5V
GNDGND

Constructor

I made a set of numerous constructors because we can have more options and situations to manage.

		LoRa_E32(byte txE32pin, byte rxE32pin, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600);
		LoRa_E32(byte txE32pin, byte rxE32pin, byte auxPin, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600);
		LoRa_E32(byte txE32pin, byte rxE32pin, byte auxPin, byte m0Pin, byte m1Pin, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600);

The first set of constructors is created to delegate Serial and other pins to the library.

  • txE32pin and rxE32pin is the pin to connect to UART and they are mandatory.
  • auxPin is a pin that check the operation, transmission and receiving status (we are going to explain better next), that pin It isn’t mandatory, if you don’t set It I apply a delay to permit the operation to complete itself (with latency, if you have trouble, like freeze device, you must put a pull-up 4.7k resistor or better connect to the device ).
  • m0pin and m1Pin are the pins to change operation MODE (see the table upper), I think this pins in “production” are going to connect directly HIGH or LOW, but for test they are usefully to be managed by the library.
  • bpsRate is the boudrate of SoftwareSerial normally is 9600 (the only baud rate in programmin/sleep mode)

A simple example is

#include "LoRa_E32.h"

LoRa_E32 e32ttl100(2, 3);  // e32 TX e32 RX
// LoRa_E32 e32ttl100(2, 3, 5, 6, 7);  // e32 TX e32 RX

We can use a SoftwareSerial directly with another constructor

		LoRa_E32(HardwareSerial* serial, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600);
		LoRa_E32(HardwareSerial* serial, byte auxPin, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600);
		LoRa_E32(HardwareSerial* serial, byte auxPin, byte m0Pin, byte m1Pin, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600);

The example upper with this constructor can be done like so.

#include <SoftwareSerial.h>
#include "LoRa_E32.h"

SoftwareSerial mySerial(2, 3); // e32 TX e32 RX
LoRa_E32 e32ttl100(&mySerial);
// LoRa_E32 e32ttl100(&mySerial, 5, 7, 6);

The last set of constructors permits using an HardwareSerial instead of SoftwareSerial.

		LoRa_E32(SoftwareSerial* serial, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600);
		LoRa_E32(SoftwareSerial* serial, byte auxPin, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600);
		LoRa_E32(SoftwareSerial* serial, byte auxPin, byte m0Pin, byte m1Pin, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600);

For esp32, you have three additional constructors to permit to manage pins for HardWare serial.

			LoRa_E32(byte txE32pin, byte rxE32pin, HardwareSerial* serial, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600, uint32_t serialConfig = SERIAL_8N1);
			LoRa_E32(byte txE32pin, byte rxE32pin, HardwareSerial* serial, byte auxPin, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600, uint32_t serialConfig = SERIAL_8N1);
			LoRa_E32(byte txE32pin, byte rxE32pin, HardwareSerial* serial, byte auxPin, byte m0Pin, byte m1Pin, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600, uint32_t serialConfig = SERIAL_8N1);

Breaking change on esp32 constructor for managed HardwareSerial pins, now reference of HardwareSerial is after the pins to remove ambiguous constructors.

Begin

The begin command is used to startup Serial and pins in input and output mode.

void begin();

in execution is

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

Configuration and information method

There are many methods for managing configuration and getting information about the device.

		ResponseStructContainer getConfiguration();
		ResponseStatus setConfiguration(Configuration configuration, PROGRAM_COMMAND saveType = WRITE_CFG_PWR_DWN_LOSE);

		ResponseStructContainer getModuleInformation();
        void printParameters(struct Configuration configuration);
        ResponseStatus resetModule();

Response container

To simplify response management, I created a set of containers that usefully manage errors and return generic data.

ResponseStatus

This is a status container with two simple entry points; you can get the status code and the description of the status code.

	Serial.println(c.getResponseDescription()); // Description of code
	Serial.println(c.code); // 1 if Success

The code is

  SUCCESS = 1,
  ERR_UNKNOWN,
  ERR_NOT_SUPPORT,
  ERR_NOT_IMPLEMENT,
  ERR_NOT_INITIAL,
  ERR_INVALID_PARAM,
  ERR_DATA_SIZE_NOT_MATCH,
  ERR_BUF_TOO_SMALL,
  ERR_TIMEOUT,
  ERR_HARDWARE,
  ERR_HEAD_NOT_RECOGNIZED
ResponseContainer

This container is created to manage String response and has two entry points.

data with the string returned from the message and status an instance of RepsonseStatus.

		ResponseContainer rs = e32ttl.receiveMessage();
		String message = rs.data;

		Serial.println(rs.status.getResponseDescription());
		Serial.println(message);
ResponseStructContainer

This is the more “complex” container. I use this to manage structure, It has the same entry point of ResponseContainer, but data is a void pointer to manage complex structure.

	ResponseStructContainer c;
	c = e32ttl100.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);
        c.close();

Every time you use a ResponseStructContainer you must close It with close()

getConfiguration and setConfiguration

The first method is getConfiguration, and you can use It to retrieve all data stored on the device.

		ResponseStructContainer getConfiguration();

Here is a usage example.

	ResponseStructContainer c;
	c = e32ttl100.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);
        Serial.println(configuration.SPED.getUARTBaudRate());

Structure of configuration have all data of settings, and I add a series of functions to get all description of single data.

	configuration.ADDL = 0x0; // First part of address
	configuration.ADDH = 0x1; // Second part of address
	configuration.CHAN = 0x19;// Channel

	configuration.OPTION.fec = FEC_0_OFF; // Forward error correction switch
	configuration.OPTION.fixedTransmission = FT_TRANSPARENT_TRANSMISSION; // Transmission mode
	configuration.OPTION.ioDriveMode = IO_D_MODE_PUSH_PULLS_PULL_UPS; // Pull-up management
	configuration.OPTION.transmissionPower = POWER_17; // dBm transmission power 
	configuration.OPTION.wirelessWakeupTime = WAKE_UP_1250; // Wait time for wake up

	configuration.SPED.airDataRate = AIR_DATA_RATE_011_48; // Air data rate
	configuration.SPED.uartBaudRate = UART_BPS_115200; // Communication baud rate
	configuration.SPED.uartParity = MODE_00_8N1; // Parity bit

You have the equivalent function for all attributes to get all descriptions:

	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());

In the same way, setConfiguration wants a configuration structure, so I think the better way to manage configuration is to retrieve the current one, apply the only change you need and set It again.

		ResponseStatus setConfiguration(Configuration configuration, PROGRAM_COMMAND saveType = WRITE_CFG_PWR_DWN_LOSE);

configuration is the structure previously shown, saveType permit you to choose if the difference becomes permanent or only for the current session.

	ResponseStructContainer c;
	c = e32ttl100.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);
	configuration.ADDL = 0x0;
	configuration.ADDH = 0x1;
	configuration.CHAN = 0x19;

	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_17;
	configuration.OPTION.wirelessWakeupTime = WAKE_UP_1250;

	configuration.SPED.airDataRate = AIR_DATA_RATE_011_48;
	configuration.SPED.uartBaudRate = UART_BPS_115200;
	configuration.SPED.uartParity = MODE_00_8N1;

	// Set configuration changed and set to not hold the configuration
	ResponseStatus rs = e32ttl100.setConfiguration(configuration, WRITE_CFG_PWR_DWN_LOSE);
	Serial.println(rs.getResponseDescription());
	Serial.println(rs.code);
	printParameters(configuration);

The parameters are all managed as constant:

Basic configuration option

ADDHHigh address byte of the module (the default 00H)00H-FFH
ADDLLow address byte of the module (the default 00H)00H-FFH
SPEDInformation about data rate parity bit and Air data rate
CHANCommunication channel(410M + CHAN*1M), default 17H (433MHz), valid only for 433MHz device check below to check the correct frequency of your device00H-1FH
OPTIONType of transmission, pull-up settings, wake-up time, FEC, Transmission power

SPED detail

UART Parity bit: UART mode can be different between communication parties

7 6 UART parity bit Constant value
008N1 (default)MODE_00_8N1
018O1MODE_01_8O1
108 E1MODE_10_8E1
118N1 (equal to 00)MODE_11_8N1

UART baud rate: UART baud rate can be different between communication parties. The UART baud rate has nothing to do with wireless transmission parameters & won’t affect the wireless transmit/receive features.

543 TTL UART baud rate(bps) Constant value
0001200UART_BPS_1200
0012400UART_BPS_2400
0104800UART_BPS_4800
0119600 (default)UART_BPS_9600
10019200UART_BPS_19200
10138400UART_BPS_38400
11057600UART_BPS_57600
111115200UART_BPS_115200

Air data rate: The lower the air data rate, the longer the transmitting distance, better anti-interference performance, and longer transmitting time; the air data rate must be constant for both communication parties.

210 Air data rate(bps) Constant value
0000.3kAIR_DATA_RATE_000_03
0011.2kAIR_DATA_RATE_001_12
0102.4k (default)AIR_DATA_RATE_010_24
0114.8kAIR_DATA_RATE_011_48
1009.6kAIR_DATA_RATE_100_96
10119.2kAIR_DATA_RATE_101_192
11019.2k (same to 101)AIR_DATA_RATE_110_192
11119.2k (same to 101)AIR_DATA_RATE_111_192

OPTION detail

Transmission mode: The first three bytes of each user’s data frame can be used as high/low address and channel in fixed transmission mode. The module changes its address and channel when transmitted. And it will revert to the original setting after completing the process.

7 Fixed transmission enabling bit(similar to MODBUS) Constant value
0Transparent transmission modeFT_TRANSPARENT_TRANSMISSION
1Fixed transmission modeFT_FIXED_TRANSMISSION

IO drive mode: this bit is used for the module internal pull-up resistor. It also increases the level’s adaptability in case of an open drain. But in some cases, it may need an external pull-up resistor.

6 IO drive mode ( default 1) Constant value
1TXD and AUX push-pull outputs, RXD pull-up inputsIO_D_MODE_PUSH_PULLS_PULL_UPS
0TXD、AUX open-collector outputs, RXD open-collector inputsIO_D_MODE_OPEN_COLLECTOR

Wireless wake-up time: the transmit & receive module work in mode 0, whose delay time is invalid & can be an arbitrary value; the transmitter works in mode one can send the preamble code of the corresponding time continuously when the receiver operates in mode 2, the time means the monitor interval time (wireless wake-up). Only the data from the transmitter that works in mode one can be
received.

543 Wireless wake-up time Constant value
000250ms (default)WAKE_UP_250
001500msWAKE_UP_500
010750msWAKE_UP_750
0111000msWAKE_UP_1000
1001250msWAKE_UP_1250
1011500msWAKE_UP_1500
1101750msWAKE_UP_1750
1112000msWAKE_UP_2000

FEC: after turning off FEC, the actual data transmission rate increases while anti-interference ability decreases. Also, the transmission distance is relatively short, and both communication parties must keep on the same pages about turn-on or turn-off FEC.

2 FEC switch Constant value
0Turn off FECFEC_0_OFF
1Turn on FEC (default)FEC_1_ON

Transmission power

You can change this set of constants by applying a definition like so:

#define E32_TTL_100 // default value without set 

Applicable for E32-TTL-100, E32-TTL-100S1, E32-T100S2.
The external power must make sure the current output ability is more than 250mA and ensure the power supply ripple within 100mV.
Low power transmission is not recommended due to its low power supply
efficiency.

#define E32_TTL_100 // default value without set 
10 Transmission power (approximation) Constant value
0020dBm (default)POWER_20
0117dBmPOWER_17
1014dBmPOWER_14
1110dBmPOWER_10

Applicable for E32-TTL-500。
The external power must make sure the current output ability is more than 700mA and ensure the power supply ripple within 100mV.
Low power transmission is not recommended due to its low power supply efficiency.

#define E32_TTL_500
10 Transmission power (approximation) Constant value
0027dBm (default)POWER_27
0124dBmPOWER_24
1021dBmPOWER_21
1118dBmPOWER_18

Applicable for E32-TTL-1W, E32 (433T30S), E32 (868T30S), E32 (915T30S)
The external power must make sure the current output ability is more than 1A and ensure the power supply ripple within 100mV.
Low power transmission is not recommended due to its low power supply
efficiency.

#define E32_TTL_1W
10 Transmission power (approximation) Constant value
0030dBm (default)POWER_30
0127dBmPOWER_27
1024dBmPOWER_24
1121dBmPOWER_21

You can configure Channel frequency also with this define:

// One of 
#define FREQUENCY_433 
#define FREQUENCY_170
#define FREQUENCY_470
#define FREQUENCY_868
#define FREQUENCY_915

Send receive message

First, we must introduce a simple but usefully method to check if something is in the receiving buffer

int available();

It’s simple to return how many bytes you have in the current stream.

Normal transmission mode

Normal/Transparent transmission mode sends messages to all devices with the same address and channel.

LoRa E32 transmitting scenarios, lines are channels.

There is a lot of methods to send/receive messages, and we are going to explain in detail:

        ResponseStatus sendMessage(const String message);
        ResponseContainer receiveMessage();

The first method is sendMessage and is used to send a String to a device in Normal mode.

	ResponseStatus rs = e32ttl.sendMessage("Prova");
	Serial.println(rs.getResponseDescription());

The other device simply does on the loop.

       if (e32ttl.available()  > 1){
		ResponseContainer rs = e32ttl.receiveMessage();
		String message = rs.data; // First ever get the data
		Serial.println(rs.status.getResponseDescription());
		Serial.println(message);
	}

Pay attention if you receive multiple messages in the buffer, and you don’t want reading all in one time you must use ResponseContainer rs = e32ttl.receiveMessageUntil();

Manage structure

If you wish to send a complex structure, you can use this method

        ResponseStatus sendMessage(const void *message, const uint8_t size);
        ResponseStructContainer receiveMessage(const uint8_t size);

It’s used to send structure, for example:

	struct Messaggione {
		char type[5];
		char message[8];
		bool mitico;
	};
        struct Messaggione messaggione = {"TEMP", "Peple", true};
        ResponseStatus rs = e32ttl.sendMessage(&messaggione, sizeof(Messaggione));
	Serial.println(rs.getResponseDescription());

and the other side, you can receive the message so

		ResponseStructContainer rsc = e32ttl.receiveMessage(sizeof(Messaggione));
		struct Messaggione messaggione = *(Messaggione*) rsc.data;
		Serial.println(messaggione.message);
		Serial.println(messaggione.mitico);
Read partial structure

If you want to read the first part of the message to manage more types of structure, you can use this method.

ResponseContainer receiveInitialMessage(const uint8_t size);

I create It to receive a string with type or other to identify the structure to load.

		struct Messaggione { // Partial strucutre without type
			char message[8];
			bool mitico;
		};

		char type[5]; // first part of structure
		ResponseContainer rs = e32ttl.receiveInitialMessage(sizeof(type));
                // Put string in a char array (not needed)
		memcpy ( type, rs.data.c_str(), sizeof(type) );

		Serial.println("READ TYPE: ");
		Serial.println(rs.status.getResponseDescription());
		Serial.println(type);

                // Read the rest of structure
		ResponseStructContainer rsc = e32ttl.receiveMessage(sizeof(Messaggione));
		struct Messaggione messaggione = *(Messaggione*) rsc.data;

Fixed mode instead of normal mode

In some manner, I create a set of methods to use with fixed transmission

Fixed transmission

You need to change only the sending method because the destination device doesn’t receive the preamble with Address and Channel when setting the fixed mode.

So for the String message, you have

        ResponseStatus sendFixedMessage(byte ADDH, byte ADDL, byte CHAN, const String message);
        ResponseStatus sendBroadcastFixedMessage(byte CHAN, const String message);

and for the structure, you have

        ResponseStatus sendFixedMessage(byte ADDH, byte ADDL, byte CHAN, const void *message, const uint8_t size);
        ResponseStatus sendBroadcastFixedMessage(byte CHAN, const void *message, const uint8_t size );

Here is a simple example

	ResponseStatus rs = e32ttl.sendFixedMessage(0, 0, 0x17, &messaggione, sizeof(Messaggione));
//	ResponseStatus rs = e32ttl.sendFixedMessage(0, 0, 0x17, "Ciao");

Fixed transmission have more scenarios

LoRa E32 transmitting scenarios, lines are channels

If you send to a specific device (second scenario Fixed transmission), you must add ADDL, ADDH, and CHAN to identify It directly.

ResponseStatus rs = e32ttl.sendFixedMessage(2, 2, 0x17, "Message to a device");

If you want to send a message to all devices in a specified Channel, you can use this method.

ResponseStatus rs = e32ttl.sendBroadcastFixedMessage(0x17, "Message to a devices of a channel");

If you wish to receive all broadcast messages in the network, you must set your ADDH and ADDL with BROADCAST_ADDRESS.

        ResponseStructContainer c;
	c = e32ttl100.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);
	configuration.ADDL = BROADCAST_ADDRESS;
	configuration.ADDH = BROADCAST_ADDRESS;

	// Set configuration changed and set to not hold the configuration
	ResponseStatus rs = e32ttl100.setConfiguration(configuration, WRITE_CFG_PWR_DWN_LOSE);
	Serial.println(rs.getResponseDescription());
	Serial.println(rs.code);
	printParameters(configuration);

Thanks

Now you have all information to do your work, but I think It’s important to show some real examples to understand better all the possibilities.

  1. LoRa E32 device for Arduino, esp32 or esp8266: settings and basic usage
  2. LoRa E32 device for Arduino, esp32 or esp8266: library
  3. LoRa E32 device for Arduino, esp32 or esp8266: configuration
  4. LoRa E32 device for Arduino, esp32 or esp8266: fixed transmission
  5. LoRa E32 device for Arduino, esp32 or esp8266: power saving and sending structured data
  6. LoRa E32 device for Arduino, esp32 or esp8266: WOR (wake on radio) microcontroller and Arduino shield
  7. LoRa E32 device for Arduino, esp32 or esp8266: WOR (wake on radio) microcontroller and WeMos D1 shield
  8. EByte LoRa E32 device for Arduino, esp32 or esp8266: WOR (wake on radio) and new ESP32 shield
  9. Ebyte LoRa E32 with STM32: WOR (wake on radio) and new STM32 shield

Github library


Spread the love

30 Responses

  1. Paulo says:

    Hi,

    But HardwareSerial isn’t abstract? I guess it can’t be instantiated.

    • Hi Paulo,
      you can do like so
      LoRa_E32(HardwareSerial* serial, byte rxPin, byte txPin, byte auxPin, byte m0Pin, byte m1Pin, UART_BPS_RATE bpsRate = UART_BPS_RATE_9600, uint32_t serialConfig = SERIAL_8N1);
      #define RX 15
      #define TX 16
      #define AUX 17
      #define M0 18
      #define M1 19

      LoRa_E32 e32ttl100(&Serial1, RX, TX, AUX, M0, M1);

      Bye Renzo

      • Paulo says:

        But I got some errors like:

        error: expected ‘)’ before ‘*’ token

        I already included:

        #include “Arduino.h”

        #include “HardwareSerial.h”
        #include “SoftwareSerial.h”
        #include “LoRa_E32.h”
        #define E32_TTL_1W

        I don’t know how to solve..

  2. Paulo says:

    Ok. Now I think I got it.

    HardwareSerial serial1(2);
    LoRa_E32 e32ttl1w(&serial1, UART_BPS_RATE_9600);

    And connected the E32 to RX2 (GPIO16) and TX2 (GPIO17).

    Thank you for your help and attention!

  3. Tuna says:

    Your rx & tx pins are very confusing. I dont think that the picture and the pinout under it match (at least for arduino). Also in library code example’s headers you say that tx is pin2 but 5 rows below it you initialize it as pin3 (which matches the list here). So i think that at least the pinout picture and code example headers are wrong.

    • Hi Tuna,
      I think It’s true, in some examples rx and tx not match, If you send me an EMail with the fixes you’ve found I’m going to apply them
      Bye Renzo

      • Tuna says:

        okay library problem was my mistake. But i think it is very confusing for lots of people that from which point of view you set te rx/tx pins. I now know that you mean arduino’s rx/tx by looking through your code. Maybe it would be helpful for other people to make the examples (that come with the library) more clear?

        The only real mistake i have found is the pinout for arduino (probably ESP8266 too?) in written form under the pinout picture. E32’s rx should be pin 3 and tx pin 2. You have it swapped. This is wrong referencing to the initialisation you do in the code examples under. (LoRa_E32 e32ttl100(2, 3); // RX, TX –from arduino point of view)

      • Tuna says:

        Actually I just noticed that the aux pin doesn’t match in the picture and the written pinout under it either so I recommend you to go through them and check everything.

  4. Vitor says:

    Hello Renzo

    Do you have an example code including the LoRa E32 with an esp32?, im trying use your library but i’m finding some compilation errors

    Do you have telegram or whatsapp?

    Thanks for read and help

  5. steger123 says:

    Hello Renzo,

    first of all congratulation for the library. Great work ! I wish a lot of people will enjoy the benefit 🙂
    I would like to use a
    868 MHz LoRa SX 1276 RF long range E32-868T30D
    module.

    How can I setup the base frequency and the channels @ 868 MHz.
    I declared this: #define FREQUENCY_868
    but for example how configuration.CHAN = 0x17; == 23d
    effecting the frequency ? 868 MHz + 23 -> 891 MHz is the final transmission frequency ?

    Based on Your program I managed to reach till this level:

    
    #define E32_TTL_1W      
    #define FREQUENCY_868
    /*
    #define FREQUENCY_433
    #define FREQUENCY_170
    #define FREQUENCY_470
    #define FREQUENCY_868
    #define FREQUENCY_915
    */
    
    #include "Arduino.h"
    #include "LoRa_E32.h"
    
    LoRa_E32 e32ttl100(2, 3); // e32 TX e32 RX
    
    void printParameters(struct Configuration configuration);
    void printModuleInformation(struct ModuleInformation moduleInformation);
    
    void setup() {
    	Serial.begin(9600);
    	delay(500);
    
    	// Startup all pins and UART
    	e32ttl100.begin();
    
    	ResponseStructContainer c;
    	c = e32ttl100.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);
      //configuration.ADDL = 0x0; // 0x0; (def: 00H /00H-FFH) // First part of address
      //configuration.ADDH = 0x1; // 0x1; (def: 00H /00H-FFH) // Second part of address
      //configuration.CHAN = 0x17; // Communication channel (def 17H == 23d == 433MHz / 410 M + CHAN*1M)
    
    	//configuration.OPTION.fec = FEC_0_OFF;
    //	configuration.OPTION.fixedTransmission = FT_TRANSPARENT_TRANSMISSION;
    	//configuration.OPTION.ioDriveMode = IO_D_MODE_PUSH_PULLS_PULL_UPS;
    
     // #define E32_TTL_100 // default value without set  //POWER_20 POWER_17 POWER_14 POWER_10
     // #define E32_TTL_1W                                //POWER_30 POWER_27 POWER_24 POWER_21
    	configuration.OPTION.transmissionPower = POWER_21; // dBm transmission power 
    	
    	//configuration.OPTION.wirelessWakeupTime = WAKE_UP_1250; // Wait time for wake up
    
    //	configuration.SPED.airDataRate = AIR_DATA_RATE_011_48;  // Air data rate
    //	configuration.SPED.uartBaudRate = UART_BPS_115200;      // 9600bps (default) Communication baud rate
    //	configuration.SPED.uartParity = MODE_00_8N1;
    
    	// Set configuration changed and set to not hold the configuration
    	ResponseStatus rs = e32ttl100.setConfiguration(configuration, WRITE_CFG_PWR_DWN_LOSE);
    	Serial.println(rs.getResponseDescription());
    	Serial.println(rs.code);
    	printParameters(configuration);
    	c.close();
    }
    
    void loop() {
    
    }
    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, BIN);
    	Serial.print(F("AddL : "));  Serial.println(configuration.ADDL, BIN);
    	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("----------------------------------------");
    
    }
    

    Thank You for Your support in advace.

    • Hi steger,
      yes you can define mhz before include.

      // One of
      #define FREQUENCY_433
      #define FREQUENCY_170
      #define FREQUENCY_470
      #define FREQUENCY_868
      #define FREQUENCY_915

      The channel is added to the base frequency.

      #ifdef FREQUENCY_433
      #define OPERATING_FREQUENCY 410
      #elif defined(FREQUENCY_170)
      #define OPERATING_FREQUENCY 130
      #elif defined(FREQUENCY_470)
      #define OPERATING_FREQUENCY 370
      #elif defined(FREQUENCY_868)
      #define OPERATING_FREQUENCY 862
      #elif defined(FREQUENCY_915)
      #define OPERATING_FREQUENCY 900
      #else
      #define OPERATING_FREQUENCY 410
      #endif

      Bye Renzo

  6. Emmanuel_FR says:

    Ciao Renzo,

    Thank you for your library, it works fine. Just one little thing that might help people like me who don’t remember that ESP8266 pinout was designed by someone evil : D2 is NOT GPIO2. So one suggestion : For the wemos option, you should just add the precision that the arduino pinout is not valid. I thought I had killed both my modules, until I made a test with Ebytes config software and understood !

    Grazzie mille

    • Hi Emmanuel,
      in all the examples in the library I add the double declaration

      // ---------- esp8266 pins --------------
      //LoRa_E32 e32ttl(D2, D3, D5, D7, D6);
      //LoRa_E32 e32ttl(D2, D3); // Config without connect AUX and M0 M1
      
      //#include <SoftwareSerial.h>
      //SoftwareSerial mySerial(D2, D3); // Arduino RX <-- e32 TX, Arduino TX --> e32 RX
      //LoRa_E32 e32ttl(&mySerial, D5, D7, D6);
      // -------------------------------------
      
      // ---------- Arduino pins --------------
      //LoRa_E32 e32ttl(2, 3, 5, 7, 6);
      LoRa_E32 e32ttl(2, 3, 4); // Config without connect AUX and M0 M1
      
      //#include <SoftwareSerial.h>
      //SoftwareSerial mySerial(2, 3); // Arduino RX <-- e32 TX, Arduino TX --> e32 RX
      //LoRa_E32 e32ttl(&mySerial, 5, 7, 6);
      // -------------------------------------
      

      and I add the wiring diagram for esp8266, esp32 and Arduino in the specified section on article 6/7/8.

      But I try to specify better in every section.

      Thanks Renzo

  7. Massimo Baldi says:

    Ciao Renzo, ho seguito con molto interesse i tuoi esempi e la libreria. Veramente complimenti. Mi chiedevo se la libreria poteva essere utilizzata pe qualsiasi modulo Lora, esempio quelli ESP32 LORA OLED della TTGO con a bordo oltra che al LORA un display, nei quali non ho trovato i pin M0 e M1

    • Ciao Massimo,
      no, questa libreria è funzionante solo su dispositivi UART dell’EByte in particolare l’E32, poi ho anche la lib per l’E22.
      Avevo scelto dei device UART per poterli usare anche direttamente dal PC con il relativo device dell’EByte.
      Ciao Renzo

  8. Lucas says:

    Hello Renzo,
    I would like to know if there is a function in your library to check RSSI values. If not, is there any other way to check these values?

    Thank you.

  9. Rajat Handa says:

    Hi, Thanks for your library and I am trying to get the Freq from the module however I am facing a strange issue that its showing me 429 Mhz where as my module is Ebyte E32-900T30D which has 865 Mhz band and is 1W module.
    I am using Esp32 dev kit v1 board.

    /*
     * LoRa E32-TTL-100
     * Get configuration.
     * http://mischianti.org
     *
     * E32-TTL-100----- Arduino UNO
     * M0         ----- 3.3v
     * M1         ----- 3.3v
     * TX         ----- PIN 2 (PullUP)
     * RX         ----- PIN 3 (PullUP & Voltage divider)
     * AUX        ----- Not connected
     * VCC        ----- 3.3v/5v
     * GND        ----- GND
     *
     */
    
    #include "Arduino.h"
    #include "LoRa_E32.h"
    
    #define FREQUENCY_868
    #define RX 16
    #define TX 17
    #define AUX 15
    #define M0 18
    #define M1 19
    #define E32_TTL_1W
    
    HardwareSerial serial1(2);
    LoRa_E32 e32ttl1w(&serial1, UART_BPS_RATE_9600);
    
    void printParameters(struct Configuration configuration);
    void printModuleInformation(struct ModuleInformation moduleInformation);
    
    void setup() {
      Serial.begin(115200);
      delay(1500);
    
      // Startup all pins and UART
      e32ttl1w.begin();
    
      ResponseStructContainer c;
      c = e32ttl1w.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);
      //configuration.ADDL = 0x6;
      //configuration.ADDH = 0x10;
      //configuration.CHAN = 0x17;
    
      //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_20;
      //configuration.OPTION.wirelessWakeupTime = WAKE_UP_1250;
    
      //configuration.SPED.airDataRate = AIR_DATA_RATE_011_48;
      //configuration.SPED.uartBaudRate = UART_BPS_9600;
      //configuration.SPED.uartParity = MODE_00_8N1;
    
      // Set configuration changed and set to not hold the configuration
      ResponseStatus rs = e32ttl1w.setConfiguration(configuration, WRITE_CFG_PWR_DWN_LOSE);
      Serial.println(rs.getResponseDescription());
      Serial.println(rs.code);
      printParameters(configuration);
      c.close();
    }
    
    void loop() {
    
    }
    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, BIN);
      Serial.print(F("AddL : "));  Serial.println(configuration.ADDL, BIN);
      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("----------------------------------------");
    
    }
    
  10. Nuno says:

    Hello Renzo,

    I have a LoRa module E32-433T33D (it has 2w transmission power). I am currently using #define E32_TTL_1W but this one only allow 1W… Is it possible to use this LoRa module (E32-433T33D) it with your library? How can I do it?

    Regards
    Nuno

  11. ebyte says:

    Dear community members,

    Thank you all for your enthusiastic support and recognition of the ebyte brand! We have been working hard to provide you with excellent products and services to take your experience in the IoT field to the next level.

    We are happy to announce that the latest version of the EBYTE website (www.cdebyte.com)has been updated! Here you will be able to more easily browse our product lines and learn about the latest technologies and solutions.

    In order to thank you for your continued support, we have launched a free sample event(https://www.cdebyte.com/resources-FreeTrial) This is a rare opportunity for you to experience our latest products firsthand. Everyone is welcome to actively participate and share the innovation and convenience brought by Ebyte.

    Come visit our updated website and explore the latest IoT solutions:www.cdebyte.com. We look forward to discussing and developing together with you, thank you!

Leave a Reply to Renzo Mischianti Cancel reply

Your email address will not be published. Required fields are marked *