UDP Loopback Example

This example shows how to perform a loopback test by transmitting from a Desktop to the Arduino and back.

Contents

Step 1: Deploy to the Arduino

The ArduinoUdpLoopbackExample model uses the Arduino UDP Receive block to receive an array of integers and then the Arduino UDP Transmit block to transmit the array back to the desktop computer.

Use the following steps to deploy the model onto the Arduino:

  1. Open the model ArduinoUdpLoopbackExample.slx
  2. If you are using an Arduino other than the Arduino Mega 2560, change the configuration parameters to match the board that you are using.
  3. Double-click on the UDP Transmit block and change the ip address and port number to match your network's configuration.
  4. Build the model by clicking the build button

As soon as the deployment is finished, the Arduino should be transmitting UDP data.

Step 2: Run the host script

The host script uses the udp functionality from Instrument Control Toolbox to read incoming UDP data.

Use the following steps to read data on the host computer:

  1. Open the receiving function UdpLoopback_host.m
  2. Change the ip address and port number to match your network's configuration. i.e. h = udp('192.168.1.3',8888,'LocalPort',8887,'TimeOut',0.1);
  3. Run this function to receive UDP data from the Arduino

Note:

Incoming UDP data tends to be blocked by a firewall. If you are not receiving any UDP data, you might have to configure your firewall to accept incoming UDP data or turn it off momentarily.