ESP32 OGN DIY-Tracker

Introduction

A new series of modules appeared on the market, which are very suitable to make an OGN-Tracker.
The module contains ESP32 chipset and the sx1276 RF chip which is same chip as in the RFM95 RF modules.
You can find the modules by searching for "ESP32" and "sx1276". Most of them contain an 128x64pixel OLED display.

To make a functional OGN tracker it is enough to attach (almost) any GPS, and all the rest is software.
If you can, get a GPS which has a PPS output, this simplifies the exact timing acquisition.

ogn-tracker-esp32.jpg

Attractive features of the ESP32 chipset is Bluetooth and WiFi.
It is thus possible to connect the ESP32 Tracker to flight software like XCsoar or LK8000
and do things like automatic log upload after landing.
It is all up to the software, however, up to this date, such software does not exist yet.

Such a tiny tracker can also easily be installed in a drone: just connect the 5V power and the MAVlink port (two wires).
The first tests has been done and the tracker transmits the position of the drone and can alert the drone of the presence of other drones or aircrafts carrying the OGN-Tracker.
ogn-tracker-esp32-in-drone.jpg

Hardware

There are already few variants of the ESP32 modules suitable for our purpose.
Some of them are under label "HELTEC LoRa 32", some under label "TTGO".
When you get one, make sure you have the 868/915MHz version, not the 433MHz one.

All modules contain the sx1276 RF chip which is same as in the RFM95 modules.

All modules have the charging circuit for a single cell Li-Ion which can be very useful, if the tracker is to be run on its own batteries.

Some TTGO modules are with, some are without the OLED display.

All modules contain Bluetooth and WiFi interfaces.

I found here an interesting comparison between HELTEC and TTGO, which includes some RF measurements.

From my experience: I was surprised to find the reception range of the HELTEC module to be significantly better than the RFM69 or RFM95 modules. This would point to a rather good RF coupling circuit.

The conclusion from all this could be the following: we need to check the range and in particular watch the antennas.

Pinout

The pinout of TTGO and HELTEC is almost identical: the only difference is the LED on the board: on HELTEC modules it is connected to GPIO25 and on the TTGO to GPIO2.

Several pins are already assigned like the SPI for the RF chip or the I2C for the OLED display. Nethertheless the SPI and I2C can be re-used.

TTGO_pinout.jpg


Hardware particularities

All the modules I have seen (or know about) the RF crystal offset by 20 to 40ppm, thus about 20 or 40kHz frequency offset at 868MHz.
This needs correction, which needs to be performed once, and then it is stored in the NVS (Non-Volatile Storage) of the ESP32.
To make the correction by -20kHz send the command to the console:

$POGN,FreqCorr=-20

Ideally, measure the frequency offset with an OGN receiver, it should be less than +/-10kHz.
If you don't have access to the OGN receiver setup the -20kHz correction and once you are in range check the frequency offset
or ask OGN support.

There is one hardware difference I have noticed between HELTEC and TTGO: the LED on the PCB is on GPIO25 (HELTEC) or on GPIO2 (TTGO). The GPIO25 is otherwise DAC2 output, thus on the TTGO it is easier to use the DAC output for sound generation. Nevertheless it is still possible on HELTEC.

GPS module

GPS module should be with TTL UART data interface. There are some (rare) with UART RS232 and I2C, these are not directly supported.
Almost any NMEA GPS should work with the tracker. GPS which understands UBX or MTK commands to switch the serial port baudrate is preferred, as baud rate higher than 9600bps speeds up the position transmission effectively by one second.
When an UBX GPS is being used it is additionally switched to "airborne" navigation mode.

"Enable" control line to the GPS can be useful, although the software does not make yet any use of it.
Features like software power off can then be easily implemented.

GPS module: VK2828U

used in original DIY-Tracker, works fine, only the "enable" control line not clear to work yet.

GPS module: GN-801

this appears to be a good and cheap GNSS receiver, but beware of two particularities:

TTGO_GN-801_BMP280_.jpg

Here is a TTGO module (this one without OLED display) with GN-801 GPS and a BMP280 pressure sensor.
The enable (white) wire is not connected yet, as the resistor on the GPS module needs to be undone first.

MAVlink

Option for using MAVlink telemetry port instead of a GPS is being tested. This way the tracker can be connected to a drone autopilot which sends telemetry using MAVlink protocol. This feature is now being tested with ArduPilot APM 2.6

ESP32 toolchain

