Raspberry Pi's Pan Tilt HAT Control Using Arduino MKR WiFi 1010 and LIS3DH Interface
This example shows how to configure use the example Simulink model interfacing a Raspberry Pi® hardware with a Pan Tilt HAT control. The model receives information from an Arduino WiFi MKR 1010 connected to a LIS3DH accelerometer sensor. The Pan tilt HAT orientation is controlled based on the received data from the Arduino.
Prerequisites
Before you start this example, complete the Get Started with Arduino Hardware example.
For more information on how to use the Simulink Support Package for Raspberry Pi Hardware, see Get Started with Simulink Support Package for Raspberry Pi Hardware.
Required Hardware
Raspberry Pi board
Arduino WiFi MKR 1010 with LIS3DH accelerometer sensor
Optional: Camera module for the Raspberry Pi
Raspberry Pi board
Power supply with at least 1A output
Pan Tilt HAT hardware module
Hardware Connection
Mount the Pan Tilt HAT hardware module on your Raspberry Pi board.
Connect the Arduino WiFi MKR 1010 board to the computer running Simulink.
(optional) Mount the camera board to your pan and tilt hardware module.
(optional) Connect the CSI cable of the camera board to the CSI port on the Raspberry Pi. For more information, refer to Camera Module.
Configure Arduino Simulink Model
1. Open the arduino_lis3dh_raspberrypi_pantilt_control Simulink model.
This model is configured to send information to Arduino WiFi MKR 1010 by setting up its TCP/IP server functionality.
2. In the Simulink model, double-click the LIS3DH block and ensure that 4D position
is selected for Detect parameter and select appropriate axes (for example, X, Y, Z), on which the position detection should be detected. Also, specify a threshold and duration above which, the LIS3DH sensor must detect the position. This threshold and duration will depend on your specific application and the sensitivity of the sensor.
3. Configure WiFi.
i. In your Simulink model, click Hardware > Hardware Settings to open Configuration Parameters dialog. Navigate to Hardware Implementation > Target hardware resource > WiFI properties.
ii. Double-click the WiFi TCP/IP Send block to open the block parameters dialog. Select Server
for Connection mode and specify the value for Local IP port for communication.
2. On the Hardware tab of the Simulink model, in the Mode section, click Run on board and then select Run on board
from the drop-down list. In the Deploy section, click Build, Deploy & Start.
Configure Pan Tilt HAT Control Raspberry Pi Simulink Model
1. Open the raspberrypi_lis3dh_pantilthat_control Simulink model.
This model is configured to receive information from the Raspberry Pi by setting up the TCP/IP server functionality.
2. Configure TCP/IP Receive block.
- Double-click the TCP/IP Receive block to open the block parameters dialog. Select Client
for Connection mode parameter and specify the value for Remote IP address for communication. Also, specify the data type, data size and sample time.
2. On the Hardware tab of the Simulink model, in the Mode section, click Run on board and then select Run on board
from the drop-down list. In the Deploy section, click Build, Deploy & Start.
Pan Tilt HAT Orientation Control
Once the Simulink models are deployed, the Raspberry Pi, with the Simulink model, tries to connect to the Arduino WiFi MKR 1010 board. Once the connection is established, the Arduino starts sending data from the LIS3DH accelerometer sensor to the Raspberry Pi.
The Raspberry Pi receives the data using the TCP/IP Receive block and processes it through the MATLAB Function block. The MATLAB Function block then controls the PAN TilT HAT based on the determined position status.
If you connect a camera module, the video stream is displayed using the V4L2 Video Capture and SDL Video Display blocks.