Main Content

Change the LED Glow Intensity on STMicroelectronics Nucleo Boards

This example demonstrates how to use the Simulink® Coder™ Support Package to run a Simulink model on an STMicroelectronics® Nucleo board to brighten and dim an LED.

Simulink Coder Support Package for STMicroelectronics Nucleo Boards enables you to use PWM Output block to vary the duty cycle of digital output pulse. This PWM output is written to GPIO 13 which is a user LED.

In this example you will learn how to configure a simple Simulink model to change the intensity of user LED for STMicroelectronics Nucleo F401RE board. You can configure this model for other supported Nucleo boards by browsing to Configuration Parameters > Hardware Implementation > Hardware board and selecting the required board.

Available versions of this example

STM Nucleo: PWMLEDSTMNucleo.slx

Prerequisites

We recommend completing these examples:

Required Hardware

To run this example you need the following hardware:

  • Supported STMicroelectronics Nucleo boards

  • USB type A to Mini-B cable

Model

The following figure shows the example model:

Connecting Pin D3 with D13

We will write the PWM output to GPIO D3, and connect D3 to D13 (user LED) using a breadboard wire, as shown.

Configuring the Model for Code Generation and Download

In this task, you configure the model for the supported STMicroelectronics Nucleo board.

1. Open the PWM-LED model. This model has been configured for the Nucleo F401RE board.

2. Open the Modeling tab and press CTRL+E to open Configuration Parameters dialog box.

3. Go to Hardware Implementation > Hardware board.

The user LED is driven by GPIO Pin 13 on the Nucleo F401RE board. The user LED might be driven by a different Pin on different Nucleo boards.

4. Open Hardware tab and click Build, Deploy & Start to automatically download the generated bin file, PWMLEDSTMNucleo.bin, on to the connected Nucleo board.

5. Observe that the onboard LED connected at Pin 13 brightens up to the fullest and then dims up to the lowest intensity.

You can change the value of bias and sample time in "sine wave" block to observe the difference in LED intesntiy and its frequency.