LabVIEW | LED Brightness Control | UART | PWM
This project demonstrates how to control the brightness of an LED connected to the NUCLEO STM32F446RE development board using LabVIEW and USART communication.
This project allows the user to configure the USART settings and send brightness levels to the STM32F446RE microcontroller using a LabVIEW .vi
file. The microcontroller receives the data via USART and adjusts the brightness of the LED connected to pin PA0
using PWM.
- LabVIEW Integration: Includes a LabVIEW
.vi
file located in theLabVIEW_files
folder for easy configuration and control. - USART Communication: Implements UART communication to receive brightness levels.
- PWM Control: Adjusts the LED brightness dynamically using a hardware timer (TIM2) and PWM.
- STM32F446RE: Compatible with the NUCLEO STM32F446RE development board.
-
LabVIEW Configuration:
- The user configures the USART settings and sends the brightness level (0–100%) to the STM32 board using the
.vi
file.
- The user configures the USART settings and sends the brightness level (0–100%) to the STM32 board using the
-
STM32 Board:
- The board receives the data via USART2 and processes it.
- The received brightness value is mapped to the PWM duty cycle for controlling the LED brightness.
-
PWM Output:
- The TIM2 timer generates PWM signals, and the LED brightness is updated based on the received duty cycle.
- LabVIEW_files: Contains the LabVIEW
.vi
file for user interaction. - src: Contains the main application code, including:
main_app.c
main_app.h
- Other related files.
- NUCLEO STM32F446RE development board
- LED connected to pin
PA0
- USB connection for USART communication
- LabVIEW software installed on the user's PC
- Toolchains:
- STM32CubeIDE or Keil uVision for code compilation and debugging
- LabVIEW:
- For running the provided
.vi
file
- For running the provided
- USART Drivers:
- Ensure proper USB-to-serial drivers are installed for PC communication.
-
Hardware Setup:
- Connect an LED to pin
PA0
of the STM32 board. - Power the STM32 board using a USB cable.
- Connect an LED to pin
-
Software Setup:
- Open the LabVIEW
.vi
file from theLabVIEW_files
folder. - Configure the USART settings to match the STM32 configuration (Baud rate: 115200, 8N1 format).
- Open the LabVIEW
-
Run the Application:
- Flash the compiled code to the STM32 board.
- Use LabVIEW to send brightness values to the board.
- Observe the LED brightness changing based on the input.
- Baud Rate: 115200
- Word Length: 8 Bits
- Stop Bits: 1
- Parity: None
- Flow Control: None
- Open the
.vi
file in LabVIEW. - Set the desired brightness level (0-100%) using the provided slider or numeric input.
- Click "SET" to transmit the brightness value to the STM32 board.
-
PWM Initialization:
- TIM2 is configured to generate PWM signals with a frequency based on the system clock.
- The duty cycle is dynamically updated using
HAL_TIM_PWM_Start_IT
.
-
USART Handling:
- Uses
HAL_UART_Receive_IT
to receive brightness values in interrupt mode. - The callback function
HAL_UART_RxCpltCallback
processes the received data.
- Uses
Contributions to enhance the project are welcome. Please follow the standard GitHub workflow:
- Fork the repository.
- Create a feature branch.
- Commit your changes.
- Submit a pull request.
This project is licensed under the MIT License.
For further assistance or inquiries, please contact: [your email here].