This example shows how to use the Simulink® Support Package for Raspberry Pi™ Hardware to control the color of an 8x8 LED matrix on Raspberry Pi Sense HAT from a web page over WebSockets.
Raspberry Pi hardware
Raspberry Pi Sense HAT
Micro USB cable
Configure the Raspberry Pi network using the Hardware Setup screen.
Tip: Before you start this example, we recommend you complete the Getting Started with Simulink Support Package for Raspberry Pi Hardware and Publish Data from Raspberry Pi Sense HAT to WebSocket Server examples.
1. Plug the Sense HAT module into the GPIO pins of the Raspberry Pi hardware.
2. Connect the micro end of the USB cable to the Raspberry Pi and the regular USB end of the USB cable to the computer. Wait until the PWR LED on the hardware starts blinking.
Open the Raspberry Pi Dashboard Monitor and Tune model.
The model is divided into two areas based on the functionality of the blocks in each area.
Subscribe Data to Websocket Client: This model shows how to subscribe to the data from a web page over WebSockets. In this model, the WebSocket Subscribe block is configured to receive RGB values from the web browser. The output of the Websocket Subscribe block is connected to a subsystem. On receiving a valid input, the subsystem converts the RGB values to an 8x8 matrix and then provides the values to the Color Display block.
Server IP address: The address of your Raspberry Pi hardware. The IP address specified in this example is a private IP address so that you can access the server in a private network.
Server Port: The port number of the server application running on your Raspberry Pi hardware. The client publishes or subscribes to data from this port on the server.
2. On the Hardware tab of the Simulink model, in the Mode section, select Run on board and then click Build, Deploy & Start.
The deployed model starts receiving pixel values from the client application running on your browser.
To open the dashboard in your default web browser, enter this command at the MATLAB® Command Window:
Tip: The web browser dashboard is best viewed in a Google Chrome® or Firefox® browser.
While the model is running on the hardware, drag the thumb of the scroll bar on the page. When you drag the scroll bar, the pixel values are communicated to the server application running on the hardware, which in turn changes the color of the LED matrix on the Raspberry Pi Sense HAT.