EByte_LoRa_E220_micropython_library

MicroPython LoRa EBYTE E220 LLCC68 device library complete and tested with Arduino, esp8266, esp32, STM32 and Raspberry Pi Pico (rp2040 boards).

OTHER License

Downloads
122
Stars
17
Committers
1

EBYTE LoRa E220 devices micropython library (LLCC68)

Changelog

  • 2023-07-16 0.0.5 Fix retrieve transmisison power Issue
  • 2023-05-02 0.0.4 Minor fix on data size message
  • 2023-04-18 0.0.3 Fix regular expression models
  • 2023-04-18 0.0.2 Distinct frequency from 900MHz and 915Mhz devices Forum
  • 2023-03-21 0.0.1 Fully functional library

Installation

To install the library execute the following command:

pip install ebyte-lora-e220

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.

Initialization

from lora_e220 import LoRaE220
from machine import UART

uart2 = UART(2)
lora = LoRaE220('400T22D', uart2, aux_pin=15, m0_pin=21, m1_pin=19)

Start the module transmission

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

Get Configuration

from lora_e220 import LoRaE220, print_configuration
from lora_e220_operation_constant import ResponseStatusCode

code, configuration = lora.get_configuration()

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

print_configuration(configuration)

The result

----------------------------------------
Initialization: {} Success
Retrieve configuration: {} Success
----------------------------------------
HEAD :  0xc1   0x0   0x8
AddH :  0x0
AddL :  0x0
Chan :  23  ->  433
SpeedParityBit :  0b0  ->  8N1 (Default)
SpeedUARTDatte :  0b11  ->  9600bps (default)
SpeedAirDataRate :  0b10  ->  2.4kbps (default)
OptionSubPacketSett:  0b0  ->  200bytes (default)
OptionTranPower :  0b0  ->  22dBm (Default)
OptionRSSIAmbientNo:  0b0  ->  Disabled (default)
TransModeWORPeriod :  0b11  ->  2000ms (default)
TransModeEnableLBT :  0b0  ->  Disabled (default)
TransModeEnableRSSI:  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.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.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.OPTION.subPacketSetting = SubPacketSetting.SPS_064_10

configuration_to_set.TRANSMISSION_MODE.fixedTransmission = FixedTransmission.FIXED_TRANSMISSION
configuration_to_set.TRANSMISSION_MODE.WORPeriod = WorPeriod.WOR_1500_010
configuration_to_set.TRANSMISSION_MODE.enableLBT = LbtEnableByte.LBT_DISABLED
configuration_to_set.TRANSMISSION_MODE.enableRSSI = RssiEnableByte.RSSI_ENABLED

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)
        utime.sleep_ms(2000)

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'])
        utime.sleep_ms(2000)

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 E220 devices to Micropython

Tutorial of the original library

An Arduino UNO shield to simplify the use

You can order the PCB here

Instruction and assembly video on 6 part of the guide

An WeMos D1 shield to simplify the use

You can order the PCB here

Instruction and assembly video on 6 part of the guide

Ebyte LoRa E220 LLCC68 device for Arduino, esp32 or esp8266: library

Package Rankings
Top 18.73% on Pypi.org
Related Projects