Exploring LoRa RYLR896 with MicroPython

Introduction

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.

  1. VDD – for the supply voltage. This should be provided with minimum of 2V to 3.6V maximum.
  2. 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.
  3. RXD – for the UART serial receive pin.
  4. TXD – for the UART serial transmit pin.
  5. N/C – not connected.
  6. GND – for the ground pin.

Circuit Diagram

Raspberry Pi Pico with RYLR896:

  1. Connect RYLR896 VDD to Pico 3.3V pin.
  2. Connect RYLR896 RXD to Pico pin 6.
  3. Connect RYLR896 TXD to Pico pin 7.
  4. Connect RYLR896 GND to Pico GND pin.

ESP32 with RYLR896:

  1. Connect RYLR896 VDD to ESP32 3.3V pin.
  2. Connect RYLR896 RXD to ESP32 GPIO 26.
  3. Connect RYLR896 TXD to ESP32 GPIO 27.
  4. 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:

 1# More details can be found in TechToTinker.blogspot.com 
 2# George Bantique | tech.to.tinker@gmail.com
 3
 4from machine import Pin, UART
 5from time import sleep_ms
 6
 7class RYLR896:
 8    def __init__(self, port_num, tx_pin='', rx_pin=''):
 9        if tx_pin=='' and rx_pin=='':
10            self._uart = UART(port_num)
11        else:
12            self._uart = UART(port_num, tx=tx_pin, rx=rx_pin)
13                
14    def cmd(self, lora_cmd):
15        self._uart.write('{}rn'.format(lora_cmd))
16        while(self._uart.any()==0):
17            pass
18        reply = self._uart.readline()
19        print(reply.decode().strip('rn'))
20    
21    def test(self):
22        self._uart.write('ATrn')
23        while(self._uart.any()==0):
24            pass
25        reply = self._uart.readline()
26        print(reply.decode().strip('rn'))
27
28    def set_addr(self, addr):
29        self._uart.write('AT+ADDRESS={}rn'.format(addr))
30        while(self._uart.any()==0):
31            pass
32        reply = self._uart.readline()
33        print(reply.decode().strip('rn'))
34        print('Address set to:{}rn'.format(addr))
35
36
37    def send_msg(self, addr, msg):
38        self._uart.write('AT+SEND={},{},{}rn'.format(addr,len(msg),msg))
39        while(self._uart.any()==0):
40            pass
41        reply = self._uart.readline()
42        print(reply.decode().strip('rn'))
43        
44    def read_msg(self):
45        if self._uart.any()==0:
46            print('Nothing to show.')
47        else:
48            msg = ''
49            while(self._uart.any()):
50                msg = msg + self._uart.read(self._uart.any()).decode()
51            print(msg.strip('rn'))
52    
53
54lora = RYLR896(1) # Sets the UART port to be use
55sleep_ms(100)
56lora.set_addr(1)  # Sets the LoRa address

2. For the ESP32:

 1# More details can be found in TechToTinker.blogspot.com 
 2# George Bantique | tech.to.tinker@gmail.com
 3
 4from machine import Pin, UART
 5from time import sleep_ms
 6                                                                          
 7class RYLR896:
 8    def __init__(self, port_num, tx='', rx=''):
 9        if tx=='' and rx=='':
10            self._uart = UART(port_num)
11        else:
12            self._uart = UART(port_num, tx=tx, rx=rx)
13
14    def cmd(self, lora_cmd):
15        self._uart.write('{}rn'.format(lora_cmd))
16        while(self._uart.any()==0):
17            pass
18        reply = self._uart.readline()
19        print(reply.decode().strip('rn'))
20    
21    def test(self):
22        self._uart.write('ATrn')
23        while(self._uart.any()==0):
24            pass
25        reply = self._uart.readline()
26        print(reply.decode().strip('rn'))
27
28    def set_addr(self, addr):
29        self._uart.write('AT+ADDRESS={}rn'.format(addr))
30        while(self._uart.any()==0):
31            pass
32        reply = self._uart.readline()
33        print(reply.decode().strip('rn'))
34        print('Address set to:{}rn'.format(addr))
35              
36    def send_msg(self, addr, msg):
37        self._uart.write('AT+SEND={},{},{}rn'.format(addr,len(msg),msg))
38        while(self._uart.any()==0):
39            pass
40        reply = self._uart.readline()
41        print(reply.decode().strip('rn'))
42        
43    def read_msg(self):
44        if self._uart.any()==0:
45            print('Nothing to show.')
46        else:
47            msg = ''
48            while(self._uart.any()):
49                msg = msg + self._uart.read(self._uart.any()).decode()
50            print(msg.strip('rn'))
51            
52lora = RYLR896(2,rx=27,tx=26) # Sets the UART port to be use
53sleep_ms(100)
54lora.set_addr(2)  # Sets the LoRa address

References And Credits

  1. More details from the official page of RYLR896 https://reyax.com/products/rylr896/

  2. RYLR896 Datasheet: https://reyax.com/wp-content/uploads/2019/12/RYLR896_EN-1.pdf

  3. RYLR896 AT Command Reference: https://reyax.com/wp-content/uploads/2020/01/Lora-AT-Command-RYLR40x_RYLR89x_EN.pdf





2 comments

Are there any things that should be edited on the micropython code if you are trying to do this with two picos? does the address need to be changed on one of them from 1 to 0? also I am trying to accomplish this with a reyax rylr498, upon clicking run I get the shell out put:

Address set to : 1rn

When I try to run lora.test() I get an error showing +ERR=1

Reply to Hunter Sprague

Hi Hunter Sprague,

Pico 1: lora = RYLR896(1) # Sets the UART port to be use sleep_ms(100) lora.set_addr(1) # Sets the LoRa address

Pico 2: lora = RYLR896(1) # Sets the UART port to be use sleep_ms(100) lora.set_addr(2) # Sets the LoRa address

Reply to George Bantique

GitHub-flavored Markdown & a sane subset of HTML is supported.