Main Content

Trigger Downstream Function-Call Subsystem Using Raspberry Pi External Interrupt Block with Single Tap Event on BMI160 Sensor

This example shows how to use the Simulink® Support Package for Raspberry Pi® Hardware to trigger a downstream function-call in Monitor and Tune action when single tap event occurs on the BMI160 sensor using a Raspberry Pi External Interrupt block. This example model for monitor and tune simulation showcases the capabilities of the External Interrupt block during a single tap event on the BMI160 sensor.

When you use the Monitor and Tune (External mode) action, a single tap event occuring on BMI160 sensor provides simulation to the Raspberry Pi board digital pin externally. For every rising edge of this input pulse signal, the downstream function-call subsystem is triggered.


For more information on how to run a Simulink model on Raspberry Pi hardware, see the Get Started with Simulink Support Package for Raspberry Pi Hardware example.

Required Hardware

  • Raspberry Pi board

  • BMI160 Boosterpack

  • Micro USB cable

  • Connecting wires

Configure Simulink Model for Counting Single Taps on BMI160 Sensor

For the external simulation mode, this example uses a preconfigured Simulink model from the Simulink Support Package for Raspberry Pi Hardware.

Open the i2c_tap_interrupt_detection Simulink model.

In the Interrupt Source area, Initialize Function subsystem consists of BMI160 block and Event Listener blocks.

In the Event Listener block, ensure that Event type is set to Initialize.

In the BMI160 Sensor, ensure that the Single tap option is selected in the Generate interrupts on parameter.

Configure the External Interrupt block parameters to their default values. Clear the Add simulation input port option.

Run Simulink Model in External Simulation Mode (Monitor and Tune)

1. On the Hardware tab of the Simulink model, click Hardware settings.

2. In the Configuration Parameters dialog box, select Hardware Implementation > Target hardware resources > External mode.

3. Ensure to select the Run external mode in a background thread option to execute the Simulink model in a background thread.

4. On the Hardware tab of the Simulink model, click Monitor & Tune.

During simulation, the single tap event on the sensor generates interrupt on pin 9 of the Raspberry Pi board. The tap on pin 9 simulates an interrupt on every rising edge of the tap signals.

Observe the incrementing counter values in Display block for every rising edge of the tap. You can open the scope and observe the tap generated output plotted against the rate transition block output.

You can notice a delay in the downstream function-call subsystem.

You can also view the output of the manual switch and the rate transition block output in the Simulation Data Inspector and Logic Analyzer.

Other Things to Try

Observe the scope output for Monitor and Tune action on the falling edge (set Mode to Falling in the External Interrupt block) as well as both rising and falling edge (set Mode to Either in the External Interrupt block) of the simulation signal.