UDP Receive Example

This example shows how to Receive UDP data with the Arduino. The host desktop computer will be used to transmit UDP data.

Contents

Step 1: Deploy to the Arduino

The UdpReceive_arduino model uses the UDP Receive block to receive an array of uint8's from the host computer.

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

  1. Open the model ArduinoUdpReceiveExample.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 Receive block and change the ip address and port number to match your network's configuration.
  4. Place the model in external mode by clicking the run button

As soon as the deployment is finished, the Arduino should be ready to receive UDP data. It will then display the received data after transmission from the host script.

Step 2: Run the host script

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

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

  1. Open the transmitting host function UdpTransmit_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 transmit UDP data to the Arduino