Let’s consider the following example to understand the basic logic of the SNODE Arduino library.
There are three nodes each of which has one or more sensors. Node 1 has three sensors (Button 1, Button 2, Button 3). Node 2 has two sensors (Button and Led). Node 3 has a sensor (RGB Led). The figure below shows the structure of the Node network with sensors.
Figure 8 – Node network
Each node must be assigned to a unique id as mentioned earlier. In our case, let it be the following IDs: Node ID = 50, Node ID = 60, Node ID =70.
Sensor addresses are automatically assigned during their registration. And their value will be such as those are shown in the figure below.
Task:Three nodes are connected to the same network.
- Button Sensor = 1 of Node ID = 50 should turn on and off Led Sensor = 2 of Node Id = 60.
- Button Sensor = 2 of Node ID = 50 should turn on and off Green Led Sensor = 1 of Node Id = 70.
- Button Sensor = 3 of Node ID = 50 should turn on and off Red Led Sensor = 1 of Node Id = 70.
- Button Sensor = 1 of Node ID = 60 should turn on and off Blue Led Sensor = 1 of Node Id = 70.
On the picture below with the help of arrows is shown schematic connection between sensors (one sensor is controlled by another) of each of the node.
Note : Node ID = 60 has two types of sensors (input and output). The Led Sensor is output. The Button Sensor is input.
Figure 9 – Node network diagram
A short video below shows how the SNODE network works.
The following figure is the pin connections of Arduino boards (Nano and Micro), MCP2515 CAN bus shield, Button and Led Modules.
The full source code could be found here.
Download or Clone the library from GitHub with:
Let’s consider the source code of the example of Node ID 60 (Button and Led Sensors).
If you want to run the code on another arduino board, uncomment the necessary one in the file.
The table below shows the pin to pin connection (Arduino Nano, Micro and MCP2515 CAN Bus Shield).
|Arduino Nano||Arduino Micro||The MCP2515 CAN Bus Shield|
|5 V||5 V||VCC|
The SNODE library uses the standard SPI interface. Hardware Abstraction Layer (HAL) could be found here.
Add header files:
Initialization of the SNODE library and registration of node sensors:
The SNODE_Registration function is used to register sensors of the node. The pointer to the SNODE_SENSOR_REG structure is used as the input parameter of the function (const PSNODE_SENSOR_REG pSensor). The struct of the Button Sensor is as follows.
The struct of the Led Sensor is as follows.
The SNODE_ProcessPacket function should be called in a loop in order to procedure the SNODE Engine (receive and send frames, multi-frames, timings, etc.).