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-engine as a library. Writing luos_engine and the needed networks libs in the section lib_deps will download the Luos-engine library from PIO registry and will build and link everything needed by your project.


Since version 3.0.0 luos-engine is network independent. You can choose the network you want to use by adding the corresponding network library in the section lib_deps.

Fill in the file platformio.ini accordingly:

build_unflags = -Os
build_flags =
-include node_config.h
-DROBUSHAL=STM32F0 ;Optional: Luos-engine will try to use the same HAL as LuosHAL if not defined
-DSERIALHAL=STM32F0 ;Optional: Luos-engine will try to use the same HAL as LuosHAL if not defined
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_engine@^X.Y.Z → Minimal version of Luos-engine (writing nothing here will download the last version).

2. Include Luos-engine in your main file

At the top of the main file, add #include "luos-engine.h" and the network libs you want. With this line, you just added Luos-engine library to your project so that you can use Luos API.

#include "stm32f0xx_hal.h"
#include "luos_engine.h"
#include "robus_network.h"
#include "serial_network.h"


int main(void)
// Init

// Loop
while (1)


Either Luos-engine library or any other Luos-engine packages or network that you will create or add have two special functions: Init() and Loop().

-Init function is called once, at MCU boot. -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.