Package: ebyte-lora-e22-circuitpython
EBYTE LoRa E22 devices circuitpython library (SX1262, SX1268)Changelog2024-02-06 0.0.1 Fully functional libraryLibrary usageHere an example of constructor, you must pass the UART interface and (if you want, but It's reccomended)
the AUX pin, M0 and M1.InstallationTo install the library execute the following command:pipinstallebyte-lora-e22-circuitpythonInitializationfromlora_e22importLoRaE22importboardimportbusio# Create a UART object to communicate with the LoRa module with ESP32uart2=busio.UART(board.TX2,board.RX2,baudrate=9600)# Create a LoRaE22 object, passing the UART object and pin configurationslora=LoRaE22('400T22D',uart2,aux_pin=board.D15,m0_pin=board.D21,m1_pin=board.D19)Start the module transmissioncode=lora.begin()print("Initialization:{}",ResponseStatusCode.get_description(code))Get Configurationfromlora_e22importLoRaE22,print_configurationfromlora_e22_operation_constantimportResponseStatusCodecode,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 ConfigurationYou can set only the desidered parameter, the other will be set to default value.configuration_to_set=Configuration('400T22D')configuration_to_set.ADDL=0x02configuration_to_set.ADDH=0x01configuration_to_set.CHAN=23configuration_to_set.NETID=0configuration_to_set.SPED.airDataRate=AirDataRate.AIR_DATA_RATE_100_96configuration_to_set.SPED.uartParity=UARTParity.MODE_00_8N1configuration_to_set.SPED.uartBaudRate=UARTBaudRate.BPS_9600configuration_to_set.OPTION.subPacketSetting=SubPacketSetting.SPS_064_10configuration_to_set.OPTION.transmissionPower=TransmissionPower('400T22D').\get_transmission_power().POWER_10# or# configuration_to_set.OPTION.transmissionPower = TransmissionPower22.POWER_10configuration_to_set.OPTION.RSSIAmbientNoise=RssiAmbientNoiseEnable.RSSI_AMBIENT_NOISE_ENABLEDconfiguration_to_set.TRANSMISSION_MODE.WORTransceiverControl=WorTransceiverControl.WOR_TRANSMITTERconfiguration_to_set.TRANSMISSION_MODE.enableLBT=LbtEnableByte.LBT_DISABLEDconfiguration_to_set.TRANSMISSION_MODE.enableRSSI=RssiEnableByte.RSSI_ENABLEDconfiguration_to_set.TRANSMISSION_MODE.enableRepeater=RepeaterModeEnableByte.REPEATER_DISABLEDconfiguration_to_set.TRANSMISSION_MODE.fixedTransmission=FixedTransmission.FIXED_TRANSMISSIONconfiguration_to_set.TRANSMISSION_MODE.WORPeriod=WorPeriod.WOR_1500_010configuration_to_set.CRYPT.CRYPT_H=1configuration_to_set.CRYPT.CRYPT_L=1# Set the new configuration on the LoRa module and print the updated configuration to the consolecode,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, FixedTransmissionSend string messageHere an example of send data, you can pass a stringlora.send_transparent_message('pippo')lora.send_fixed_message(0,2,23,'pippo')Here the receiver codewhileTrue:iflora.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 configurationconfiguration_to_set.TRANSMISSION_MODE.enableRSSI=RssiEnableByte.RSSI_ENABLEDand set the flag to True in the receive_message methodcode,value,rssi=lora.receive_message(True)ResultSuccess!
pippoSend dictionary messageHere an example of send data, you can pass a dictionarylora.send_transparent_dict({'pippo':'fixed','pippo2':'fixed2'})lora.send_fixed_dict(0,0x01,23,{'pippo':'fixed','pippo2':'fixed2'})Here the receiver codewhileTrue:iflora.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 configurationconfiguration_to_set.TRANSMISSION_MODE.enableRSSI=RssiEnableByte.RSSI_ENABLEDand set the flag to True in the receive_dict methodcode,value,rssi=lora.receive_dict(True)ResultSuccess!
{'pippo': 'fixed', 'pippo2': 'fixed2'}
fixedThis is a porting of the Arduino library for EBYTE LoRa E22 devices to MicropythonSoon a complete tutorial of the original library on my sitewww.mischianti.orgEbyte LoRa E22 device for Arduino, esp32 or esp8266: settings and basic usageEbyte LoRa E22 device for Arduino, esp32 or esp8266: libraryEbyte LoRa E22 device for Arduino, esp32 or esp8266: configurationEbyte LoRa E22 device for Arduino, esp32 or esp8266: fixed transmission and RSSIEbyte LoRa E22 device for Arduino, esp32 or esp8266: power saving and sending structured dataEbyte LoRa E22 device for Arduino, esp32 or esp8266: WOR microcontroller and Arduino shieldEbyte LoRa E22 device for Arduino, esp32 or esp8266: WOR microcontroller and WeMos D1 shieldEbyte LoRa E22 device for Arduino, esp32 or esp8266: WOR microcontroller and esp32 dev v1 shieldhttps://downloads.arduino.cc/libraries/logs/github.com/xreef/EByte_LoRa_E22_Series_Library/An Arduino UNO shield to simplify the useYou can order the PCBhereInstruction and assembly video on 6 part of the guideAn WeMos D1 shield to simplify the useYou can order the PCBhereInstruction and assembly video on 6 part of the guideLoRa E22 (EBYTE LoRa sx1262/sx1268) series Library for Arduino, esp8266 and esp32-I create a library to manage EBYTE E22 series of LoRa device, very powerfull, simple and cheap device.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 agains 2.4 GHz for the NRF24L01) but at thrice the distance (from 4000m to 10000m).LoRa E22You can find hereAliExpress (433MHz 4Km)-AliExpress (433MHz 10Km)Please refer to my article to get updated SchemaLibraryYou can find my library here.To download.Click the DOWNLOADS button in the top right corner, rename the uncompressed folder LoRa_E22.Check that the LoRa_E22 folder contains LoRa_E22.cpp and LoRa_E22.h.Place the LoRa_E22 library folder your /libraries/ folder.You may need to create the libraries subfolder if its your first library.Restart the IDE.PinoutE22Pin No.Pin itemPin directionPin application1M0Input（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 output5AUXOutputPer 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).6VCCPower supply 2.3V~5.5V DC7GNDGroundAs you can see you can set various modes via M0 and M1 pins.ModeM1M0ExplanationNormal00UART 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 receiverConfiguration mode10Users can access the register through the serial port to
control the working state of the moduleDeep sleep mode11Sleep modeAs 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 schemaAs I already say It’s not important to connect all pin to the output of microcontroller, you can put M0 and M1 pins to HIGH or LOW to get desidered configuration, andif you don’t connect AUX the library set a reasonable delay to be sure that the operation is complete.AUX pinWhen transmitting data can be used to wake up external MCU and return HIGH on data transfer finish.LoRa E22 AUX Pin on transmissionWhen receiving AUX going LOW and return HIGH when buffer is empty.LoRa e22 AUX pin on receptionIt’s also used for self checking to restore normal operation (on power-on and sleep/program mode).LoRa e22 AUX pin on self-checkesp8266 connection schema is more simple because It work at the same voltage of logical communications (3.3v).LoRa E22 TTL 100 Wemos D1 fully connectedIt’s important to add 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)GNDGNDSimilar connection schema for esp32, but for RX and TX we use RX2 and TX2, because by default esp32 doesn’t have SoftwareSerial but have 3 Serial.Ebyte LoRa E22 device esp32 dev kit v1 breadboard full connectionE22esp32M0D21M1D19TXPIN RX2 (PullUP 4,7KΩ)RXPIN TX3 (PullUP 4,7KΩ)AUXPIN D18 (PullUP 4,7KΩ)VCC5V (but work with less power in 3.3v)GNDGNDBasic configuration optionADDHHigh address byte of module (the default 00H)00H-FFHADDLLow address byte of module (the default 00H)00H-FFHSPEDInformation about data rate parity bit and Air data rateCHANCommunication channel（410M + CHAN*1M）, default 17H (433MHz),valid only for 433MHz devicechek below to check the correct frequency of your device00H-1FHOPTIONType of transmission, packet size, allow special messageTRANSMISSION_MODEA lot of parameter that specify the transmission modalityOPTIONType of transmission, pull-up settings, wake-up time, FEC, Transmission powerSPED detailUART Parity bit:UART mode can be different between communication parties43UART parity bitConstant value008N1 (default)MODE_00_8N1018O1MODE_01_8O1108 E1MODE_10_8E1118N1 (equal to 00)MODE_11_8N1UART 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 value0001200UART_BPS_12000012400UART_BPS_24000104800UART_BPS_48000119600 (default)UART_BPS_960010019200UART_BPS_1920010138400UART_BPS_3840011057600UART_BPS_57600111115200UART_BPS_115200Air 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 value0000.3kAIR_DATA_RATE_000_030011.2kAIR_DATA_RATE_001_120102.4k (default)AIR_DATA_RATE_010_240114.8kAIR_DATA_RATE_011_481009.6kAIR_DATA_RATE_100_9610119.2kAIR_DATA_RATE_101_19211038.4kAIR_DATA_RATE_110_38411162.5kAIR_DATA_RATE_111_625OPTION detail####Sub packet settingThis 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 sizeConstant value00240bytes (default)SPS_240_0001128bytesSPS_128_011064bytesSPS_064_101132bytesSPS_032_11####RSSI Ambient noise enableThis 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 enableConstant value0EnableRSSI_AMBIENT_NOISE_ENABLED1Disable (default)RSSI_AMBIENT_NOISE_DISABLEDTRANSMISSION_MODE Detail####Enable RSSIWhen enabled, the module receives wireless data and it will follow an RSSI strength byte after output via the serial port TXD####Transmission typeTransmission 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 transmissionWhen enabled, wireless data will be monitored before it is transmitted, which can avoid interference to a certain extent, but may cause data delay.####WORWOR 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 cycleIf 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 500msThe longer the WOR monitoring interval period, the lower the average power consumption, but
the greater the data delayBoth the transmitter and the receiver must be the same (very important).Send receive messageFirst we must introduce a simple but usefully method to check if something is in the receiving bufferintavailable();It’s simply return how many bytes you have in the current stream.Normal transmission modeNormal/Transparent transmission mode is used to send messages to all device with same address and channel.LoRa E22 transmitting scenarios, lines are channelsFixed transmission have more scenariosLoRa E22 transmitting scenarios, lines are channelsThanksNow 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 usageEbyte LoRa E22 device for Arduino, esp32 or esp8266: libraryEbyte LoRa E22 device for Arduino, esp32 or esp8266: configurationEbyte LoRa E22 device for Arduino, esp32 or esp8266: fixed transmission and RSSIEbyte LoRa E22 device for Arduino, esp32 or esp8266: power saving and sending structured dataEbyte LoRa E22 device for Arduino, esp32 or esp8266: repeater mode and remote settingsEbyte LoRa E22 device for Arduino, esp32 or esp8266: WOR microcontroller and Arduino shieldEbyte LoRa E22 device for Arduino, esp32 or esp8266: WOR microcontroller and WeMos D1 shieldEbyte LoRa E22 device for Arduino, esp32 or esp8266: WOR microcontroller and esp32 dev v1 shield