Exploring LoRa RYLR896 with MicroPython
In this article, we will explore the Reyax LoRa module RYLR896 using MicroPython. For this we will used both a Raspberry Pi Pico and an ESP32.
PINOUT:
From left to right facing front.
- VDD – for the supply voltage. This should be provided with minimum of 2V to 3.6V maximum.
- NRST – for the active-low RESET pin. This could be tied to microcontroller’s ground so that when microcontroller is reset, so the LoRa is also be resetted.
- RXD – for the UART serial receive pin.
- TXD – for the UART serial transmit pin.
- N/C – not connected.
- GND – for the ground pin.
CIRCUIT DIAGRAM:
Raspberry Pi Pico with RYLR896:

- Connect RYLR896 VDD to Pico 3.3V pin.
- Connect RYLR896 RXD to Pico pin 6.
- Connect RYLR896 TXD to Pico pin 7.
- Connect RYLR896 GND to Pico GND pin.
ESP32 with RYLR896:

- Connect RYLR896 VDD to ESP32 3.3V pin.
- Connect RYLR896 RXD to ESP32 GPIO 26.
- Connect RYLR896 TXD to ESP32 GPIO 27.
- Connect RYLR896 GND to ESP32 GND pin.
VIDEO DEMONSTRATION:
CALL TO ACTION:
For any concern, write your message in the comment section.
You might also like to support my journey on Youtube by Subscribing. Click this to Subscribe to TechToTinker.
Thank you and have a good days ahead.
See you,
– George Bantique | tech.to.tinker@gmail.com
SOURCE CODE:
1. For the Raspberry Pi Pico:
# More details can be found in TechToTinker.blogspot.com
# George Bantique | tech.to.tinker@gmail.com
from machine import Pin, UART
from time import sleep_ms
class RYLR896:
def __init__(self, port_num, tx_pin='', rx_pin=''):
if tx_pin=='' and rx_pin=='':
self._uart = UART(port_num)
else:
self._uart = UART(port_num, tx=tx_pin, rx=rx_pin)
def cmd(self, lora_cmd):
self._uart.write('{}rn'.format(lora_cmd))
while(self._uart.any()==0):
pass
reply = self._uart.readline()
print(reply.decode().strip('rn'))
def test(self):
self._uart.write('ATrn')
while(self._uart.any()==0):
pass
reply = self._uart.readline()
print(reply.decode().strip('rn'))
def set_addr(self, addr):
self._uart.write('AT+ADDRESS={}rn'.format(addr))
while(self._uart.any()==0):
pass
reply = self._uart.readline()
print(reply.decode().strip('rn'))
print('Address set to:{}rn'.format(addr))
def send_msg(self, addr, msg):
self._uart.write('AT+SEND={},{},{}rn'.format(addr,len(msg),msg))
while(self._uart.any()==0):
pass
reply = self._uart.readline()
print(reply.decode().strip('rn'))
def read_msg(self):
if self._uart.any()==0:
print('Nothing to show.')
else:
msg = ''
while(self._uart.any()):
msg = msg + self._uart.read(self._uart.any()).decode()
print(msg.strip('rn'))
lora = RYLR896(1) # Sets the UART port to be use
sleep_ms(100)
lora.set_addr(1) # Sets the LoRa address
2. For the ESP32:
# More details can be found in TechToTinker.blogspot.com
# George Bantique | tech.to.tinker@gmail.com
from machine import Pin, UART
from time import sleep_ms
class RYLR896:
def __init__(self, port_num, tx='', rx=''):
if tx=='' and rx=='':
self._uart = UART(port_num)
else:
self._uart = UART(port_num, tx=tx, rx=rx)
def cmd(self, lora_cmd):
self._uart.write('{}rn'.format(lora_cmd))
while(self._uart.any()==0):
pass
reply = self._uart.readline()
print(reply.decode().strip('rn'))
def test(self):
self._uart.write('ATrn')
while(self._uart.any()==0):
pass
reply = self._uart.readline()
print(reply.decode().strip('rn'))
def set_addr(self, addr):
self._uart.write('AT+ADDRESS={}rn'.format(addr))
while(self._uart.any()==0):
pass
reply = self._uart.readline()
print(reply.decode().strip('rn'))
print('Address set to:{}rn'.format(addr))
def send_msg(self, addr, msg):
self._uart.write('AT+SEND={},{},{}rn'.format(addr,len(msg),msg))
while(self._uart.any()==0):
pass
reply = self._uart.readline()
print(reply.decode().strip('rn'))
def read_msg(self):
if self._uart.any()==0:
print('Nothing to show.')
else:
msg = ''
while(self._uart.any()):
msg = msg + self._uart.read(self._uart.any()).decode()
print(msg.strip('rn'))
lora = RYLR896(2,rx=27,tx=26) # Sets the UART port to be use
sleep_ms(100)
lora.set_addr(2) # Sets the LoRa address
REFERENCES AND CREDITS:
1. More details from the official page of RYLR896
2. RYLR896 Datasheet:
3. RYLR896 AT Command Reference:
hi George,
Do you know how to do a hardware reset on the RYLR896?
I tried grounding pin 2 – NRST with no effect.
Es posible almacenar en una variable el valor de lora.read_msg()