forked from beegee-tokyo/SX126x-Mesh-Network
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4d36a8
commit 0d3a714
Showing
24 changed files
with
3,310 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.pio | ||
.vscode/.browse.c_cpp.* | ||
.vscode/c_cpp_properties.json | ||
.vscode/launch.json | ||
.vscode/ipch | ||
Generated | ||
Docs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Continuous Integration (CI) is the practice, in software | ||
# engineering, of merging all developer working copies with a shared mainline | ||
# several times a day < https://docs.platformio.org/page/ci/index.html > | ||
# | ||
# Documentation: | ||
# | ||
# * Travis CI Embedded Builds with PlatformIO | ||
# < https://docs.travis-ci.com/user/integration/platformio/ > | ||
# | ||
# * PlatformIO integration with Travis CI | ||
# < https://docs.platformio.org/page/ci/travis.html > | ||
# | ||
# * User Guide for `platformio ci` command | ||
# < https://docs.platformio.org/page/userguide/cmd_ci.html > | ||
# | ||
# | ||
# Please choose one of the following templates (proposed below) and uncomment | ||
# it (remove "# " before each line) or use own configuration according to the | ||
# Travis CI documentation (see above). | ||
# | ||
|
||
|
||
# | ||
# Template #1: General project. Test it using existing `platformio.ini`. | ||
# | ||
|
||
# language: python | ||
# python: | ||
# - "2.7" | ||
# | ||
# sudo: false | ||
# cache: | ||
# directories: | ||
# - "~/.platformio" | ||
# | ||
# install: | ||
# - pip install -U platformio | ||
# - platformio update | ||
# | ||
# script: | ||
# - platformio run | ||
|
||
|
||
# | ||
# Template #2: The project is intended to be used as a library with examples. | ||
# | ||
|
||
# language: python | ||
# python: | ||
# - "2.7" | ||
# | ||
# sudo: false | ||
# cache: | ||
# directories: | ||
# - "~/.platformio" | ||
# | ||
# env: | ||
# - PLATFORMIO_CI_SRC=path/to/test/file.c | ||
# - PLATFORMIO_CI_SRC=examples/file.ino | ||
# - PLATFORMIO_CI_SRC=path/to/test/directory | ||
# | ||
# install: | ||
# - pip install -U platformio | ||
# - platformio update | ||
# | ||
# script: | ||
# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"board": "esp8266:esp8266:huzzah", | ||
"configuration": "xtal=80,vt=flash,exception=disabled,ssl=all,eesz=4M,ip=lm2f,dbg=Disabled,lvl=None____,wipe=none,baud=115200", | ||
"port": "COM6" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
// See http://go.microsoft.com/fwlink/?LinkId=827846 | ||
// for the documentation about the extensions.json format | ||
"recommendations": [ | ||
"platformio.platformio-ide" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"terminal.integrated.env.windows": { | ||
"PATH": "C:\\Users\\beegee\\.platformio\\penv\\Scripts;C:\\Users\\beegee\\.platformio\\penv;B:\\DevTools\\Python2.7\\;B:\\DevTools\\Python2.7\\Scripts;B:\\DevTools\\ESP-IDF Tools\\toolchain\\bin;B:\\DevTools\\ESP-IDF Tools\\mconf-idf;B:\\DevTools\\ESP-IDF Tools;C:\\Program Files (x86)\\Intel\\iCLS Client\\;C:\\Program Files\\Intel\\iCLS Client\\;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files (x86)\\Intel\\UCRT\\;C:\\Program Files\\Intel\\UCRT\\;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\IPT;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\IPT;B:\\DevTools\\Microsoft VS Code\\bin;C:\\Program Files (x86)\\Bitvise SSH Client;C:\\Program Files (x86)\\Nordic Semiconductor\\nrf5x\\bin\\;B:\\msys32\\usr\\bin;B:\\DevTools\\NRF52-Flashtools;B:\\DevTools\\Cmake\\bin;C:\\Program Files\\Git\\cmd;C:\\Users\\beegee\\.platformio\\penv\\Scripts;B:\\DevTools\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin;B:\\DevTools\\GNU Tools ARM Embedded\\8 2018-q4-major\\bin;B:\\DevTools\\Python2.7\\;B:\\DevTools\\Python2.7\\Scripts;B:\\DevTools\\ESP-IDF Tools\\toolchain\\bin;B:\\DevTools\\ESP-IDF Tools\\mconf-idf;B:\\DevTools\\ESP-IDF Tools;C:\\Program Files (x86)\\Intel\\iCLS Client\\;C:\\Program Files\\Intel\\iCLS Client\\;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files (x86)\\Intel\\UCRT\\;C:\\Program Files\\Intel\\UCRT\\;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\IPT;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\IPT;B:\\DevTools\\Microsoft VS Code\\bin;C:\\Program Files (x86)\\Bitvise SSH Client;C:\\Program Files (x86)\\Nordic Semiconductor\\nrf5x\\bin\\;B:\\msys32\\usr\\bin;B:\\DevTools\\NRF52-Flashtools;B:\\DevTools\\Cmake\\bin;C:\\Program Files\\Git\\cmd;C:\\Users\\beegee\\.platformio\\penv\\Scripts;B:\\DevTools\\GNU Tools Arm Embedded\\7 2018-q2-update\\bin;B:\\DevTools\\GNU Tools ARM Embedded\\8 2018-q4-major\\bin", | ||
"PLATFORMIO_CALLER": "vscode" | ||
}, | ||
"files.associations": { | ||
"functional": "cpp" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,60 @@ | ||
# SX126x-Mesh-Network | ||
A simple LoRa Mesh network low level layer for the Semtech SX126x transceivers. | ||
SX126x-Mesh-Network | ||
=== | ||
## Scope of the tutorial: | ||
This tutorial will just create a simple Mesh network that sends randomly messages to other nodes within the Mesh network. There is no data structure or gateway functions to other networks like GSM or WiFi. | ||
The goal here is to have a working core Mesh network that can be used to build up a second layer of communication which can be anything you want to do, e.g. a network of sensors that send out their sensor data. | ||
|
||
## Target hardware: | ||
The code is written to work on either an ESP32 or a nRF52 microcontroller and is not compatible with other microcontrollers. The LoRa transceivers used are [Semtech SX1262 transceivers](https://www.semtech.com/products/wireless-rf/lora-transceivers/sx1262). They are either connected to the microcontroller as a Adafruit Feather compatible breakout ([Circuitrocks Alora RFM1262](https://circuit.rocks/product:2685)) or integrated into a SOC together with a Nordic nRF52 ([Insight ISP4520](https://www.insightsip.com/products/combo-smart-modules/isp4520)). | ||
|
||
## And another important thing: | ||
This code is NOT written to work with the ArduinoIDE. It is structured to be compiled under [PlatformIO](https://platformio.org/) using one of the IDE’s supported by PlatformIO. My favorite is Visual Studio Code. | ||
|
||
## Tutorial for this example | ||
A fairly deep explanation how this software works can be found in the [Alora RFM162 – LoRa Mesh Network](https://learn.circuit.rocks/alora-rfm162-lora-mesh-network) article | ||
|
||
## How to compile for the different platforms | ||
Have a look into the platformio.ini file. You can see examples for 5 different target boards, 2 nRF52 based boards and 3 ESP32 boards from different sources. | ||
|
||
The code depends heavily on compiler defines to adapt different LoRa transceiver boards, used GPIO's, used libraries and available peripherals (display). These defines are set in the platformio.ini file. | ||
Here is a list of the important defines: | ||
- -DADAFRUIT=1 | ||
- Select code specific for the Adafruit nRF52832 Feather board | ||
- -DHAS_DISPLAY=1 | ||
- Set for that have an OLED display based on the SH1106 chipset. This option requires to set as well | ||
- -DOLED_SDA=23 | ||
- defines the GPIO used to connect the SDA | ||
- -DOLED_SCL=22 | ||
- defines the GPIO used to connect the SCL | ||
- -DRED_ESP=1 | ||
- Used to select a specific setup for an Elecrow ESP32S WIFI BLE Board v1.0 board | ||
- -DIS_NOT_FEATHER=1 | ||
- Used to distinguish between the Adafruit ESP32 HUZZAH Feathers and other ESP32 boards | ||
|
||
Other defines used in the code, but setup by the PlatformIO packages | ||
- ISP4520 | ||
- Set for Insight ISP4520 boards | ||
- ESP32 | ||
- Set for ESP32 boards | ||
- NRF52 | ||
- Set for nRF52 boards | ||
|
||
## Debug output over BLE | ||
In the application the BLE UART is activated and the boards starts advertising. On a nRF52 based board there is a DFU service, the OTA update service of Nordic to update the firmware on the chip. On all boards there is a simple BLE-UART service to send debug messages over BLE to a BLE-UART app like the [Serial Bluetooth Terminal](https://play.google.com/store/apps/details?id=de.kai_morich.serial_bluetooth_terminal) for Android | ||
|
||
## Library Dependencies | ||
#### [SX126x-Arduino](https://github.com/beegee-tokyo/SX126x-Arduino) | ||
- Arduino library for LoRa communication with Semtech SX126x chips. It is based on Semtech's SX126x libraries and adapted to the Arduino framework for ESP32, ESP8266 and nRF52832. It will not work with other uC's like AVR. | ||
|
||
#### [esp8266-oled-ssd1306](https://github.com/ThingPulse/esp8266-oled-ssd1306) | ||
- Driver for the SSD1306 and SH1106 based 128x64, 128x32, 64x48 pixel OLED display running on ESP8266/ESP32 | ||
|
||
## Platform Dependencies | ||
#### [Adafruit_nRF52_Arduino](https://github.com/adafruit/Adafruit_nRF52_Arduino) | ||
- The Arduino BSP for Adafruit Bluefruit nRF52 series | ||
|
||
#### [arduino-esp32](https://github.com/espressif/arduino-esp32) | ||
- The Arduino BSP for Espressif ESP32 based board. | ||
|
||
#### [Arduino Core for Circuitrocks Alora Boards](https://github.com/beegee-tokyo/Circuitrocks_ISP4520_Arduino) | ||
- The Arduino BSP for the ISP4520 boards. Manual installation pf the BSP is required as explained [here](https://github.com/beegee-tokyo/Circuitrocks_ISP4520_Arduino#bsp-installation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
#ifdef NRF52 | ||
#include <Arduino.h> | ||
#include "nrf_timer.h" | ||
#include "nrf52Timer.h" | ||
|
||
static void defaultFunc(){}; | ||
static funcPtr_t Timer_callbackPtr; | ||
|
||
TimerClass::TimerClass(int timer, int channel) | ||
{ | ||
nrf_timer = nrf_timers[timer]; | ||
cc_channel = nrf_timer_cc_channel_t(channel); | ||
|
||
Timer_callbackPtr = defaultFunc; | ||
Timers[timer] = this; | ||
|
||
// Timer mode with 32bit width | ||
nrf_timer_bit_width_set(nrf_timer, NRF_TIMER_BIT_WIDTH_32); | ||
nrf_timer_mode_set(nrf_timer, NRF_TIMER_MODE_TIMER); | ||
nrf_timer_frequency_set(nrf_timer, NRF_TIMER_FREQ_16MHz); | ||
} | ||
|
||
void TimerClass::attachInterrupt(funcPtr_t callback, int microsec) | ||
{ | ||
// This function will be called when time out interrupt will occur | ||
if (callback) | ||
{ | ||
Timer_callbackPtr = callback; | ||
} | ||
else | ||
{ | ||
Serial.println("ERROR: callback function pointer is null."); | ||
return; | ||
} | ||
|
||
// Start if not already running (and reset?) | ||
nrf_timer_task_trigger(nrf_timer, NRF_TIMER_TASK_START); | ||
nrf_timer_task_trigger(nrf_timer, NRF_TIMER_TASK_CLEAR); | ||
|
||
// Clear and enable compare interrupt | ||
nrf_timer_int_mask_t chanel_mask = nrf_timer_compare_int_get(cc_channel); | ||
nrf_timer_int_enable(nrf_timer, chanel_mask); | ||
|
||
if (nrf_timer == nrf_timers[1]) | ||
NVIC_EnableIRQ(TIMER1_IRQn); | ||
if (nrf_timer == nrf_timers[2]) | ||
NVIC_EnableIRQ(TIMER2_IRQn); | ||
if (nrf_timer == nrf_timers[3]) | ||
NVIC_EnableIRQ(TIMER3_IRQn); | ||
if (nrf_timer == nrf_timers[4]) | ||
NVIC_EnableIRQ(TIMER4_IRQn); | ||
|
||
// Program compare register between 0 & 2**28 (max on 32 bits @16 ticks/us) | ||
if (microsec < 0) | ||
microsec = 0; | ||
if (microsec >= 1 << 28) | ||
microsec = (1 << 28) - 1; | ||
uint32_t ticks = nrf_timer_us_to_ticks(microsec, NRF_TIMER_FREQ_16MHz); | ||
nrf_timer_cc_write(nrf_timer, cc_channel, ticks); | ||
} | ||
|
||
// Should be called in the Timer_callbackPtr() function | ||
inline void TimerClass::detachInterrupt() | ||
{ | ||
// Stop timer | ||
nrf_timer_task_trigger(nrf_timer, NRF_TIMER_TASK_STOP); | ||
|
||
// Disable timer compare interrupt | ||
nrf_timer_int_mask_t chanel_mask = nrf_timer_compare_int_get(cc_channel); | ||
nrf_timer_int_disable(nrf_timer, chanel_mask); | ||
|
||
// Clear event - TODO? | ||
nrf_timer_event_t event = nrf_timer_compare_event_get(chanel_mask); | ||
nrf_timer_event_clear(nrf_timer, event); | ||
} | ||
|
||
// Timer 0 is used by the soft device but Timer 1, 2, 3 and 4 are available | ||
extern "C" void TIMER1_IRQHandler(void) | ||
{ | ||
if (Timers[1]) | ||
{ | ||
Timers[1]->detachInterrupt(); | ||
Timer_callbackPtr(); | ||
} | ||
} | ||
|
||
extern "C" void TIMER2_IRQHandler(void) | ||
{ | ||
if (Timers[2]) | ||
{ | ||
Timers[2]->detachInterrupt(); | ||
Timer_callbackPtr(); | ||
} | ||
} | ||
|
||
extern "C" void TIMER3_IRQHandler(void) | ||
{ | ||
if (Timers[3]) | ||
{ | ||
Timers[3]->detachInterrupt(); | ||
Timer_callbackPtr(); | ||
} | ||
} | ||
|
||
extern "C" void TIMER4_IRQHandler(void) | ||
{ | ||
if (Timers[4]) | ||
{ | ||
Timers[4]->detachInterrupt(); | ||
Timer_callbackPtr(); | ||
} | ||
} | ||
|
||
NRF_TIMER_Type *nrf_timers[] = {NRF_TIMER0, NRF_TIMER1, NRF_TIMER2, | ||
NRF_TIMER3, NRF_TIMER4}; | ||
|
||
TimerClass *Timers[5] = {0}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifdef NRF52 | ||
#ifndef _TIMER_H_ | ||
#define _TIMER_H_ | ||
|
||
typedef void (*funcPtr_t)(); | ||
|
||
class TimerClass | ||
{ | ||
public: | ||
TimerClass(int timer = 1, int channel = 0); | ||
void attachInterrupt(funcPtr_t callback, int microsec); | ||
inline void detachInterrupt(); | ||
|
||
private: | ||
NRF_TIMER_Type *nrf_timer; | ||
nrf_timer_cc_channel_t cc_channel; | ||
}; | ||
|
||
extern NRF_TIMER_Type *nrf_timers[5]; | ||
extern TimerClass *Timers[5]; | ||
|
||
#endif // _TIMER_H_ | ||
#endif // NRF52 |
Oops, something went wrong.