Connecting to RAK811 or RAK4200 Lora Module

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
RS485
Posts: 4
Joined: Tue Sep 10, 2019 1:39 am

Connecting to RAK811 or RAK4200 Lora Module

Post by RS485 » Thu Sep 10, 2020 12:36 am

Hi Guys,

I am using Thonny as my IDE and v1.3 as the firmware I tried 1.2 and got the same result.

I am having some issues getting back a response using UART 2 on a DEVKIT ESP32.

Using a piece of terminal software on my pc and connecting it via a USB->COM works fine.

The board is a bit funny as it needs a \r\n at the end to get a response.

The code I tried is:
from machine import UART
uart=UART(2,115200)
uart.init(115200,bits=8,parity=None,stop=1,rx=16,tx=17)
uart.write("at+version\r\n")
print(uart.read())

It always seems to output None meaning there is nothing in the string, the weird thing is that print(uart) on the REPL I seem to get this weird output:
print(uart)
UART(2, baudrate=115201, bits=8, parity=None, stop=1, tx=17, rx=16, rts=-1, cts=-1, txbuf=256, rxbuf=256, timeout=0, timeout_char=1)
** Notice the baudrate ?
If someone can help me would appreciate it.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Connecting to RAK811 or RAK4200 Lora Module

Post by dhylands » Thu Sep 10, 2020 3:54 pm

When you set a baudrate, the driver will try to match the baudrate as best it can. What you're seeing is the actual baudrate being used.

The sender/receiver can typically tolerate a difference of 5-10% and still work (10% is pushing it, but 5% should be fine). 115201 baud is only 0.0009% which is essentially "perfect".

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Connecting to RAK811 or RAK4200 Lora Module

Post by pythoncoder » Fri Sep 11, 2020 7:20 am

I think your problem is that you are reading the UART before the data has arrived. By default machine.UART has a zero timeout so .read or .readline return immediately with None if there is no data. Incidentally, if your expected data is terminated with a newline, I recommend .readline.

Options are:
  • Delay for a period before issuing .read or .readline.
  • Instantiate the UART with e.g. timeout=5000 for a 5 second timeout.
  • Loop on .any until the expected number of characters have arrived.
  • Use the uasyncio StreamReader and StreamWriter methods.
For applications of any complexity the last option is the most powerful.
Peter Hinch
Index to my micropython libraries.

RS485
Posts: 4
Joined: Tue Sep 10, 2019 1:39 am

Re: Connecting to RAK811 or RAK4200 Lora Module

Post by RS485 » Sun Sep 13, 2020 10:18 pm

Thanks Peter ill give it a try today! I have also got a RFM95 and working on the following library:

https://github.com/fantasticdonkey/uLoRa

I kind of reverse engineering it to work with a ESP32 DEV KIT V1 and HopeRF RFM95W module working in the 915Mhz Band.

I got it to work with OTAA and ABP using AU frequencies.

The only issue is that I think the frame counter needs to be stored somewhere on restart of the board one of the ideas was to save the current framecount to FLASH I need to test it, ill be sharing the code soon as soon as I get it going in case someone else needs it.

Post Reply