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.
We recommend completing the Getting Started with Simulink Support Package for Raspberry Pi Hardware example.
Raspberry Pi Hardware
OBD(On-board diagnostics) Connector
MCP2515 based CAN shield
Configure CAN Hardware
Connect the CAN Shield on the Raspberry Pi board.
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
In your Simulink model, click Modeling tab and then select Model Settings to open Configuration Parameters dialog.
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.
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 Window.
Configure the parameters in the CAN Transmit block.
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. To open the model, enter the following command at the MATLAB command prompt.
Configure the parameters in the CAN Receive block.
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.