The wiringPi library of C provides a hardware PWM method, while wiringPi library of Python doesn’t provide
hardware PWM method. There is only software PWM for Python.
The hardware PWM only needs to be configured, does not occupy CPU resources, and is more precise in time
control. The software PWM requires the CPU to work all the time, using the code to output high level and low
level. This part of the code is carried out in multi-thread, and the time precision is relatively not high enough.
In Python, you can set its frequency. The duty cycle range is 0-100. You can set duty cycle with decimals, so
although it is 0-100, you set more than 100 levels.
For more details, please refer http://wiringpi.com/reference/software-pwm-library/
Circuit
Code
This project is designed to make PWM output GPIO18 with pulse width increasing from 0% to 100%, and then
reducing from 100% to 0% gradually.
C Code 4.1.1 BreathingLED
First observe the project result, and then analyze the code.
1. Use cd command to enter 04.1.1_BreathingLED directory of C code.
cd ~/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi/Code/C_Code/04.1.1_BreathingLED
2. Use following command to compile “BreathingLED.c” and generate executable file “BreathingLED”.
gcc BreathingLED.c -o BreathingLED -lwiringPi
3. Then run the generated file “BreathingLED”
sudo ./ BreathingLED