Skip to content

aizukanne/ESP32-micropython-lora

 
 

Repository files navigation

This is a modified version of pycom's micropython originally written for the LoPy which is an ESP32 with an SX1272 LoRa chip (RFM92). I added libraries for the SX1276 LoRa module ( RFM95W). The code will work with any ESP32 and SX1276 LoRa module ( RFM95W). The pin connections are as follows:

For ESP32 Revision 1

RADIO_MOSI------------GPIO27
RADIO_MISO------------GPIO19
RADIO_SCLK------------GPIO5
RADIO_NSS-------------GPIO18
RADIO_DIO-------------GPIO23

With this, the LoRaWAN Gateway code and other LoRa scripts in micropython available at this link will work https://github.com/pycom/pycom-libraries/tree/master/examples/lorawan-nano-gateway.

TODO: Transmit is not working at the moment but I hope to have that fixed ASAP.

The MicroPython project

ESP32 DevKit C

This is the MicroPython project, which aims to put an implementation of Python 3.x on microcontrollers and small embedded systems. You can find the official website at micropython.org.

WARNING: this project is in beta stage and is subject to changes of the code-base, including project-wide name changes and API changes.

MicroPython implements the entire Python 3.4 syntax (including exceptions, "with", "yield from", etc., and additionally "async" keyword from Python 3.5). The following core datatypes are provided: str (including basic Unicode support), bytes, bytearray, tuple, list, dict, set, frozenset, array.array, collections.namedtuple, classes and instances. Builtin modules include sys, time, and struct, etc. Select ports have support for _thread module (multithreading). Note that only subset of Python 3.4 functionality implemented for the data types and modules.

See the repository www.github.com/micropython/pyboard for the MicroPython board (PyBoard), the officially supported reference electronic circuit board.

Major components in this repository:

  • py/ -- the core Python implementation, including compiler, runtime, and core library.
  • unix/ -- a version of MicroPython that runs on Unix.
  • exp32/ -- a version of MicroPython that runs on the ESP32 based boards from Pycom.
  • stmhal/ -- a version of MicroPython that runs on the PyBoard and similar STM32 boards (using ST's Cube HAL drivers).
  • minimal/ -- a minimal MicroPython port. Start with this if you want to port MicroPython to another microcontroller.
  • tests/ -- test framework and test scripts.
  • docs/ -- user documentation in Sphinx reStructuredText format.

Additional components:

  • bare-arm/ -- a bare minimum version of MicroPython for ARM MCUs. Used mostly to control code size.
  • teensy/ -- a version of MicroPython that runs on the Teensy 3.1 (preliminary but functional).
  • pic16bit/ -- a version of MicroPython for 16-bit PIC microcontrollers.
  • cc3200/ -- a version of MicroPython that runs on the CC3200 from TI.
  • esp8266/ -- an experimental port for ESP8266 WiFi modules.
  • tools/ -- various tools, including the pyboard.py module.
  • examples/ -- a few example Python scripts.

The subdirectories above may include READMEs with additional info.

"make" is used to build the components, or "gmake" on BSD-based systems. You will also need bash and Python (at least 2.7 or 3.3).

The Unix version

The "unix" port requires a standard Unix environment with gcc and GNU make. x86 and x64 architectures are supported (i.e. x86 32- and 64-bit), as well as ARM and MIPS. Making full-featured port to another architecture requires writing some assembly code for the exception handling and garbage collection. Alternatively, fallback implementation based on setjmp/longjmp can be used.

To build (see section below for required dependencies):

$ cd unix
$ make axtls
$ make

Then to give it a try:

$ ./micropython
>>> list(5 * x + y for x in range(10) for y in [4, 2, 1])

Use CTRL-D (i.e. EOF) to exit the shell. Learn about command-line options (in particular, how to increase heap size which may be needed for larger applications):

$ ./micropython --help

Run complete testsuite:

$ make test

Unix version comes with a builtin package manager called upip, e.g.:

$ ./micropython -m upip install micropython-pystone
$ ./micropython -m pystone

Browse available modules on PyPI. Standard library modules come from micropython-lib project.

External dependencies

Building Unix version requires some dependencies installed. For Debian/Ubuntu/Mint derivative Linux distros, install build-essential (includes toolchain and make), libffi-dev, and pkg-config packages.

Other dependencies can be built together with MicroPython. Oftentimes, you need to do this to enable extra features or capabilities. To build these additional dependencies, first fetch git submodules for them:

$ git submodule update --init

Use this same command to get the latest versions of dependencies, as they are updated from time to time. After that, in unix/ dir, execute:

$ make deplibs

This will build all available dependencies (regardless whether they are used or not). If you intend to build MicroPython with additional options (like cross-compiling), the same set of options should be passed to make deplibs. To actually enabled use of dependencies, edit unix/mpconfigport.mk file, which has inline descriptions of the options. For example, to build SSL module (required for upip tool described above), set MICROPY_PY_USSL to 1.

In unix/mpconfigport.mk, you can also disable some dependencies enabled by default, like FFI support, which requires libffi development files to be installed.

The ESP32 version

The "esp32" port requires an xtensa gcc compiler, which can be downloaded from the Espressif website:

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

export PATH=$PATH:$HOME/esp/xtensa-esp32-elf/bin

Alternatively, you may create an alias for the above command. This way you can get the toolchain only when you need it. To do this, add different line to your ~/.bash_profile file::

alias get_esp32="export PATH=$PATH:$HOME/esp/xtensa-esp32-elf/bin"

Then when you need the toolchain you can type get_esp32 on the command line and the toolchain will be added to your PATH.

You also need the ESP IDF along side this repository in order to build the ESP32 port. To get it:

$ git clone https://github.com/pycom/pycom-esp-idf.git

After cloning, make sure to checkout all the submodules:

$ cd pycom-esp-idf
$ git submodule update --init

Finally, before building, export the IDF_PATH variable

$ export IDF_PATH=~/pycom-esp-idf

To build and flash your LoPy for 868MHz regions:

$ cd esp32
$ make BOARD=LOPY TARGET=boot clean
$ make BOARD=LOPY TARGET=boot
$ make BOARD=LOPY LORA_BAND=USE_BAND_868 TARGET=app
$ make BOARD=LOPY LORA_BAND=USE_BAND_868 flash

or for 915MHz regions:

$ cd esp32
$ make BOARD=LOPY TARGET=boot clean
$ make BOARD=LOPY TARGET=boot
$ make BOARD=LOPY LORA_BAND=USE_BAND_915 TARGET=app
$ make BOARD=LOPY LORA_BAND=USE_BAND_915 flash

or the WiPy 2.0:

$ cd esp32
$ make BOARD=WIPY TARGET=boot
$ make BOARD=WIPY TARGET=app
$ make BOARD=WIPY flash

or the SiPy:

$ cd esp32
$ make BOARD=SIPY TARGET=boot
$ make BOARD=SIPY TARGET=app
$ make BOARD=SIPY flash

Make sure that your board is placed into programming mode, otherwise flahing will fail. To do this, connect P2 to GND and then reset the board.

About

A fork of MicroPython with the ESP32 port customized to run on ESP32 + SX1276 Lora Module.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 92.7%
  • C++ 2.7%
  • Python 2.6%
  • Objective-C 1.2%
  • Makefile 0.3%
  • HTML 0.3%
  • Other 0.2%