Simplecomm library to send data through any arduino stream
4 January, 2019 by
Simplecomm library to send data through any arduino stream
Boot & Work Corp. S.L., Support Team


This is Industrial Shields library for all the different Industrial Shields PLC’s .


Ethernet or 20 I/Os PLC:      Ethernet PLC     20 I/Os PLC

SimpleComm Industrial Shields Library:  SimpleComm Github repository


With the SimpleComm library you can send data through any Arduino Stream: RS-485, RS-232, Ethernet… It is enough flexible to support different kind of communication typologies: Ad-hoc, Master-Slave, Client-Server… Using an easy to use API. The SimpleCoom library is included on Tools40 library.

The SimplePacket class encapsulates the data into a packet.

The setData function fills up the packet with the desired data for sending it to a remote device. It is possible to fill up the packet with different types of data: bool, char, unsigned char, int, unsigned int, long, unsigned long, double, string and even custom data types.

int num = 1234;
SimplePacket packet1;
SimplePacket packet2;
packet2.setData("text data");
typedef struct {
    int a;
    char b;
} customType;
customType customVar;
customVar.a = 1234;
customVar.b = 'B';
SimplePacket packet3;
packet3.setData(customVar, sizeof(customVar));

There are also getter functions, which return the data contained in the packet, depending on the data type. If length is specified, it returns the data length in bytes.

int num = packet1.getInt();
const char *str = packet2.getString();
const customType *var = (const customType*) packet3.getData();

The SimpleComm class is the interface for sending and receiving packets through the desired Arduino Stream.

The begin(byte) function enables the communication system and sets the devices identifier/address. Each device has its own address which identifies it. Devices receive packets sent to them, using their address, but not to others.

byte address = 1234;

It is possible to send packets to a device with an address, and optionally define the packet type.

byte destination = 87;
SimpleComm.send(RS485, packet, destination);
SimpleComm.send(RS485, packet, destination, 0x33);

To send packets to all devices it is possible to send a broadcast packet with the destination field set to 0 (zero).

byte destination = 0;
SimpleComm.send(RS485, packet, destination);

The receive function receives a packet from another device, using the stream. It returns true if a packet is really received.

SimplePacket rxPacket;
if (SimpleComm.receive(RS485, rxPacket)) {
    // A packet is received

It is also possible to receive all the packets (sniffer mode) by setting the SimpleComm address to 0 (zero). This mode is useful when implementing a gateway node between Ethernet and RS-485.

byte address = 0;

How to install the Tools40 library in the Arduino IDE

  1. Download the Tools40 library from the GitHub. Click on: “Clone or download”. After that download the zip file on your desktop.
  2. Add the library on the Arduino IDE. Click on: Sketch–>Include library–>Add .ZIP libraryand choose “”. After choose the the library has to be charged. To verify the library is added correctly you can see the library on: //File/Examples/Tools40
  3. Now your library is correctly installed and you can see examples to how to use that library on our PLCs using different protocols such as Ethernet (Server and Client connections) or RS-485.

Simplecomm library to send data through any arduino stream
Boot & Work Corp. S.L., Support Team
4 January, 2019
Share this post

Looking for your ideal PLC?

Take a look at this product comparison with other industrial controllers Arduino-based.

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.

Industrial PLC comparison >>

Do you want more information?

Just fill the form!

Tell me more!