Main Content

Transmit and Receive Data Using Raspberry Pi CAN Blocks

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

Introduction

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

Prerequisites

We recommend completing the Get Started with Simulink Support Package for Raspberry Pi Hardware example.

Required 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 Simulink 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.

Open the raspberrypi_CAN_transmit Simulink model.

  1. Configure the parameters in the CAN Transmit block.

  2. On the Hardware tab of the Simulink model, in the Mode section, select Run on board 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.

Open the raspberrypi_CAN_receive Simulink model.

  1. Configure the parameters in the CAN Receive block.

  2. On the Hardware tab of the Simulink model, in the Mode section, select Run on board 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

Monitoring Engine RPM using Raspberry Pi CAN Blocks in Monitor Engine RPM Using Raspberry Pi CAN Blocks.