Skip to main content

Part 3: unleash your code

1. Introduction​

The first two parts of the Get started tutorial are now done. Good work! πŸ’ͺ

In this part, we will learn how to configure Luos engine to access to multiple boards in your physical network. Then, we will run our first example into these boards.

info

We will use the same board from the first two parts, but you also need a second board to create a network. Supported boards are listed here.

2. Create a physical network​

As we saw in Part 1, Luos engine allows you to define services and use them together on one MCU. What really sets Luos apart and makes it special is that you can also make services work together on separated MCUs.

Let's make a network with two boards!

In this part, we will use the β€œdefault wiring” defined by Luos to create a network of two MCUs. We will use a OneWire network, limiting the circuit to simple wires and pins:

  • Tx and Rx pins, which are connected together and wired to the Tx and Rx pins of the other board (see the next image).
  • One PTP wire.
tip

πŸ’‘ Luos Point-To-Point (PTP) connection allows you to find your board's physical position. Luos engine can deal with up to 8 PTP lines on each board to connect as many boards as you want.

caution

To prevent any mistakes, unplug the USB cables from the boards before wiring.

luos_img

To create your network, you have to identify the pins used to perform Luos communication:

Function nameArduino pinSTM32L432KC pinSTM32F072RB pinSTM32F401RE pinSTM32F410RB pinSTM32G431KB pinSeeeduino XIAO pinESP32 WROOM 32 Dev Kit
TXTxPA9 (D0)PA9 (D8)PB7(21)PB7 (21)PA9 (D0)D6Tx (SD2)
RXRxPA10 (D1)PA10 (D2)PB6 (D10)PB6 (D10)PA10 (D1)D7Rx (SD3)
PTPD6PB5 (D12)PA8 (D7)PB5 (D5)PB5 (D5)PB5 (D12)D1IO26

Below are the schematics of various boards and how to wire them:

luos_img

You should now be able to wire the two boards together. From now on, we will call these boards board 1 and board 2.

danger

After wiring the boards together, you will have to power both of them for the network to work correctly. In the next steps of this tutorial, board 1 will already be plugged to the computer with the USB cable. To power board 2, you can either connect the power output pin of board 1 (5V pin) to the power input pin of board 2 (Vin pin), or simply plug board 2 to another USB cable so that both boards are powered by the computer. In the first case, do not forget to wire the GND pins together on both boards.

3. Build a Luos distributed system​

In Part 1, you have downloaded or cloned the Get started code folder in your computer. We will use this code to demonstrate how Luos engine works using a network. We will begin by moving the blinker app service from board 1 to board 2 and see what happens next.

Flash board 1​

caution

Connect the USB cable of board 1 and leave the USB cable of board 2 disconnected.

  1. In VS Code, open the folder Get_started that corresponds to your board 1: file/open folder.

  2. From the left panel, locate and open the file src/main.c or src/Arduino.ino.

  3. Comment the following two lines to remove the blinker service from this board: Blinker_Init(); and Blinker_Loop();

    ...
    Luos_Init();
    Led_Init();
    Pipe_Init();
    Gate_Init();
    //Blinker_Init(); <== comment this line
    ...
    Luos_Loop();
    Led_Loop();
    Pipe_Loop();
    Gate_Loop();
    //Blinker_Loop(); <== comment this line
info

These lines trigger the initialization and looping execution of all the packages in your project.

  1. Check whether the proper board environnement is selected depending on your board:
luos_img
5. Build and flash _board 1_ by clicking on the arrow pointing to the right on the bottom left in VS Code.

Flash board 2​

caution

You should now unplug the USB cable of board 1 and connect the USB cable of board 2.

  1. In VS Code, open the folder Get_started project corresponding to your board 2, file/open folder. (If you have the same boards twice, you can open the same folder.)

  2. From the left panel, find and open the file src/main.c (or src/Arduino.ino for Arduino users).

  3. This time, comment the following six lines to remove all of the services except the blinker: Led_Init();, Pipe_Init();, Gate_Init();, Led_Loop();, Pipe_Loop();, and Gate_Loop();

    ...
    Luos_Init();
    //Led_Init(); <== comment this line
    //Pipe_Init(); <== comment this line
    //Gate_Init(); <== comment this line
    Blinker_Init();
    ...
    Luos_Loop();
    //Led_Loop(); <== comment this line
    //Pipe_Loop(); <== comment this line
    //Gate_Loop(); <== comment this line
    Blinker_Loop();
tip

In order to keep using Luos engine in your MCU, don't comment Luos_init() nor Luos_Loop().

  1. Check if the right board environment is selected depending on your board:
luos_img
5. Build and flash _board 2_ by clicking on the arrow pointing to the right on the bottom left in VS Code.

We are done!

To check if everything is OK, plug a USB cable into board 1, and power board 2 according to your previous choice (power pins from board 1 or USB cable from computer).

The LED of board 1 should blink thanks to the blinker app in board 2.

Congratulation, you've just created your first Luos distributed system. The objective of this part of our Get started was to use a service located in your first board, in another board to perform an action on it.

4. Use Pyluos to control your network​

You can now use pyluos-shell in your terminal, as we did in Part 2. You should see the following:

**$ pyluos-shell**
Searching for a gate available
Testing /dev/cu.usbserial-D308N885
Testing /dev/cu.usbmodem13102
Connected to "/dev/cu.usbmodem13102".
Sending detection signal.
Waiting for routing table...
Device setup.

Hit Ctrl-D to exit this interpreter.

Your luos device have been successfully mounted into a "device" object:
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ β•­node 1 /!\ Not certified ┃
┃ β”‚ Type Alias ID ┃
┃ β”œ> State led 2 ┃
┃ β”œ> Pipe Pipe 3 ┃
┃ β•°> Gate gate 1 ┃
β•”>┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
β•‘ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
β•šβ•β• 0>┃0 β•­node 2 /!\ Not certified ┃
┃ β”‚ Type Alias ID ┃
┃ β•°> Unknown blinker 4 ┃
>┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

As we can see, the blinker application is now displayed on a separate board. You still can control and interact with services on both boards with pyluos, as we did in Part 2.

For example, with your network connected to the computer, follow the step 3 from Part 2 and try to execute these lines one by one in an IPython session:

  1. Set up the blinking timing to 250ms (you should see the LED blink faster):
device.blinker.time=0.25
  1. Pause the blinking of the LED:
device.blinker.pause()
  1. Turn on the LED:
device.led.state=True
  1. Turn off the LED:
device.led.state=False
  1. Restart the blinking of the LED:
device.blinker.play()

5. Next steps​

In the next part of the Get started tutorial, we'll use the default network used by the Luos engine called Robus. The customization of your physical interface will be addressed in a future tutorial. The default hardware interface used by Robus is defined on the Robus HAL folder corresponding to your device.

6. Test your skills​

Congratulation, you have plugged, configured, and used your first Luos network!

The next step will show you how to visualize your network online through the Luos Network Display tool.

You can check out our tutorials to learn more about Luos and understand how to use the features of Luos engine. We also invite you to check out our documentation to learn more about the core concepts of Luos engine.

⭐ If you liked this tutorial, feel free to star our Luos engine repository⭐

A feedback? Let's discuss onΒ DiscordΒ |Β Github

The author: Nicolas Rabault

CEO at Luos
Nicolas Rabault

Former roboticist, research engineer in real-time embedded systems and founder of Pollen Robotics, Nicolas Rabault is CEO of Luos. Nicolas dedicated his life to develop tools making embedded subsets work together and simplifying reusability.

Related content


    Get started Repository