Pi-blaster Improves Software PWM on Raspberry Pi

Raspberry Pi
Pi-blaster Improves Software PWM on Raspberry Pi

raspberrypi-pulses-on-scopeWithout an external digital to analog converter circuit, getting pulse width modulation out of more than a single PWM pin on the Raspberry Pi could be achieved by writing your own code to set the pins high and low at the appropriate time (i.e. bitbanging). The solution isn’t perfect, however. Since you’re sharing the CPU of the Raspberry Pi with other processes that are running simultaneously, you can’t rely on getting the clock cycle you need to change the state of the pin at just the right time. This means that pulsing pins for fading LED effects, mixing colors with RGB LEDs, or controlling servos will have unexpected effects.

Thomas Sarlandie from TB Ideas needed PWM for a project but didn’t have the time to wait for the circuitry he needed. While exploring his options with software PWM, he came across ServoBlaster, which cleverly offloads the task of switching the pins to the direct memory access (DMA) controller. Since ServoBlaster was meant for controlling hobby servo motors using pulses, it didn’t give Thomas the full 0 to 100% PWM control he sought. After making some adjustments to the code, he had what he wanted: PWM control on the GPIO pins of the Raspberry Pi. His code, pi-blaster, is now available to all of us so that we can pulse the pins on our Pis all we want! [via Hack A Day]

What will the next generation of Make: look like? We’re inviting you to shape the future by investing in Make:. By becoming an investor, you help decide what’s next. The future of Make: is in your hands. Learn More.

Tagged

Matt Richardson is a San Francisco-based creative technologist and Contributing Editor at MAKE. He’s the co-author of Getting Started with Raspberry Pi and the author of Getting Started with BeagleBone.

View more articles by Matt Richardson
Discuss this article with the rest of the community on our Discord server!

ADVERTISEMENT

Escape to an island of imagination + innovation as Maker Faire Bay Area returns for its 16th iteration!

Prices Increase in....

Days
Hours
Minutes
Seconds
FEEDBACK