“Glowing” LEDs on the Raspberry Pi GPIO pins.

The Raspberry Pi cannot do multiple levels of output on its GPIO pins. It is often cited as one of the advantages of Arduino over the RPi (and it is). However, for simple applications, different output levels can be simulated. This is easily demonstrated by making an LED glow on and off:

This effect is achieved by switching the GPIO pin on and off. Not much is needed for that: the code running in the video is only using the standard /sys/class/gpio interface. I used Perl, as I’m comfortable with it. The code can be found on github. It could be done in bash without any extra drivers needed.

The LED I use is a ledborg, a simple and cheap addon that allows for easy and risk free experimentation with GPIO output, but the technique works on any LED wired to the RPi GPIO pins.

Update: as pointed out it is basically pulse-width modulation, although the code doesn’t store the state of the pulse during a phase.

About these ads

4 thoughts on ““Glowing” LEDs on the Raspberry Pi GPIO pins.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s