Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/xreef/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).
https://github.com/xreef/ebyte_lora_e220_micropython_library

arduino arduino-samd-boards e220 ebyte esp32 esp8266 llcc68 lora micropython pico python radio raspberry raspberry-pi rp2040 stm32 uart

Last synced: 6 days ago
JSON representation

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

Awesome Lists containing this project

README

        


Support forum EByte e220 English


Forum supporto EByte e220 italiano

# EBYTE LoRa E220 devices micropython library (LLCC68)

### Changelog
- 2023-07-16 0.0.5 Fix retrieve transmisison power [Issue](https://github.com/xreef/EByte_LoRa_E220_python_raspberrypi_library/issues/1)
- 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](https://www.mischianti.org/forums/topic/e32-915t-and-e32-900t-modules/)
- 2023-03-21 0.0.1 Fully functional library

### Installation
To install the library execute the following command:

```bash
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

```python
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

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

#### Get Configuration

```python
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.
```python
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
```python
lora.send_transparent_message('pippo')
```

```python
lora.send_fixed_message(0, 2, 23, 'pippo')
```
Here the receiver code
```python
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
```python
configuration_to_set.TRANSMISSION_MODE.enableRSSI = RssiEnableByte.RSSI_ENABLED
```

and set the flag to True in the receive_message method
```python
code, value, rssi = lora.receive_message(True)
```

Result

```
Success!
pippo
```

#### Send dictionary message

Here an example of send data, you can pass a dictionary
```python
lora.send_transparent_dict({'pippo': 'fixed', 'pippo2': 'fixed2'})
```

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

Here the receiver code
```python
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
```python
configuration_to_set.TRANSMISSION_MODE.enableRSSI = RssiEnableByte.RSSI_ENABLED
```

and set the flag to True in the receive_dict method
```python
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

- [Ebyte LoRa E220 device for Arduino, esp32 or esp8266: settings and basic usage](https://www.mischianti.org/2022/03/11/ebyte-lora-e220-llcc68-device-for-arduino-esp32-or-esp8266-specs-and-basic-use-1/)
- [Ebyte LoRa E220 device for Arduino, esp32 or esp8266: library](https://www.mischianti.org/2022/03/17/ebyte-lora-e220-llcc68-device-for-arduino-esp32-or-esp8266-library-2/)
- [Ebyte LoRa E220 device for Arduino, esp32 or esp8266: configuration](https://www.mischianti.org/2022/04/19/ebyte-lora-e220-llcc68-device-for-arduino-esp32-or-esp8266-configuration-3/)
- [Ebyte LoRa E220 device for Arduino, esp32 or esp8266: fixed transmission, broadcast, monitor, and RSSI](https://www.mischianti.org/2022/04/27/ebyte-lora-e220-device-for-arduino-esp32-or-esp8266-fixed-transmission-broadcast-monitor-and-rssi-4/)
- [Ebyte LoRa E220 device for Arduino, esp32 or esp8266: power saving and sending structured data](https://www.mischianti.org/2022/05/06/ebyte-lora-e220-device-for-arduino-esp32-or-esp8266-manage-wake-on-radio-and-sends-structured-data-5/)
- Ebyte LoRa E220 device for Arduino, esp32 or esp8266: WOR microcontroller and Arduino shield
- Ebyte LoRa E220 device for Arduino, esp32 or esp8266: WOR microcontroller and WeMos D1 shield
- Ebyte LoRa E220 device for Arduino, esp32 or esp8266: WOR microcontroller and esp32 dev v1 shield

LLCC68

LoRa Smart Home (LLCC68) is a sub-GHz LoRa® RF Transceiver for medium-range indoor and indoor to outdoor wireless applications. SPI interface. Pin-to-pin is compatible with SX1262. SX1261, SX1262, SX1268, and LLCC68 are designed for long battery life with just 4.2 mA of active receive current consumption. The SX1261 can transmit up to +15 dBm, and the SX1262, SX1268, and LLCC68 can transmit up to +22 dBm with highly efficient integrated power amplifiers.



These devices support LoRa modulation for LPWAN use cases and (G)FSK modulation for legacy use cases. The devices are highly configurable to meet different application requirements for consumer use. The device provides LoRa modulation compatible with Semtech transceivers used by the LoRaWAN® specification released by the LoRa Alliance®. The radio is suitable for systems targeting compliance with radio regulations, including but not limited to ETSI EN 300 220, FCC CFR 47 Part 15, China regulatory requirements, and the Japanese ARIB T-108. Continuous frequency coverage from 150MHz to 960MHz allows the support of all major sub-GHz ISM bands around the world.

Features


  • The new LoRa spread spectrum modulation technology developed based on LLCC68, it brings a more extended communication distance and stronger anti-interference ability;

  • Support users to set the communication key by themselves, and it cannot be read, which significantly improves the confidentiality of user data;

  • Support LBT function, monitor the channel environment noise before sending, which significantly improves the communication success rate of the module in harsh environments;

  • Support RSSI signal strength indicator function for evaluating signal quality, improving communication network, and ranging;

  • Support air wakeup, that is ultra-low power consumption, suitable for battery-powered applications;

  • Support point to point transmission, broadcast transmission, channel sense;

  • Support deep sleep, the power consumption of the whole machine is about 5uA in this mode;

  • The module has built-in PA+LNA, and the communication distance can reach 5km under ideal conditions;

  • The parameters are saved after power-off, and the module will work according to the set parameters after power-on;

  • Efficient watchdog design, once an exception occurs, the module will automatically restart and continue to work according to the previous parameter settings;

  • Support the bit rate of2.4k~62.5kbps;

  • Support 3.0~5.5V power supply, power supply greater than 5V can guarantee the best performance;

  • Industrial standard design, supporting long-term use at -40~+85℃;

Comparison

LLCC68SX1278-SX1276Distance> 11Km8KmRate (LoRa)1.76Kbps – 62.5Kbps 0.3Kbps – 19.2KbpsSleep power consumption2µA 5µA

Library

Library for Ebyte LoRa E220 LLCC68 device for Arduino, esp32 or esp8266.

Pinout



Pin No.Pin itemPin directionPin application1M0Input(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
OutputTo 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).6VCCPower supply 3V~5.5V DC7GNDGround

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

ModeM1M0ExplanationNormal00UART and wireless channels are open, and transparent transmission is onWOR Transmitter01WOR TransmitterWOR Receiver10WOR Receiver (Supports wake up over air)Deep sleep mode11The module goes to sleep (automatically wake up when configuring parameters)

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 can control all modes via software. Still, we are going to explain better next.

Fully connected schema

As I already said, It’s not essential to connect all pins to the microcontroller’s output; you can put M0 and M1 pins to HIGH or LOW to get the desired configuration. If you don’t connect AUX, the library set a reasonable delay to ensure that the operation is complete (If you have trouble with the device freezing, 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.



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

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



esp8266

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



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

E22esp8266M0D7M1D6TXPIN D2 (PullUP 4,7KΩ)RXPIN D3 (PullUP 4,7KΩ)AUXPIN D5 (PullUP 4,7KΩ)VCC5V (but work with less power in 3.3v)GNDGND

esp32

Similar connection schema for esp32, but for RX and TX, we use RX2 and TX2 because, by default, esp32 doesn’t have SoftwareSerial but has 3 Serial.



E22esp32M0D21M1D19TXPIN 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

Arduino MKR WiFi 1010

M02 (voltage divider)M13 (voltage divider)TXPIN 14 Tx (PullUP 4,7KΩ)RXPIN 13 Rx (PullUP 4,7KΩ)AUXPIN 1 (PullUP 4,7KΩ)VCC5VGNDGND

# An Arduino UNO shield to simplify the use
![Arduino UNO shield](https://www.mischianti.org/wp-content/uploads/2019/12/ArduinoShieldMountedE32LoRa_min.jpg)

You can order the PCB [here](https://www.pcbway.com/project/shareproject/LoRa_E32_Series_device_Arduino_shield.html)

Instruction and assembly video on 6 part of the guide

# An WeMos D1 shield to simplify the use
![Arduino UNO shield](https://www.mischianti.org/wp-content/uploads/2020/01/WeMosD1ShieldMountedE32LoRa_min.jpg)

You can order the PCB [here](https://www.pcbway.com/project/shareproject/LoRa_E32_Series_device_WeMos_D1_mini_shield_RF_8km_range.html)

Instruction and assembly video on 6 part of the guide

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




LoRa or Long Range wireless data telemetry is a technology pioneered by Semtech that operates at a lower frequency than NRF24L01 (433 MHz, 868 MHz, or 916 MHz against 2.4 GHz for the NRF24L01) but at thrice the distance (from 5000m to 11000m).



Basic configuration option

NameDescriptionAddressADDHHigh address byte of the module (the default 00H)00HADDLLow address byte of the module (the default 00H)01HSPEDInformation about data rate parity bit and Air data rate02HOPTION Type of transmission, packet size, allow the special message 03H CHANCommunication channel(410M + CHAN*1M), default 17H (433MHz), valid only for 433MHz device check below to check the correct frequency of your device04HOPTIONType of transmission, packet size, allow the special message05HTRANSMISSION_MODEA lot of parameters that specify the transmission modality06HCRYPTEncryption to avoid interception07H

SPED detail

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

UART parity bitConstant value8N1 (default)MODE_00_8N18O1MODE_01_8O18E1MODE_10_8E18N1 (equal to 00)MODE_11_8N1

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





TTL UART baud rate(bps)Constant value1200UART_BPS_12002400UART_BPS_24004800UART_BPS_48009600 (default)UART_BPS_960019200UART_BPS_1920038400UART_BPS_3840057600UART_BPS_57600115200UART_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.

Air data rate(bps) Constant value 2.4k AIR_DATA_RATE_000_24 2.4k AIR_DATA_RATE_001_24 2.4k (default)AIR_DATA_RATE_010_244.8kAIR_DATA_RATE_011_489.6kAIR_DATA_RATE_100_9619.2kAIR_DATA_RATE_101_19238.4kAIR_DATA_RATE_110_38462.5kAIR_DATA_RATE_111_625

OPTION detail

Sub packet setting

This is the max length of the packet.

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

Packet size Constant value 200bytes (default)SPS_200_00128bytesSPS_128_0164bytesSPS_064_1032bytesSPS_032_11

RSSI Ambient noise enable

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

When enabled, the C0, C1, C2, C3 commands 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.

RSSI Ambient noise enable Constant value EnableRSSI_AMBIENT_NOISE_ENABLEDDisable (default)RSSI_AMBIENT_NOISE_DISABLED

Transmission power

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

#define E220_22 // default value without set 

Applicable for E220 with 22dBm as max power.
Low power transmission is not recommended due to its low power supply efficiency.

Transmission power (approximation) Constant value 22dBm (default)POWER_2217dBmPOWER_1713dBmPOWER_1310dBmPOWER_10

Applicable for E220 with 30dBm as max power.
Low power transmission is not recommended due to its low power supply efficiency.

#define E220_30

Transmission power (approximation) Constant value 30dBm (default)POWER_3027dBmPOWER_2724dBmPOWER_2421dBmPOWER_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

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

Enable RSSI Constant value EnableRSSI_ENABLEDDisable (default)RSSI_DISABLED

Transmission type

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.

Fixed transmission enabling bit Constant value Fixed transmission modeFT_FIXED_TRANSMISSIONTransparent transmission mode (default)FT_TRANSPARENT_TRANSMISSION

Monitor data before transmission

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

LBT enable byte Constant value EnableLBT_ENABLEDDisable (default)LBT_DISABLED

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 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).

Wireless wake-up time Constant value 500msWAKE_UP_5001000msWAKE_UP_10001500msWAKE_UP_15002000ms (default)WAKE_UP_20002500msWAKE_UP_25003000msWAKE_UP_30003500msWAKE_UP_35004000msWAKE_UP_4000

Check buffer

First, we must introduce a simple but practical 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.



Send receive messages

Normal transmission mode

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

Fixed transmission

Fixed transmission have more scenarios

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. Ebyte LoRa E220 device for Arduino, esp32 or esp8266: settings and basic usage

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

  3. Ebyte LoRa E220 device for Arduino, esp32 or esp8266: configuration

  4. Ebyte LoRa E220 device for Arduino, esp32 or esp8266: fixed transmission, broadcast, monitor, and RSSI

  5. Ebyte LoRa E220 device for Arduino, esp32 or esp8266: power saving and sending structured data

  6. Ebyte LoRa E220 device for Arduino, esp32 or esp8266: WOR microcontroller and Arduino shield

  7. Ebyte LoRa E220 device for Arduino, esp32 or esp8266: WOR microcontroller and WeMos D1 shield

  8. Ebyte LoRa E220 device for Arduino, esp32 or esp8266: WOR microcontroller and esp32 dev v1 shield

Github library