dernasherbrezon / sx127x

Library to work with Semtech chips SX1276/77/78/79.
Apache License 2.0
31 stars 4 forks source link
esp-idf esp32 lora raspberry-pi raspberrypi semtech sx1276 sx1277 sx1278 sx1279

PlatformIO Registry Component Registry Quality Gate Status main

About

Library to work with semtech sx127x chips.

Features

There are several similar libraries exist, but this one is much better:

This library supports all standard LoRa features:

And FSK/OOK features:

How to use

esp-idf

Clone this repository somewhere, e.g.:

cd ~/myprojects/esp
git clone https://github.com/dernasherbrezon/sx127x.git

Add path to components:

set(EXTRA_COMPONENT_DIRS /home/user/myprojects/esp/sx127x)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(my-esp-project)

platformio

Add the following dependency to platformio.ini:

lib_deps = dernasherbrezon/sx127x

Linux

Linux version depends on kernel SPI driver only. Make sure it is enabled. Clone this repository somewhere, e.g.:

cd ~/myprojects/esp
git clone https://github.com/dernasherbrezon/sx127x.git

Add subdirectory:

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/sx127x)
target_link_libraries(my_application sx127x)

Custom architecture

It is possible to use this library in any other microcontroller architecture. To do this several steps are required.

  1. Implement functions to work via SPI. Interface is defined in include/sx127x_spi.h and put implementation somewhere inside your project.
  2. Clone this library into your project
  3. Connect all things together in your application's cmake file:
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/sx127x/include)
add_library(sx127x STATIC
        "${CMAKE_CURRENT_SOURCE_DIR}/sx127x/src/sx127x.c"
        "${CMAKE_CURRENT_SOURCE_DIR}/src/sx127x_custom_spi_implementation.c")
target_link_libraries(my_application sx127x)

Functions

All functions follow the same format:

sx127x_(modulation)_(rx or tx or empty)_(set or get)_(parameter)

Where:

Examples

examples folder contains the following examples:

Tests

There are several unit tests in the test folder. They can be executed on any host machine using the commands below:

cd test
mkdir build
cd build
cmake ..
make test

Integration tests

Integration tests can verify communication between real devices in different modes. Tests require two LoRa boards connected to the same host. It is possible to test on any other boards by overriding pin mappings in test/test_app/main.c. By default tests assume transmitter and receiver is TTGO lora32.

Before running tests from ESP-IDF make sure pytest is installed.

Run the following command to test:

cd test/test_app
idf.py build
pytest --target esp32 --port="/dev/ttyACM0|/dev/ttyACM1" pytest_*