This example shows how to use Simulink® Support Package for Raspberry Pi™ Hardware to monitor vehicle engine RPM and read the data on a web browser.
The model in this example uses CAN Transmit, CAN Receive, Scope, and Websocket Publish blocks. The Read Engine RPM subsystem in the model extracts and validates engine RPM details from the data received.
We recommend completing the Getting Started with Simulink Support Package for Raspberry Pi Hardware example.
To run this example, you must have the following hardware:
Supported Raspberry Pi board
OBD (on-board diagnostics) connector
MCP2515 based CAN shield
1. Connect the CAN shield to 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.
In this example, request is first sent from the CAN Transmit block to the vehicle for engine RPM details. The vehicle responds and sends the RPM details to the CAN Receive block. The model settings are preconfigured in this example. For information on setting or modifying the CAN properties, see Model Configuration Simulink Support Package for Raspberry Pi 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.
The constant value vector [2 1 12 0 0 0 0 0] represents a byte. Each element in the vector is a bit that is interpreted as described in the table.
1. In your Simulink model, click the Modeling tab and then select Model Settings to open Configuration Parameters dialog box.
2. Select the Hardware Implementation pane and select your Raspberry Pi hardware from the Hardware board parameter list. Do not change any other settings. The parameter values under the Hardware board settings are automatically populated to their default values.
3. Select the Target hardware resources pane and enter the IP address for the Raspberry Pi hardware in the Device Address field.
4. Click OK.
Double-click the CAN Transmit block to open the block mask and set the CAN Transmit block parameters as shown. 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. Specify the value as
The vehicle responds to the request on the CAN bus at message ID 7E8h. The CAN Receive block receives the engine RPM details.
hex2dec('7df') message received and its usage is as shown in the table.
The Scope block displays the data 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.
The Websocket Publish block is used to publish the engine RPM details on a web page. The engine RPM details can be viewed on the web page in a computer or a mobile device. To publish the engine RPM details on a web page, set the block parameters as required. The IP address should be the same as the IP address of the Raspberry Pi hardware specified in the Configuration Parameters dialog. For more information, see the Publish data from Raspberry Pi Sense HAT to a Websocket Server in Publish data from Raspberry Pi Sense HAT to a WebSocket Server.
Working with Raspberry Pi CAN blocks in Transmit and Receive Data Using Raspberry Pi® CAN blocks.