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.
Connecting to RAK811 or RAK4200 Lora Module
Re: Connecting to RAK811 or RAK4200 Lora Module
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".
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".
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Connecting to RAK811 or RAK4200 Lora Module
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:
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.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Connecting to RAK811 or RAK4200 Lora Module
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.
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.