Transmit and Receive Data Using Raspberry Pi® CAN blocks

This example shows to use Simulink® Support Package for Raspberry Pi® Hardware to to transmit and receive data from the CAN network using the specified CAN device.

Introduction

In this example, the Arduino CAN Transmit model with a CAN Transmit block is used to transmit data. The Arduino CAN Receive model with a CAN Receive block is used to receive data.

Prerequisites

Required Hardware

To run this example, you must have the following hardware:

  • Raspberry Pi Hardware

  • Connecting wires

  • OBD(On-board diagnostics) Connector

  • MCP2515 based CAN shield

Configure CAN hardware

1. Connect the CAN Shield on the Raspberry Pi board.

2. Connect the OBD Connector from the vehicle to the MCP2515 based CAN shield. For more information on MCP2515, see MCP2515.

Configure the Model for Supported Raspberry Pi Hardware

1. In your Simulink model, click Modeling tab and then select Model Settings to open Configuration Parameters dialog.

2. Select the Hardware Implementation pane and select your required Raspberry Pi hardware from the Hardware board parameter list. Do not change any other settings. The Model Settings are pre-configured in this model. For information on setting or modifying the CAN properties, see Model Configuration Simulink Support Package for Raspberry Pi Hardware.

3. Click OK.

Transmit Data From Raspberry Pi Hardware

This example uses the Raspberry Pi CAN Transmit model, with a CAN Transmit block, to transmit 1 byte of data from the Raspberry Pi hardware. To open the model, enter the following command at the MATLAB command prompt.

open_system('raspberrypi_CAN_transmit');
%

1. Set the CAN Transmit block parameters as shown in this image.

2. In your Simulink model, click the Hardware tab and then click Monitor & Tune to transmit the data.

Receive Data with Raspberry Pi Hardware

This example uses the Raspberry Pi CAN Receive model, with a CAN Receive block, to receive 1 byte of data by the Raspberry Pi hardware. To open the model, enter the following command at the MATLAB command prompt.

open_system('raspberrypi_CAN_receive');

1. Set the CAN Receive block parameters as shown in this image.

2. In your Simulink model, click the Hardware tab and then click Monitor & Tune to receive the data. The Scope block displays the data being received in the target hardware.

Other things to Try