led_pwm_control
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
led_pwm_control [2017/01/23 17:40] – walkeradmin | led_pwm_control [2017/01/23 18:59] – [LED States] walkeradmin | ||
---|---|---|---|
Line 8: | Line 8: | ||
\\ | \\ | ||
This is great until you want to control the brightness of the LED. You can control the LED Brightness using timers in Python (the slower/ | This is great until you want to control the brightness of the LED. You can control the LED Brightness using timers in Python (the slower/ | ||
+ | \\ | ||
\\ | \\ | ||
As you slow the frequency, the LED flickers. | As you slow the frequency, the LED flickers. | ||
As you speed up the LED, it does eventually start to dim, but uses all the Pi cpu resources (well on zero it does). | As you speed up the LED, it does eventually start to dim, but uses all the Pi cpu resources (well on zero it does). | ||
+ | \\ | ||
\\ | \\ | ||
So the most elegant solution is to use the PWM function. Its very simple to use, however there are only a couple of pins on the GPIO that support it. This is hardware based PWM, so it doesn' | So the most elegant solution is to use the PWM function. Its very simple to use, however there are only a couple of pins on the GPIO that support it. This is hardware based PWM, so it doesn' | ||
Line 16: | Line 18: | ||
\\ | \\ | ||
+ | ---- | ||
+ | |||
+ | ==== Using PWM from the Command Line ==== | ||
+ | \\ | ||
+ | I have not used this in Python yet, so for now I am doing it from the command line, using the [[gpio_control_from_command_line|WiringPi]] libraries. Check out the [[gpio_control_from_command_line|WiringPi]] page if you need to set this up (takes about 20 seconds). | ||
+ | \\ | ||
+ | \\ | ||
+ | I found this information regarding the Raspberry Pi GPIO for the Pi2. I have not found the same information for the Pi 3 yet. | ||
+ | \\ | ||
+ | \\ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | There are two hardware PWM channels on the BCM2385/6. | ||
+ | \\ | ||
+ | \\ | ||
+ | PWM0, which can be set to use GPIOs 12, 18, 40, and 52. Only 12 (pin 32) and 18 (pin 12) are available on the B+/2B, and PWM1 which can be set to use GPIOs 13, 19, 41, 45 and 53. Only 13 is available on the B+/2B, on pin 35 (but I think PWM1 is used for something - is it the audio output?) | ||
+ | |||
+ | ---- | ||
+ | |||
+ | \\ | ||
+ | For this example I am going to use GPIO12 (or Physical Pin32). | ||
+ | \\ | ||
+ | \\ | ||
+ | The steps to use the GPIO in PWM mode are very simple: | ||
+ | \\ | ||
+ | \\ | ||
+ | * Setup the Pin as an Output | ||
+ | * Setup the Pin in PWM Mode | ||
+ | * Start the PWM | ||
+ | |||
+ | ---- | ||
+ | ==== Setup the GPIO Pin as an Output ==== | ||
+ | \\ | ||
+ | For this we need to just type in the following line: | ||
+ | \\ | ||
+ | gpio -g mode 12 out | ||
+ | \\ | ||
+ | This sets the mode to Output | ||
+ | \\ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ==== Set the GPIO Pin Mode to PWM === | ||
+ | \\ | ||
+ | gpio -g mode 12 pwm | ||
+ | \\ | ||
+ | This sets the GPIO Pin mode to PWM. | ||
+ | \\ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ==== Set the PWM Frequency ==== | ||
+ | \\ | ||
+ | The PWM frequency is a 10 Bit number, so has a range of 0-1023 | ||
+ | \\ | ||
+ | gpio -g pwm 12 50 | ||
+ | \\ | ||
+ | The Higher the number, the brighter the LED. Simple. | ||
+ | \\ | ||
+ | \\ | ||
+ | |||
+ | ---- | ||
+ | ==== LED States ==== | ||
+ | \\ | ||
+ | {{: | ||
+ | \\ | ||
+ | \\ | ||
+ | ----------PWM-001----------PWM-010----------PWM-050----------PWM-0100----------PWM-250----------PWM-500----------PWM-999---------- |
led_pwm_control.txt · Last modified: 2023/03/09 22:35 by 127.0.0.1