To program the ESP32 chipset you need a software toolchain, which can be installed either on Windows or Linux, including the Raspberry PI.
Official instructions are here.

Note: Toolchain is designed for linux, on Windows you may install e.g. MSYS2 which will give you linux-style programming environment.

Raspberry PI:

sudo apt-get update
sudo apt-get install git wget make libncurses-dev flex bison gperf python python-serial

cd
git clone https://github.com/donny681/xtensa-esp32-elf-raspberry.git
git clone --recursive https://github.com/espressif/esp-idf.git
cd esp-idf
git submodule update --init
cd

UBUNTU:

sudo apt-get update
sudo apt-get install git wget make libncurses-dev flex bison gperf python python-serial

ESP32 toolchain for Linux is available for download from Espressif website:

Download the file, then extract it into ~/esp directory:

mkdir -p ~/esp
cd ~/esp
tar -xzf ~/Downloads/xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0.tar.gz

The toolchain will be extracted into ~/esp/xtensa-esp32-elf/ directory.

Install the ESP_IDF:

cd ~/esp

git clone --recursive https://github.com/espressif/esp-idf.git
cd esp-idf
git submodule update --init
cd

RPI & UBUNTU ENV settings:

Note: To use it, you will need to update your PATH environment variable in ~/.profile file. To make xtensa-esp32-elf available for all terminal sessions, add the following line to your ~/.profile file

export PATH=$PATH:~/xtensa-esp32-elf-raspberry/xtensa-esp32-elf/bin
export IDF_PATH=~/esp-idf

If you want to run the toolchain from an UBUNTU VM this Vagrantfile might be useful.

Communication with the ESP32 module

Communication and powering/charging the ESP32 is done through the USB.
The USB port emulates the CP210x serial port and thus the system sees it as one of the serial ports.
There can be several ESP32 connected to a single computer and then they can be flashed or monitored at same time.
You don't need a separate programmer to upload the software or files to the ESP32.

You need to know the name of the serial port where your ESP32 is connected.
Check the list of serial ports before and after connecting the device: on Linux type:

ls /dev/tty*

or check the system log files, on Linux:
dmesg | tail -n 30

Make note of the device name eg. ttyUSB1

run

make menuconfig

In the "Espressif IoT Development Framework Configuration" application go to
menuconfig —> Serial Flasher config find (/dev/ttyUSB0) change to your port.When you put the ESP32 module into a box it is certainly worth to leave the USB accessible,
as then uploading a new software or changing the configuration or powering/charging is non-problematic.


Software

Getting from github

git clone https://github.com/pjalocha/esp32-ogn-tracker.git
cd esp32-ogn-tracker

Configuring the project

You need to tell it which serial port is your ESP32 connected to, type:

make menuconfig

The ESP32-DIY tracker uses the function: uxTaskGetSystemState() so we need to request on the menuconfig the following option:
menuconfig —> components —> FreeRTOS —> Enable Free RTOS trace Facility

Choosing options, changing pin-out

edit files:

  • main/hal.h for general options
  • main/hal.cpp for exact pinout

ESP32 is fairly flexible about the pin assignment, for peripherals likes UART, SPI or I2C almost any pin can be chosen.
If you have good reasons you may relocate for example the GPS pins: data Rx/Tx, PPS and Enable.
Pins for the RF chip and the OLED display are fixed by the module construction.

Compiling

type (in the project directory):

make

or to speed it up:
make -j2

Make will take long time at the first compile or when you change any options in the menuconfig.
Otherwise it would only recompile the project files you have changed since the most recent make.

Uploading to ESP32

type:

make partition_table-flash
make flash

Configuring the Tracker

Open a serial terminal, on Linux: minicom
and configure it for 115200bps, 8bit, no parity, no hardware flow control

sudo minicom -D /dev/ttyUSB0 -b 115200 -8

or Monitor
To see the ESP32 DIY tracker application is indeed running, type make monitor. This command is launching IDF Monitor application:

$ make monitor

