Category: Raspberry Pi

Pi-Blaster: Improved Software PWM

Pi-Blaster: Improved Software PWM

What is Pulse-Width Modulation?

Pulse-width modulation (PWM), or pulse-duration modulation (PDM), is a modulation technique that controls the width of the pulse, formally the pulse duration, based on modulator signal information. (More information on Wikipedia)

PWM on the Raspberry Pi

Without an external DAC circuit, getting PWM signals out of multiple pins on the Raspberry Pi can only be achieved by software (thus, the terms software pwm / soft pwm / bitbanging), switching the pins high and low at precisely controlled time intervals.

While having its own limitations, this technique might prove itself satisfactory for projects that do not require perfect signals (i.e. servos). But even then, in a situation where time is of the essence, any piece of software of that kind becomes useless in the face of Pi’s limited CPU resources. As this solution would run simultaneously along with other processes, one cannot entirely rely on the clock cycles needed to switch the state of the pins at exactly the right time.

The Pi-Blaster Project

And this is where Thomas Sarlandie‘s excellent Pi-Blaster comes into play. Just like it’s ancestor, ServoBlaster, it cleverly offloads the task of switching the pins to the direct memory access (DMA) controller. The technique used is extremely efficient: does not use the CPU and gives very stable pulses. I would call it a hybrid PWM solution since it’s basically software that uses some other hardware to get the job done.

Installation

sudo apt-get install autoconf
./autogen.sh
./configure
make

To start pi-blaster and have it relaunched automatically on every reboot:

sudo make install

If you ever need to stop pi-blaster and prevent it from starting automatically on the next reboot:

sudo make uninstall

How to use

Pi-Blaster creates a special FIFO file in /dev/pi-blaster. Any application on your Raspberry Pi can write to it (this means that only pi-blaster needs to be root, your application can run as a normal user).

Important: when using pi-blaster, the GPIO pins you send to it are configured as output.

To set the value of a PIN, you write a command to /dev/pi-blaster in the form <GPIOPinName>=<value> where <value> must be a number between 0 and 1 (included).

For a short example, this is how we set GPIO pin 17 to a PWM of 70%:

echo "17=0.7" > /dev/pi-blaster

More information on the available options, usage examples and other articles is available on the Pi-Blaster project page on github. I’m sure the entire RPi community shares my endless gratitude towards the guys who made it all possible, Thomas Sarlandie and Richard Hirst.

Advertisements
Raspberry Pi [R2] + Extension Board V2.1 Pinout

Raspberry Pi [R2] + Extension Board V2.1 Pinout

This post came into existence because everytime I do something on my RPi (Model B) and want to check the wiring, I have to look through multiple scattered notes and diagrams, and since the BCM numbering (and all the others for that matter) is a pain in the ass, I managed to put them all together into one unified diagram to rule them all. 

Raspberry Pi Model B (R2) Pinout

The picture is pretty self-explanatory and should speak for itself, but just to clarify: this is a Raspberry Pi Model B (R2) and a Raspberry-Pi-GPIO Extension Board V2.1 expansion board that I got off eBay and couldn’t find the pinout for. The diagram describes the BCM/GPIO pin numbering and I also included the specs for Rev. 1 on the expansion board (just in case).

Thing is the Model B+ came out to replace the original Model B in July 2014 and while, compared to its predecessor, it has:

  • More GPIO: The GPIO header has grown to 40 pins, while retaining the same pinout for the first 26 pins as the Model B
  • More USB: 4 USB 2.0 ports, compared to 2 on the Model B, and better hotplug and overcurrent behaviour
  • Micro SD: The old friction-fit SD card socket has been replaced with a much nicer push-push micro SD version
  • Lower power consumption: By replacing linear regulators with switching ones, it gets a reduced power consumption by between 0.5W and 1W
  • Better audio: The audio circuit incorporates a dedicated low-noise power supply
  • Neater form factor: They have aligned the USB connectors with the board edge, moved composite video onto the 3.5mm jack, and added four squarely-placed mounting holes

I’m not likely to get one just yet, since my old one is still sufficient enough. For more information on the matter you can check out the official page on raspberrypi.org and a whole bunch of other great articles from Raspberry Pi Spy.