Main Content

Raspberry Pi Resource Monitor App

Monitor and manage Raspberry Pi resources such as MATLAB/Simulink deployed processes, CPU, RAM, SD card, external peripheral devices, and interfaces

Description

Use the Raspberry Pi Resource Monitor app to:

  • Calculate average Raspberry Pi CPU utilization percentage across all cores

  • View RAM utilization percentage

  • View total SD card memory utilization percentage

  • Run and stop MATLAB/Simulink deployed processes

  • View Raspberry Pi CPU and RAM utilization percentage for MATLAB/Simulink deployed processes

  • View log file for MATLAB/Simulink deployed processes

  • Open Raspberry Pi terminal

  • Configure two or more Raspberry Pi target boards

  • Use the available audio and video devices for MATLAB/Simulink deployed process

  • Set a MATLAB/Simulink deployed process to run-on-boot

  • View status of various interfaces such as SPI, I2C, Camera, and Serial Console

Raspberry Pi Resource Monitor App icon

Open the Raspberry Pi Resource Monitor App App

  • MATLAB Toolstrip: On the Apps tab, under Test and Measurement, click the app icon.

  • MATLAB command prompt: Enter raspberryPiResourceMonitor.

Examples

expand all

This example shows how to use the Raspberry Pi Resource Monitor app to configure the Raspberry Pi target board on the host computer. Ensure that the target board and the host computer are connected to the same network for a successful communication.

Open the Raspberry Pi Resource Monitor app.

On the Device tab, select Configure a New Connection.

Enter the Raspberry Pi IP address, Username, and Password.

Click Confirm Parameters. You can view the configured target board in the Device List pane of the app.

Configure Raspberry Pi target board

Follow the same procedure to configure another Raspberry Pi target board to the host computer. Each configured Raspberry Pi board creates a new tab in the app.

Configure two or more Raspberry Pi target boards

This example shows how to use the Raspberry Pi Resource Monitor app for the Image Inversion (Simulink Support Package for Raspberry Pi Hardware) example in the Simulink® Support Package for Raspberry Pi™ Hardware. It utilizes an externally interfaced USB camera and the raspberrypi_inversion Simulink model. Follow these steps and monitor the Raspberry Pi resources on the app:

Complete the Image Inversion (Simulink Support Package for Raspberry Pi Hardware) example and deploy the model as a standalone application on the Raspberry Pi target board.

Ensure to select the Hardware board as Raspberry Pi and configure the Raspberry Pi target board parameters in the Configuration Parameters dialog box.

Open the Raspberry Pi Resource Monitor app.

Configure the same Raspberry Pi target board on the app.

Observe the following in the raspberrypi_inversion Simulink model:

  • Model entry appears in the MATLAB/Simulink Deployed Processes table

  • Status of the model is Running

  • CPU(%) and RAM(MB) columns in the MATLAB/Simulink Deployed Processes table display the total Raspberry Pi core and RAM percentage occupancy, respectively

  • Process ID is assigned to the Simulink model

  • Process path is populated

  • Status of the camera in the Peripherals pane is In-use

  • Status of the camera in the Interfaces section is Enabled

App screen-shot for raspberrypi_inversion model

Select the model row in the MATLAB/Simulink Deployed Processes table. The section below the table is populated with the model details such as Process location, File size, Modified date, and MATLAB version.

To copy the process path, click the copy icon next to Process location.

To stop running the Simulink model, select the row for the model in the MATLAB/ Simulink Deployed Processes table. In the Resource Monitor tab, click Stop process. Observe that:

  • Status of the model is changed from Running to Stopped

  • No Process ID is assigned to the Simulink model

  • Simulink model does not occupy the Raspberry Pi CPU and RAM

  • Status of the camera is now changed from In-use to Available

To run the Simulink model every time the target board reboots, select the row for the model in the MATLAB/Simulink Deployed Processes table. In the Resource Monitor tab, click Set Run-On-Boot.

