Part 3: unleash your code
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.
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 make 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.
💡 Luos Point-To-Point (PTP) connection allows 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.
To prevent any mistakes, unplug the USB cables from the boards before wiring.
To create your network, you have to identify the pins used to perform Luos communication:
|Function name||Arduino pin||STM32L432KC pin||STM32F072RB pin||STM32F401RE pin||STM32F410RB pin||STM32G431KB pin|
|TX||Tx||PA9 (D0)||PA9 (D8)||PB7(21)||PB7 (21)||PA9 (D0)|
|RX||Rx||PA10 (D1)||PA10 (D2)||PB6 (D10)||PB6 (D10)||PA10 (D1)|
|PTP||D6||PB5 (D12)||PA8 (D7)||PB5 (D5)||PB5 (D5)||PB5 (D12)|
Below are the schematics of various boards and how to wire them:
- Arduino MKR
- Arduino Classic
- NUCLEO 32
- NUCLEO 64
You should now be able to wire the two boards together. From now on, we will call these boards board 1 and board 2.
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 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 is happening next.
Flash board 1
Connect the USB cable of board 1 and leave the USB cable of board 2 disconnected.
In VS Code, open the folder Get_started project corresponding to your board 1:
From the left panel, locate and open the file src/main.c or src/Arduino.ino file.
Comment the two lines to remove the blinker service from this board:
//Blinker_Init(); <== comment this line
//Blinker_Loop(); <== comment this line
These lines trigger the initialization and looping execution of all the packages in your project.
- Check whether the proper board environnement is selected depending on your board:
Flash board 2
You should now unplug the USB cable of board 1 and connect the USB cable of board 2.
In VS Code, open the folder Get_started project corresponding to your board 2,
file/open folder. (If you have twice the same board, you will open the same folder.)
From the left panel, find and open the file src/main.c (or src/Arduino.ino for Arduino users).
This time, comment the six lines to remove all the services except the blinker:
//Led_Init(); <== comment this line
//Pipe_Init(); <== comment this line
//Gate_Init(); <== comment this line
//Led_Loop(); <== comment this line
//Pipe_Loop(); <== comment this line
//Gate_Loop(); <== comment this line
In order to keep using Luos engine in your MCU,
Luos_Loop() must not be commented.
- Check if the proper board environment is selected depending on your board:
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 just created your first Luos distributed system where a service from one board is used in another board to perform an action on this second board.
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:
Searching for a gate available
Connected to "/dev/cu.usbmodem13102".
Sending detection signal.
Waiting for routing table...
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:
- Set up the blinking timing to 250ms (you should see the LED blink faster):
- Pause the blinking of the LED:
- Turn on the LED:
- Turn off the LED:
- Restart the blinking of the LED:
In this Get started tutorial, we used the default network used by 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.
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](https://github.com/Luos-io/luos_engine ⭐