Electronics Microcontrollers RF "/>

ESP32-based LoRa

10 August 2019 at 4:29 pm

Article image for ESP32-based LoRa

For several years I’ve been using LoRa radios from Adafruit for my students. This year, Adafruit are sold out so I’m need for an alternative. The first one I’m looking at is the TTGO LoRa 1.0 and it looks quite promising in terms of both performance and price.

The LoRa radios I’ve used from Adafruit are based on the Atmel SAMD M0 processor. They use the Feather form factor, they are well documented and very suited for teaching (as with everything shipped by Adafruit). The M0 versions did have it’s hiccups though, so the teaching experience was far from smooth as the M0 have a few conflicts and the software examples confuse many of the students. They also come without an antenna, so the students had to solder this. Not too big of a problem, but the price of $35 a piece is a “tad” expensive.

The TTGO on the other hand is $24 for two complete boards, meaning that the students no longer need to work in pairs to solve LoRa related tasks. This makes it much easier for students that for some reason miss that lecture. The boards may also include a tiny Oled that can be useful when testing, so this is a really good deal. They’re based on the ESP32 from Espressif and I’ve been wanting to get one of these boards into the hardware kits for a while and now is a good time as the software SDK is reasonably mature.

Easy to use

Getting these up and going is as easy as installing ESP32 support in your Arduino tool and selecting the TTGO LoRa board and its port. You can of course go the “traditional route” by using CMake/Ninja and ESP-IDF, but the official Arduino package covers what we need. Most of the standard Arduino examples will work, but it also comes with lots of good examples for spinning up small servers & clients using HTTP/UDP, OTA updates, BLE and even Azure IoT.

When you find code examples online, be sure to use code for the 1.0 boards and not examples for the 2.0 or 2.1 boards. If a sketch says it’s for the latter, the pinout is different, so check the table below for what pins to use. The ESP32 module still has quite a few pins available when subtracting the ones used by the LoRa radio (SX127x / RFM9x using SPI) and the Oled (using I2C). There’s also a user-controllable blue LED and the pin connected to the battery is connected via a voltage divider, so you can monitor the remaining charge.

The builtin Oled is really nice and something you don’t get with the boards from Adafruit. It’s a 128x64 pixel screen, so it can fit quite a bit of information. Note that you have to set pin 16 HIGH to use the Oled screen.

These are the pins used on the TTGO LoRa32 1.0:

BLUE_LED

2

VBAT_PIN

35

OLED_SDA

4

OLED_SCL

15

OLED_RST

16

SX1278_SCK

5

SX1278_MISO

19

SX1278_MOSI

27

SX1278_CS

18

SX1278_RESET

14

SX1278_IRQ

26

Power usage isn’t too bad on these modules either. I’ve tested briefly using some typical sketches:

Power use

Wh @ 5.1V

Deep Sleep

10mA

0.05

Blink

49mA

0.25

LoRa & Oled

54mA

0.27

Wifi (standby)

70mA

0.35

Wifi (working)

120mA

0.63

Overall I’m pretty sure that these will work just as well for teaching, so I’m placing an order for these.

The antenna is the worst part

As can be seen in Andreas Spiess excellent review of the TTGO LoRa 1.0 & Heltek LoRa board, the antenna is the largest disappointment with these boards. The 915Mhz version only shows an RSSI of 65 when two boards are next to each other. The antennas that come with the board will easily work from inside my house and about 50m around it with acceptable performance, so you may not need to upgrade them. I’m upgrading my boards to a proper antenna from Digikey, but the cheapest proper antenna is more than $8 so it kind of ruins the budget, but I need to have a couple of these anyway.

Multiple boards and not all from TTGO

The TTGO LoRa design is Open Source and several vendors produce these boards. Be aware of this and also note that there are several versions of the board. You can identify the lateer 2.0 and 2.1 versions easily since they have the USB connector to the long side, rather than in the middle of the short end as the 1.0 version I’m using. Also note that none of the sellers of the 1.0 module lists the correct pinout, but this article has a correct version.

Useful software for these boards

Given that you use the proper resources (listed below), you should get these boards up and running really easy. I don’t understand why Banggood, Aliexpress, ebay and other vendors provide code at all. It’s much better to link to a proper source. Here’s some of the sketches and resources I’ve found when testing:

Working library for the LoRa part of the 1.0 modules: https://github.com/YogoGit/TTGO-LORA32-V1.0

Working sketch to test battery: https://gist.github.com/jenschr/dfc765cb9404beb6333a8ea30d2e78a1

I2C detect sketch: https://gist.github.com/jenschr/5fed7920d861cc3e0b753dd64ed3cc68

Getting it onto the ThingsNetwork: https://www.thethingsnetwork.org/forum/t/big-esp32-sx127x-topic-part-3/18436

Two part 3D printable enclosure: https://www.thingiverse.com/thing:3443245

Neat online font converter for 1306 Oled’s http://oleddisplay.squix.ch