Main Content

TCP/IP Client Block Communication with Arduino Server

This example shows how the TCP/IP blocks in the Instrument Control Toolbox can be used with a remote server. In this example the server is running on an Arduino connected on the network. Instrument Control Toolbox provides TCP/IP blocks which are client-only blocks. Both the Send and Receive blocks can communicate via or to a server running remotely or in a different MATLAB session or to an echoserver on the same machine.

In this example there are two models which show the following:

1. Continuous stream of data from the server after a trigger.

2. On-demand read from the server after a command message is sent to the server.

Setup

You will have to load the INO file that the example provides onto an Arduino Uno and configure your network connections to the IP and Port settings in the INO file. Running the example opens both models associated with the example. You can run one at a time to get a better understanding of the difference between the two and notice how the TCP/IP blocks behave as client blocks while communicating with the server running on the Arduino.

Continuous stream of data from the server

This model consists of two subsystems:

1. Write start command - This is a triggered subsystem which at the first time interval trigger sends a start command to the server running on the Arduino using the TCP/IP Send Client block.

2. Read data stream - This is a triggered subsystem which continously reads the stream of data coming in from the Arduino server at every time interval using the TCP/IP Receive Client block.

On-demand read from the server

This model is set up to send an initial send command using the TCP/IP Send Client block for the server to acknowledge that a signal has been received and for it to send some data back which is read by the TCP/IP Receive Client block.

Results

This example makes use of the sensor attached to the analog pins on the Arduino. For the type of sensor attached you should see a corresponding output.