Chapter 4 Analog & PWM
78
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
Schematic diagram
Hardware connection
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
Summary of Contents for Ultimate Starter Kit
Page 1: ...Free your innovation Freenove is an open source electronics platform www freenove com ...
Page 117: ...117 Chapter 9 Potentiometer RGBLED www freenove com support freenove com Hardware connection ...
Page 155: ...155 Chapter 14 Relay Motor www freenove com support freenove com Hardware connection OFF 3 3V ...
Page 173: ...173 Chapter 16 Stepping Motor www freenove com support freenove com Hardware connection ...
Page 239: ...239 Chapter 22 Matrix Keypad www freenove com support freenove com Circuit Schematic diagram ...
Page 240: ...Chapter 22 Matrix Keypad 240 www freenove com support freenove com Hardware connection ...