You can also perform Monitor & Tune to run the model on the Raspberry Pi hardware. While the model is running, you can change the value of the Constant block in the model from 255 to 120 and observe the processed image output.

This example shows how to use the Raspberry Pi Resource Monitor app to deploy a simple MATLAB function, raspberrypi_camera, on the Raspberry Pi target board. This function uses an object, webcam, that represents a connection from the MATLAB software to a web camera interfaced with the Raspberry Pi target board. Follow these steps and monitor the Raspberry Pi resources on the app:

Open a new script file and type the code.

function raspberrypi_camera()

r = raspi();

w = webcam(r);
pause(0.1);

while 1  
   sp = snapshot(w);
   displayImage(r,sp);
   pause(0.1);       
end

end

Save the file as raspberrypi_camera.m.

Ensure to select the Hardware board as Raspberry Pi and configure the Raspberry Pi target board parameters in the Configuration Parameters dialog box.

Open the Raspberry Pi Resource Monitor app.

Configure the Raspberry Pi target board on the app.

In the MATLAB command prompt, run these commands to generate a configuration object and deploy the function as a standalone executable on the Raspberry Pi target board.

t = targetHardware('Raspberry Pi')
deploy(t,'raspberrypi_camera.m')

Observe the following for the raspberrypi_camera.mMATLAB function:

  • Function entry appears in the MATLAB/Simulink Deployed Processes table

  • Status of the function is Running

  • CPU(%) and RAM(MB) columns in the MATLAB/Simulink Deployed Processes table display the total Raspberry Pi core and RAM percentage occupancy, respectively

  • Process ID is assigned to the MATLAB function

  • Process path is populated

  • Status of the camera in the Peripherals pane is In-use

  • Status of the camera in the Interfaces section is Enabled

Select the model row in the MATLAB/Simulink Deployed Processes table. The section below the table is populated with model details such as Process location, File size, Created on, and MATLAB version.

To copy the process path, click the copy icon next to Process location.

To stop running the MATLAB function, select the row for the model in the MATLAB/ Simulink Deployed Processes table. In the Resource Monitor tab, click Stop process. Observe that:

  • Status of the function is changed from Running to Stopped

  • No Process ID is assigned to the MATLAB function

  • The MATLAB function does not occupy the Raspberry Pi CPU and RAM

  • Status of the camera is now changed from In-use to Available

This example shows how to use the Raspberry Pi Resource Monitor app for the Shift the Audio Signal Pitch Using MATLAB Function Block in Simulink (Simulink Support Package for Raspberry Pi Hardware) example. It uses an externally interfaced USB microphone or a webcam microphone, and a pair of headphones. This example utilizes the raspberrypi_pitchshift Simulink model. Follow these steps and monitor the Raspberry Pi resources on the app:

Complete the Shift the Audio Signal Pitch Using MATLAB Function Block in Simulink (Simulink Support Package for Raspberry Pi Hardware) example and deploy the model as a standalone application on the Raspberry Pi target board.

Ensure to select the Hardware board as Raspberry Pi and configure the Raspberry Pi target board parameters in the Configuration Parameters dialog box.

Open the Raspberry Pi Resource Monitor app.

Configure the same Raspberry Pi target board on the app.

Observe the following for the raspberrypi_pitchshift Simulink model:

  • Model entry appears in the MATLAB/Simulink Deployed Processes table

  • Status of the model is Running

  • CPU(%) and RAM(MB) columns in the MATLAB/Simulink Deployed Processes table display the total Raspberry Pi core and RAM percentage occupancy, respectively

  • Process ID is assigned to the Simulink model

  • Process path is populated

  • Audio capture and Audio playback status in the Peripherals pane is In-use

Select the model row in the MATLAB/Simulink Deployed Processes table. The section below the table is populated with the model details such as Process location, File size, Created on, and MATLAB version.

To copy the process path, click the copy icon next to Process location.

