Skip to main content

Part 2: Include Luos to your project

1. Include the Luos library in your project

The file platformio.ini in your project describes the precompiler variables and the library depencies of your project.

In our case, we want to use Luos as a library. Writing "Luos" and "LuosHAL" in the section lib_deps will download the Luos library from PIO registry and will build and link Luos to your project.

Fill in the file platformio.ini accordingly:

build_unflags = -Os
build_flags =
-include node_config.h
lib_deps =
debug_tool = stlink
upload_protocol = stlink

At the line LUOSHAL=STM32F0, we selected Luos HAL for the chosen MCU family (as we use the board STM32F072Rb, it means it is the STM32F0 family).


You can choose a minimal version that you want for your Library: Luos@^X.Y.Z → Minimal version of Luos (writing nothing here will download the last version). LuosHAL@^X.Y.Z → Minimal version of LuosHAL (writing nothing here will download the last version).

2. Include Luos in your main file

At the top of the main file, add #include "Luos.h". With this line, you just added Luos Library to your project so that you can use Luos API.

#include "stm32f0xx_hal.h"
#include "luos_engine.h"


int main(void)
// Init

// Loop
while (1)


Either Luos library or any future Luos packages that you will create have two special functions: Init() and Loop().

-Init function is called once, at MCU reset. -Loop function will be called sequentially in a loop.


Each API begins with the name of the file where it is declared. A simple rule of coding, but very convenient.

3. Include Luos PTP interruption

In the case that you have a network, you need a way to detect other MCUs in this network. With the Luos network, we use two pins (see the documentation page topology and network for more information).

Those special pins, called PTP pins, are necessary for the topology detection. They need an interruption handler to work on a Luos network.

  1. Open the file stm32xx_it.c
  2. fill in the end of the file with the following code:
/* STM32F0xx Peripheral Interrupt Handlers */
/* Add here the Interrupt Handlers for the used peripherals. */
/* For the available peripheral interrupt handler names, */
/* please refer to the startup file (startup_stm32f0xx.s). */
void EXTI4_15_IRQHandler(void)


This is the default configuration of F0 Family used for the STM32F072RB (see LuosHAL_Config.h). If you need to adapt you hardware, put your changes in the file node_config.h in your project.

4. Compile your Luos project

As you can see in the terminal when you build your project, PlatformiIO will download the last version of the Luos library from its registry, and add it as a library to your project.


Upload the code to your MCU by clicking on the right arrow button at the bottom of the IDE.


You have now created a project with an ST framework or with an Arduino framework, and configured everyting to begin with Luos.

Rename your project and add packages like in the trainings, in order to make great projects with Luos! You can check the full solution here.

The author: Thomas Salembier

CTO at Luos
Thomas Salembier

Today CTO of Luos, Thomas as a background in electronics and embedded software engineer with more than 12 years of experience in various fields of industry such as space, aeronautics, automotive and medical.

Related content