[IoT] LoRa with MicroPython on the ESP8266 and ESP32

German Gensetskiy
Go Wombat
Published in
2 min readJan 18, 2019

LoRa (Long Range) is a patented digital wireless data communication technology with low power consumption. That’s really important features for IoT applications.

That technology has great potential and we were interested in better understanding it so we decided to try it out.

LoRa Modules

And we’re ordered different modules from Aliexpress… We had E32–868T20D 868MHz, ESP32 with SX1278 433MHZ, Ra-02 AiThinker 433MHz RFM96W 433 MHz.

Not that we needed all that for the testing, but once you get locked into a serious LoRa collection, the tendency is to push it as far as you can.

Next step was in understanding how to use it with micropython. Because we love Python and therefore we love Micropython ❤. We found out that there is exists an SX127x driver for ESP8266, ESP32 and Raspberry Pi. And a clean version for ESP32 named uPyLora.

import time

from lora.sx127x import SX127x
from lora.controller_esp32 import ESP32Controller


controller = ESP32Controller()
lora = controller.add_transceiver(
SX127x(name='LoRa'),
pin_id_ss=ESP32Controller.PIN_ID_FOR_LORA_SS,
pin_id_RxDone=ESP32Controller.PIN_ID_FOR_LORA_DIO0
)

counter = 0
print("LoRa Sender")

while True:
payload = 'Hello ({0})'.format(counter)
print("Sending packet: \n{}\n".format(payload))

lora.println(payload)

counter += 1
time.sleep(1)
Picocom output

And with ESP32 it worked well.

But unfortunately, on ESP8266 that code throws memory error. The simplest way was to slightly optimize that driver by removing constant variables that were used only once and placing their values straight into the code.

Unfortunately, we have only one antenna that was included with ESP32 we ordered. That test was done on a low range, I tried to move away with module without antenna — and maximal communication range was around 1.5–2 meters. So make sure to order one for each module or check that there will be pin to attach at least a simple wire.

Thanks for reading! Hope you’ll find that info helpful.

German Gensetskiy under the support of Go Wombat Team.

And that’s helped.

--

--