To stop running the Simulink model, select the row for the model in the MATLAB/ Simulink Deployed Processes table. In the Resource Monitor tab, click Stop process. Observe that:

  • Status of the model is changed from Running to Stopped

  • No Process ID is assigned to the Simulink model

  • Simulink model does not occupy the Raspberry Pi CPU and RAM

  • Status of the Audio capture and Audio playback is now changed from In-use to Available

To run the Simulink model every time the target board reboots, select the row for the model in the MATLAB/Simulink Deployed Processes table. In the Resource Monitor tab, click Set Run-On-Boot.

App screen-shot for raspberrypi_pitchshift model

This example shows how to use the Raspberry Pi Resource Monitor app to view the core load of the target board for the Implement Multicore Programming with CPU Core Affinity for Raspberry Pi (Simulink Support Package for Raspberry Pi Hardware) example. Follow these steps:

Select Simulink Start Page > Simulink Support Package for Raspberry Pi Hardware > Raspberry Pi Multicore.

In the Create Project dialog box, enter the project name and select the folder location to save the project.

Click OK. The following warning message is displayed: The project folder does not exist. Do you want to create it?.

From the models folder, open the raspberrypi_multicore_simple model.

On the Hardware tab, click Build, Deploy & Start.

Open the Raspberry Pi Resource Monitor app.

Configure the same Raspberry Pi target board on the app.

Observe the following for the raspberrypi_multicore_simple Simulink model:

  • Model entry appears in the MATLAB/Simulink Deployed Processes table

  • Status of the model is Running

  • CPU(%) and RAM(MB) columns in the MATLAB/Simulink Deployed Processes table display the total Raspberry Pi core and RAM percentage occupancy, respectively

  • Process ID is assigned to the Simulink model

  • Process path is populated

On the Resource Monitor tab, click Open Terminal.

Establish an SSH connection to the Raspberry Pi target board.

Execute this command at the Raspberry Pi Shell to view the task mapping for the core specific to the process ID:

htop -p <PID>
Terminal for single core

Observe that the tasks are mapped only to Raspberry Pi core 0.

From the models folder, open the raspberrypi_multicore_simple_tasks_mapped model.

On the Hardware tab, click Build, Deploy & Start.

Open the Raspberry Pi Resource Monitor app.

Execute this command at the Raspberry Pi Shell to view the task mapping for the core specific to the process ID:

htop -p <PID>
Terminal for multi core

Observe that the tasks are mapped to Raspberry Pi core 0, 1, and 2.

This example shows how to use the Raspberry Pi Resource Monitor app to debug the error encountered while deploying the Simulink models preconfigured for the same external peripheral device. For example, consider you were to deploy the Image Inversion (Simulink Support Package for Raspberry Pi Hardware) and the Implement Connected I/O to Communicate with External Peripheral Devices Using Raspberry Pi (Simulink Support Package for Raspberry Pi Hardware) examples on the Raspberry Pi hardware board. The former example uses the raspberrypi_inversion Simulink model while, the later uses raspberrypi_image_processing Simulink model. Both examples utilize the V4L2 Video Capture block configured for an external USB camera Device name, /dev/video0.

When you run the raspberrypi_inversion Simulink model from the app, the Camera section in the Peripherals pane of the app is In-use with a process ID assigned to it. The status of the model is Running.

However, when you try to run the raspberrypi_image_processing model, an error message is displayed indicating that the process did not start. To view the detailed explanation of the error, on the Resource Monitor tab, click View process logfile. Notice that the Process ID in the Peripherals section indicates that the camera is already in use by the raspberrypi_inversion Simulink model.

You can either configure different cameras to both the Simulink models and deploy them on the Raspberry Pi target board or ensure that only one Simulink model utilizes the camera at a time.

Tips

Use the Raspberry Pi Resource Monitor app to configure the Device name in the block mask while using the external peripheral devices. Connect an external peripheral device like a camera to the Raspberry Pi target board. The Device ID is populated in the Peripherals section of the app. Use this identifier to configure the V4L2 Video Capture block. You can follow the same approach to configure audio devices as well.

Introduced in R2020b