FLProg - combining Arduino boards in the information ring
- Tutorial
Starting with version 1.10.5, the FLProg program allows you to combine several Arduino boards into a ring UART network. First, consider how this happens. The boards are interconnected in accordance with the circuit shown in the title illustration. Suppose that board 1 sends through a UART a data packet containing the identifiers of the board, variable, as well as the value of the variable. Board 2 accepts this packet and if it does not need data from this variable, it simply sends this packet further. If, in accordance with the program, the value of this variable is necessary for the controller, then the value from the packet is copied to the internal variable, and the packet is also sent further along the ring.
When in this way the packet, having passed the entire ring, returns to the board that sent it, packet transmission will stop.
Thus, the data from the package is available to any board connected to the ring, and any of the boards can also be the initiator of sending a package.
Scheme of the test bench:
The logic of the following:
- Arduino No. 1 receives data on temperature and humidity from sensors.
- Arduino No. 2 displays the temperature from the DS18B20.
- Arduino No. 3 displays temperature and humidity from a DHT-22 sensor.
To avoid angry comments that such logic is not necessary and is nonsense, I will clarify that this project is purely educational and is intended to explain the principles of data transmission through the information ring. To do this, we add a little more nonsense to the logic of work.
- The digital temperature value from the DS18B20 sensor catches Arduino№3, then converts it into a string and sends it to the ring. This line catches Arduino№2 and displays on the display.
- The digital temperature value from the DHT-22 sensor catches Arduino№2, then converts it into a string and sends it to the ring. This line catches Arduino№3 and displays on the display.
- The digital humidity value from the DHT-22 sensor catches the Arduino # 3, then converts it to a string and displays it on the display.
So, let's begin.
We open the FLProg program and create a project for Arduino№1. On the first board we throw the OneWire bus scan unit (library of elements, the Miscellaneous folder). This block on the leading edge at the input En scans the OneWire bus and, when there are sensors on it, it adds the detected addresses to the associated arrays. To parameterize a block, we call the block editor (double click on the block).
- First, create the new OneWire bus.
- Then create an array. Since we plan to have one sensor on the bus, we create one array.
Now we will organize the startup scheme of this block once at the start of the program. To do this, we will assemble such a scheme.
R - The trigger is located in the “Triggers” folder of the element library. It serves to highlight the leading edge of the pulse supplied to the input. At its output there will be an impulse lasting one cycle of the program during the transition of the input level from low to high.
Then we create a new board and drag the DS18x2x temperature sensor onto it (element library, Sensors folder). We call the block editor and parameterize the sensor.
- From the drop-down list, select the previously created OneWire bus on pin 4
- Select the mode of setting the address "Array"
- Select the previously created Sensor array
- We set the periodic polling mode of the sensor, with a polling frequency of once every 1 second.
Now the value received from the sensor must be sent to the ring.
In the FLProg program, you can connect the controller to the ring in two ways. In this project for Arduino№1, we will consider the first method - through blocks sending a variable to the ring.
We pull out the “Send variable to the ring” block (element library, UART folder) onto the board, and call the block editor for it.
- First, add the controller to the ring.
In the window that opens, you must select the port for connecting to the ring, the port speed, and set the device name in the ring. Also, for the convenience of working with the project, it is advisable to create a file of a list of ring variables through which all the controllers participating in it will be synchronized. - Then we create a variable that will be transferred to the ring.
In the variable creation window, you must specify the variable name and its type. - After that we set the periodic mode of sending the variable, with a period of 1 second.
After parameterizing the block, we connect the sensor and send blocks to each other and set the constant true at the input En of the send block.
We create a new board and drag the DHT-22 sensor onto it (element library, Sensors folder). We call the block editor and parameterize the sensor.
- Select the sensor connection pin
- Choose a sensor type
- We set the availability of temperature and humidity outputs
- We set the periodic method of polling the sensor with a frequency of 1 second
Then we drag two blocks of sending the variable to the ring on the third board, select the existing ring in the block settings, and create a variable in each of them.
The field of which we will connect the blocks with each other, and put the constants true on the inputs of En blocks of sending variables.
With the project for Arduino№1 finished. Such a scheme should work:
Now create a new project for Arduino№2.
Immediately connect the board to the ring. Here we use the second method, through the project tree. We open the tree up to the “Communications” branch inclusively and right-click on the “Rings” item. In the context menu that appears, select the "Add Ring" item.
The already known ring parameters window opens. We again need to enter the device name in the ring and select the port through which the device is connected to the ring. But now we do not create a ring variable file, but select the previously created one. In this case, variables between projects are automatically synchronized.
All ring parameters can be changed through the project tree by calling the context menu on the corresponding branches.
According to the Arduino№2 algorithm, it catches the temperature variable from the DHT-22 sensor, turns its value into a string and sends it to the ring. To do this, drag the “Get variable from the ring” block onto the diagram (element library, “UART” folder) and call the editor for it.
In the editor, select the ring and the corresponding variable.
Then drag and drop the “String Conversion” block (element library, the “Type Conversion” folder) and connect the input of this block to the output of the “Get Variable from the Ring”
block. Then we call the editor for the “String Conversion” block.
Since the input of this block is a Float type value, we have the ability to set the number of decimal places when converting to a string. I think one decimal place is enough for us.
Then we pull out the “Send variable to ring” block (element library, UART folder) onto the circuit, and using the editor, select the ring and create a new variable that will be sent to the ring. We also set a periodic sending mode, with a period of 1 second.
Then we connect the blocks together and set the constant true at the input En of the variable sending block.
Create a new board and drag the “Get variable from the ring” block (element library, “UART” folder) onto it and call the editor for it. In the editor, select the connected ring. Since, according to the algorithm, Arduino№3 is preparing the value for display on the display, we will create a new variable that this controller will send to us.
Now drag and drop the block “Display on the HD44780 chip” (the library of elements, the “Displays” folder) onto the diagram, and call the editor for it and parameterize it.
- Create a new display
- Set the connection according to the scheme
- Set display parameters
- Configure the display of data from the input block
- Set up the center of the first row
After that, we connect the blocks and set the constant true at the input En of the display block.
With the project for Arduino№2 finished. Such a scheme should work:
We create a project for Arduino№3.
We connect the controller to the ring using any of the above methods. When connecting, select the previously created ring variable file.
According to the algorithm, the Arduino№3 controller captures the temperature value from the DS18B20 sensor from Arduino№1 and converts it to a string and sends this string to a ring for Arduino№2. All the necessary variables for this we already have. Therefore, similar to Arduino№2. drag and drop the blocks “Get a variable from the ring” (library of elements, folder “UART”), “Convert strings” (library of elements, folder “Type Conversion”) and the block “Send variable to ring” (library of elements, UART folder) onto the diagram. Then we parameterize them.
“Getting a variable from a ring”
“Converting strings”
“Sending a variable to a ring”
After that we collect them into a circuit
We create a new board to display the temperature from the DHT-22 sensor. In the same way as Arduino№2, drag “Getting variable from the ring” (library of elements, folder “UART”) and “Display on the chip HD44780” (library of elements, folder “Displays”). We parameterize them.
“Getting the variable from the ring”
“Display on the HD44780 chip” We
connect together.
We create a new board for displaying humidity.
We also drag and drop onto the board the “Get variable from the ring” block (library of elements, the “UART” folder) and parameterize.
Then drag the “String Conversion” block (library of elements, the “Type Conversion” folder), connect it to the “Get Variable from the Ring” block and parameterize the same.
Well and last of all we drag the “Display on HD44780 chip” block (library of elements, the “Displays” folder). When parameterizing the unit, select an existing display and display the humidity value in the center of the second line.
We connect the blocks together.
The creation of the program for Arduino№3 is complete.
Final result.
Thanks for attention.