Skip to main content

RaspberryPi LoRa EBYTE E22 device library complete and tested. sx1262/sx1268

Project description

Support forum EByte e32 English
Forum supporto EByte e32 italiano

EBYTE LoRa E22 devices raspberrypi library (SX1262, SX1268)

Changelog

  • 2023-05-02 0.0.4 Fix message size error
  • 2023-04-25 0.0.3 Minor fixes
  • 2023-03-21 0.0.1 Fully functional library

Library usage

Here an example of constructor, you must pass the UART interface and (if you want, but It's reccomended) the AUX pin, M0 and M1.

Installation

To install the library execute the following command:

pip install ebyte-lora-e22-rpi

Initialization

from lora_e22 import LoRaE22
import serial

loraSerial = serial.Serial('/dev/serial0') #, baudrate=9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS)
lora = LoRaE22('400T22D', loraSerial, aux_pin=18, m0_pin=23, m1_pin=24)

Start the module transmission

code = lora.begin()
print("Initialization: {}", ResponseStatusCode.get_description(code))

Get Configuration

from lora_e22 import LoRaE22, print_configuration
from lora_e22_operation_constant import ResponseStatusCode

code, configuration = lora.get_configuration()

print("Retrieve configuration: {}", ResponseStatusCode.get_description(code))

print_configuration(configuration)

The result

# ----------------------------------------
# HEAD :  0xc1   0x0   0x9
#
# AddH :  0x0
# AddL :  0x0
#
# Chan :  23  ->  433
#
# SpeedParityBit :  0b0  ->  8N1 (Default)
# SpeedUARTDatte :  0b11  ->  9600bps (default)
# SpeedAirDataRate :  0b10  ->  2.4kbps (default)
#
# OptionSubPacketSett:  0b0  ->  240bytes (default)
# OptionTranPower :  0b0  ->  22dBm (Default)
# OptionRSSIAmbientNo:  0b0  ->  Disabled (default)
#
# TransModeWORPeriod :  0b11  ->  2000ms (default)
# TransModeTransContr:  0b0  ->  WOR Receiver (default)
# TransModeEnableLBT :  0b0  ->  Disabled (default)
# TransModeEnableRSSI:  0b0  ->  Disabled (default)
# TransModeEnabRepeat:  0b0  ->  Disabled (default)
# TransModeFixedTrans:  0b0  ->  Transparent transmission (default)
# ----------------------------------------

Set Configuration

You can set only the desidered parameter, the other will be set to default value.

configuration_to_set = Configuration('400T22D')
configuration_to_set.ADDL = 0x02
configuration_to_set.ADDH = 0x01
configuration_to_set.CHAN = 23

configuration_to_set.NETID = 0

configuration_to_set.SPED.airDataRate = AirDataRate.AIR_DATA_RATE_100_96
configuration_to_set.SPED.uartParity = UARTParity.MODE_00_8N1
configuration_to_set.SPED.uartBaudRate = UARTBaudRate.BPS_9600

configuration_to_set.OPTION.subPacketSetting = SubPacketSetting.SPS_064_10
configuration_to_set.OPTION.transmissionPower = TransmissionPower('400T22D').\
                                                    get_transmission_power().POWER_10
# or
# configuration_to_set.OPTION.transmissionPower = TransmissionPower22.POWER_10
configuration_to_set.OPTION.RSSIAmbientNoise = RssiAmbientNoiseEnable.RSSI_AMBIENT_NOISE_ENABLED

configuration_to_set.TRANSMISSION_MODE.WORTransceiverControl = WorTransceiverControl.WOR_TRANSMITTER
configuration_to_set.TRANSMISSION_MODE.enableLBT = LbtEnableByte.LBT_DISABLED
configuration_to_set.TRANSMISSION_MODE.enableRSSI = RssiEnableByte.RSSI_ENABLED
configuration_to_set.TRANSMISSION_MODE.enableRepeater = RepeaterModeEnableByte.REPEATER_DISABLED
configuration_to_set.TRANSMISSION_MODE.fixedTransmission = FixedTransmission.FIXED_TRANSMISSION
configuration_to_set.TRANSMISSION_MODE.WORPeriod = WorPeriod.WOR_1500_010

configuration_to_set.CRYPT.CRYPT_H = 1
configuration_to_set.CRYPT.CRYPT_L = 1


# Set the new configuration on the LoRa module and print the updated configuration to the console
code, confSetted = lora.set_configuration(configuration_to_set)

I create a CONSTANTS class for each parameter, here a list: AirDataRate, UARTBaudRate, UARTParity, TransmissionPower, ForwardErrorCorrectionSwitch, WirelessWakeUpTime, IODriveMode, FixedTransmission

Send string message

Here an example of send data, you can pass a string

lora.send_transparent_message('pippo')
lora.send_fixed_message(0, 2, 23, 'pippo')

Here the receiver code

while True:
    if lora.available() > 0:
        code, value = lora.receive_message()
        print(ResponseStatusCode.get_description(code))

        print(value)
        time.sleep(2)

If you want receive RSSI also you must enable it in the configuration

configuration_to_set.TRANSMISSION_MODE.enableRSSI = RssiEnableByte.RSSI_ENABLED

and set the flag to True in the receive_message method

code, value, rssi = lora.receive_message(True)

Result

Success!
pippo

Send dictionary message

Here an example of send data, you can pass a dictionary

lora.send_transparent_dict({'pippo': 'fixed', 'pippo2': 'fixed2'})
lora.send_fixed_dict(0, 0x01, 23, {'pippo': 'fixed', 'pippo2': 'fixed2'})

Here the receiver code

while True:
    if lora.available() > 0:
        code, value = lora.receive_dict()
        print(ResponseStatusCode.get_description(code))
        print(value)
        print(value['pippo'])
        time.sleep(2)

if you want receive RSSI also you must enable it in the configuration

configuration_to_set.TRANSMISSION_MODE.enableRSSI = RssiEnableByte.RSSI_ENABLED

and set the flag to True in the receive_dict method

code, value, rssi = lora.receive_dict(True)

Result

Success!
{'pippo': 'fixed', 'pippo2': 'fixed2'}
fixed

This is a porting of the Arduino library for EBYTE LoRa E22 devices to Micropython

Soon a complete tutorial of the original library on my site www.mischianti.org

Pinout

E22

Pin No. Pin item Pin direction Pin application
1M0Input(weak pull-up)Work with M1 & decide the four operating modes.Floating is not allowed, can be ground.
2M1Input(weak pull-up)Work with M0 & decide the four operating modes.Floating is not allowed, can be ground.
3RXDInputTTL UART inputs, connects to external (MCU, PC) TXD outputpin. Can be configured as open-drain or pull-up input.
4TXDOutputTTL UART outputs, connects to external RXD (MCU, PC) inputpin. Can be configured as open-drain or push-pull output

5

AUX

Output
Per indicare lo stato di funzionamento del modulo e riattivare l’MCU esterno. Durante la procedura di inizializzazione di autocontrollo, il pin emette una bassa tensione. Può essere configurato come uscita open-drain o output push-pull (è consentito non metterlo a terra, ma se hai problemi, ad esempio ti si freeze il dispositivo è preferibile mettere una restistenza di pull-up da 4.7k o meglio collegarlo al dispositivo).
6VCC
Power supply 2.3V~5.5V DC
7GND
Ground

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

Mode M1 M0 Explanation
Normal00UART and wireless channel are open, transparent transmission is on (Supports configuration over air via special command)
WOR Mode01Can be defined as WOR transmitter and WOR receiver
Configuration mode10Users can access the register through the serial port to control the working state of the module
Deep sleep mode11Sleep mode

As you can see there are some pins that can be use in a static way, but If you connect It to the library you gain in performance and you can control all mode via software, but we are going to explain better next.

Fully connected schema

Raspberry Pi

Raspberry Pi

Basic configuration option

ADDHHigh address byte of module (the default 00H)00H-FFH
ADDLLow address byte of 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 chek below to check the correct frequency of your device00H-1FH
OPTIONType of transmission, packet size, allow special message
TRANSMISSION_MODEA lot of parameter that specify the transmission modality

OPTION

Type of transmission, pull-up settings, wake-up time, FEC, Transmission power

SPED detail

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

43UART parity bitConstant 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.

765TTL 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 keep the same for both communication parties.

210Air 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
11038.4kAIR_DATA_RATE_110_384
11162.5kAIR_DATA_RATE_111_625

OPTION detail

####Sub packet setting

This is the max lenght of the packet.

When the data is smaller than the sub packet length, the serial output of the receiving end is an uninterrupted continuous output. When the data is larger than the sub packet length, the receiving end serial port will output the sub packet.

76Packet size Constant value
00240bytes (default)SPS_240_00
01128bytesSPS_128_01
1064bytesSPS_064_10
1132bytesSPS_032_11

####RSSI Ambient noise enable

This command can enable/disable the management type of RSSI, It’s important to manage the remote configuration, pay attention isn’t the RSSI parameter in the message.

When enabled, the C0 C1 C2 C3 command can be sent in the transmitting mode or WOR transmitting mode to read the register. Register 0x00: Current ambient noise rssi Register 0X01: rssi when the data was received last time.

5RSSI Ambient noise enable Constant value
0EnableRSSI_AMBIENT_NOISE_ENABLED
1Disable (default)RSSI_AMBIENT_NOISE_DISABLED

TRANSMISSION_MODE Detail

####Enable RSSI

When enabled, the module receives wireless data and it will follow an RSSI strength byte after output via the serial port TXD

####Transmission type

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

####Enable repeater function

####Monitor data before transmission

When enabled, wireless data will be monitored before it is transmitted, which can avoid interference to a certain extent, but may cause data delay.

####WOR

WOR transmitter: the module receiving and transmitting functions are turned on, and a wake-up code is added when transmitting data. Receiving is turned on.

WOR receiver: the module is unable to transmit data and works in WOR monitoring mode. The monitoring period is as follows (WOR cycle), which can save a lot of power.

####WOR cycle

If WOR is transmitting: after the WOR receiver receives the wireless data and outputs it through the serial port, it will wait for 1000ms before entering the WOR again. Users can input the serial port data and return it via the wireless during this period. Each serial byte will be refreshed for 1000ms. Users must transmit the first byte within 1000ms.

  • Period T = (1 + WOR) * 500ms, maximum 4000ms, minimum 500ms
  • The longer the WOR monitoring interval period, the lower the average power consumption, but the greater the data delay
  • Both the transmitter and the receiver must be the same (very important).

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 simply return how many bytes you have in the current stream.

Normal transmission mode

Normal/Transparent transmission mode is used to send messages to all device with same address and channel.

LoRa E22 transmitting scenarios, lines are channels

Fixed transmission have more scenarios

LoRa E22 transmitting scenarios, lines are channels

Thanks

Now you have all information to do your work, but I think It’s important to show some realistic examples to undestand better all the possibility.

  • Ebyte LoRa E22 device for Arduino, esp32 or esp8266: settings and basic usage

  • Ebyte LoRa E22 device for Arduino, esp32 or esp8266: library

  • Ebyte LoRa E22 device for Arduino, esp32 or esp8266: configuration

  • Ebyte LoRa E22 device for Arduino, esp32 or esp8266: fixed transmission and RSSI

  • Ebyte LoRa E22 device for Arduino, esp32 or esp8266: power saving and sending structured data

  • Ebyte LoRa E22 device for Arduino, esp32 or esp8266: repeater mode and remote settings

  • Ebyte LoRa E22 device for Arduino, esp32 or esp8266: WOR microcontroller and Arduino shield

  • Ebyte LoRa E22 device for Arduino, esp32 or esp8266: WOR microcontroller and WeMos D1 shield

  • Ebyte LoRa E22 device for Arduino, esp32 or esp8266: WOR microcontroller and esp32 dev v1 shield

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ebyte-lora-e22-rpi-0.0.4.tar.gz (23.5 kB view details)

Uploaded Source

Built Distribution

ebyte_lora_e22_rpi-0.0.4-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

Details for the file ebyte-lora-e22-rpi-0.0.4.tar.gz.

File metadata

  • Download URL: ebyte-lora-e22-rpi-0.0.4.tar.gz
  • Upload date:
  • Size: 23.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for ebyte-lora-e22-rpi-0.0.4.tar.gz
Algorithm Hash digest
SHA256 3b51e9a4c26fdf416e90fe9abe419c6b06d121e8b99e5ab55e2d15a886143341
MD5 18f41c1726976da0833cc10d88964d00
BLAKE2b-256 c05f53fe6b30d0488b2bf0463be57dfa16449f6d2ab78614909ba468c8879918

See more details on using hashes here.

File details

Details for the file ebyte_lora_e22_rpi-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for ebyte_lora_e22_rpi-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 89e9eda02b1bce3d273d80b7b826e8d022f2d1453b169b2c577d09af0ad0a1ef
MD5 6dedb849dd5122da99c03ac0d6a76ee1
BLAKE2b-256 2d49451fc36cd782e4da61d3893c3c57ae9b72cc6e3cd11cbe24b2ff5b3a6555

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page