MONITOR
--- idf_monitor on /dev/ttyUSB0 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:4548
load:0x40078000,len:0
load:0x40078000,len:13176
entry 0x40078d38
I (127) cpu_start: Pro cpu up.
I (127) cpu_start: Single core mode
I (128) heap_init: Initializing. RAM available for dynamic allocation:
I (131) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (137) heap_init: At 3FFC3260 len 0001CDA0 (115 KiB): DRAM
I (144) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
I (150) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (156) heap_init: At 40089AF4 len 0001650C (89 KiB): IRAM
I (163) cpu_start: Pro cpu start user code
I (181) cpu_start: Starting scheduler on PRO CPU.
$POGNR,0,0,,+0.0,0,+0,,*6A
TaskGPS:
TaskRF: v12
$POGNR,0,0,,-112.0,0,+27,,*5B
$POGNR,0,0,,-112.0,2,+28,,*56
TaskGPS: 9600bps
$POGNR,0,0,,-112.0,4,+27,,*5F
$POGNR,0,0,,-112.0,6,+28,,*52
TaskGPS: 19200bps
$POGNR,0,0,,-112.0,8,+28,,*5C
$POGNR,0,0,,-112.0,10,+28,,*65
TaskGPS: 38400bps
$POGNR,0,0,,-112.0,12,+27,,*68
$POGNR,0,0,,-112.0,14,+28,,*61
TaskGPS: 57600bps
$POGNR,0,0,,-112.0,16,+28,,*63
$GPRMC,,V,,,,,,,,,,N*53
$GPGGA,,,,,,0,00,99.99,,,,,,*48
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
...

You should see a stream of NMEA messages.
Type a command like:

$POGNS,Pilot=Pawel,FreqCorr=-20,Reg=EC-AC9,Model=JANUS

Type Ctrl-C on the terminal and check if there is a response

$GPGGA,104308.00,,,,,0,00,99.99,,,,,,*68
1:3:8A0749 RFM95/+14dBm -20.0kHz CON:115200bps
GPS: 57600bps,1.00s,NMEA,UBX,BaudOK,ModeOK
Task            Pr. Stack, 216.180kB free
main            01 3356
IDLE            00 536
GPS             04 1392
PROC            03 1284
RF              04 1256
Tmr Svc         01 1656
ipc0            24 624
esp_timer       22 4220
SPIFFS: 0kB used, 875kB total
Address      = 0x8A0749; # [24-bit]
AddrType     = 0x3; #  [2-bit]
AcftType     = 0x1; #  [4-bit]
Console      = 115200; #  [  bps]
TxPower      = +14; #  [  dBm]
FreqCorr     = -20.0; #  [  kHz]
TempCorr     = +0; #  [ degC]
PressCorr    = +0.0; #  [   Pa]
TimeCorr     = +0; #  [    s]
GeoidSepar   = +47.0; #  [    m]
Pilot        = Pawel #  [char]
Manuf        =  #  [char]
Model        =  #  [char]
Reg          =  #  [char]
Base         =  #  [char]
ICE          =  #  [char]
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30

Aircraft Type

The default is "glider" (1), but you can change it. In particular for flight log to see the towing aircrafts correctly it is recommended to set trackers in the towing planes to "tow-plane" (2)

Address type

The default is OGN (3) but you can change to be ICAO address type (1)

ICAO address

If you want your tracker transmit the ICAO address of your aircraft

RF frequency correction

The ESP32 modules appear to have cheap crystals which need correcting. This far all the modules I have seen required -20kHz and one -40kHz correction.

References

Referenced: http://esp32.net
Pinout http://esp32.net/images/Heltec/WIFI-LoRa-32/Heltec_WIFI-LoRa-32_DiagramPinoutFromTop.jpg
http://esp32.net/images/Heltec/WIFI-LoRa-32/Heltec_WIFI-LoRa-32_DiagramPinoutFromBottom.jpg
Arduino code https://robotzero.one/heltec-wifi-lora-32
ESP32 API https://esp-idf.readthedocs.io/en/latest/api-reference/index.html
UART example https://github.com/espressif/esp-idf/blob/f4009b94dca9d17b909e1094d6e3d7dbb75d52c0/examples/peripherals/uart_echo
SPI example https://github.com/espressif/esp-idf/tree/f4009b94dca9d17b909e1094d6e3d7dbb75d52c0/examples/peripherals/spi_master
I2C example https://github.com/espressif/esp-idf/tree/f4009b94dca9d17b909e1094d6e3d7dbb75d52c0/examples/peripherals/i2c
OLED driver https://github.com/olikraus/u8g2/tree/master/csrc
OLED datasheet https://cdn-shop.adafruit.com/datasheets/SSD1306.pdf
OLED example https://github.com/yanbe/ssd1306-esp-idf-i2c
OLED article http://robotcantalk.blogspot.co.uk/2015/03/interfacing-arduino-with-ssd1306-driven.html
GPS GN-801 pic https://ae01.alicdn.com/kf/HTB1TQFZnnTI8KJjSsphq6AFppXat.jpg
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License