This example shows how to use Simulink® Support Package for Arduino Hardware to monitor vehicle engine RPM using Arduino CAN blocks.
Arduino Mega 2560
Arduino Mega ADK
Arduino MKR WIFI 1010
Arduino Nano 33 IoT
The model in this example uses CAN Transmit, CAN Receive, Scope, and Subsystem blocks. The Read Engine RPM subsystem in the model extracts and validates engine RPM details from the data received.
Before you start this example, you must:
To run this example, you must have the following hardware:
Supported Arduino board
OBD (on-board diagnostics) connector
MCP2515 based CAN shield
1. Connect the CAN shield on the Arduino board.
2. Connect the OBD connector from the vehicle to the MCP2515 based CAN shield. For more information on MCP2515, see MCP2515.
In this example, request is first sent from CAN Transmit block to the vehicle. The vehicle responds and sends the RPM details to CAN Receive block. The Model Settings are pre-configured in this model. For information on setting or modifying the CAN properties, see Model Configuration Parameters for Simulink Support Package for Arduino Hardware.
The model contains a Constant block which has a preconfigured Constant value of [2 1 12 0 0 0 0 0]. This value is required to send a request to receive engine RPM details.
Information used in the value [2 1 12 0 0 0 0 0] has a specific usage. The usage and purpose of the value [2 1 12 0 0 0 0 0] is as shown in this table.
Double-click the CAN Transmit block to open the block mask and set the CAN Transmit block parameters as shown in this image. This sends a request to the engine to send the RPM details. The request is sent to the vehicle on the CAN bus at message ID 7DFh, using 8 data bytes.
Data is input as: Data input type used for transmitting messages. You can change this value, if required.
Identifier Type: Message identifier type. Use Standard (11-bitidentifier) type.
Message ID: Value of message identifier. Specify the value as
Message Length: Message length, in bytes. Secify the value as
The vehicle responds to the request on the CAN bus at message ID 7E8h. The CAN Receive blocks recives the engine RPM details in the message as shown in this image.
hex2dec('7df') received and their usage is as shown in this table.
The Scope block displays the data being received in the target hardware. The Read Engine RPM subsystem extracts and validates engine RPM details from the data received.
In your Simulink model, click the Hardware tab and then click Build, Deploy & Start to deploy the model or click Monitor & Tune to deploy and run the model in external mode.
Working with Arduino CAN blocks in Transmit and Receive Data Using Arduino® CAN Blocks.