Charlieplexing with the RaspberryPi

To combine our knowledge of hardware and software by implementing Charlieplexing on the Raspberry Pi as our project's hardware. Control six LEDs in different sequences using the Raspberry Pi (GPIO) and the internet. Using the Apache and PHP servers installed on the Raspberry Pi for software-to-hardware communication. GPIO stands for General Purpose Input/Output and is an interface found on some devices such as the Raspberry Pi. Charlieplexing is a technique proposed in early 1995 by Charlie Allen at Maxim Integrated Products for driving a multiplexed display in which a microcontroller's relatively few I/O pins are used to drive an array of LEDs, i.e. sending multiple signals or streams of information from a programming code to a low-level hardware device. The method improves on traditional multiplexing by utilizing the tri-state logic capabilities of microcontrollers.

Materials:

  • Raspberry Pi
  •  Breadboard
  • 6 LED’s
  • Cables
  • USB charger
  •  SD card

Schematics:

GPIO Pin 7, 11 and 12 are being used in this Project

This step is the Python code I created for the Charlieplexing.  It's very commented, so take a look at it and it should be easy to follow.  One thing I do want to stress about it is the way I created the list of LEDs.  In most of the code I've seen, people manually list out each LED using something like this:

LEDS=[[1,2], [2,1], [1,3], [3,1], [2,3], [3,2]]

This is very effective, but it is very static. To add a fourth lead, you must manually expand the list. This works well for a small number of leads; 10 leads equals 90 LEDs. I wanted a way to generate the list of LEDs automatically. (For more information, see my comments in the final step.)

So, I created a list of leads, based on their GPIO pin number on the Raspberry Pi, then ran the leads through two for loops to generate the list automatically:

# define an array of pins used as leads
charliePins=[7,11,12]

# Define the array of LEDs.  This is normally done
# by defining each pair separately, but I wanted the code
# to be easy to expand, so I went with this method of
# cycling through the pins and creating the pairs.  It
# has the disadvantage of not making them in order for larger
# sets of pairs, but is easier to maintain, IMO.
charlieLEDS=[]
for i in range(0,len(charliePins)-1):
for j in range(i+1,len(charliePins)):
charlieLEDS.append([charliePins[i],charliePins[j]])
charlieLEDS.append([charliePins[j],charliePins[i]])

Assembled on Bread-Board

Assembled on Bread-Board

 

#Now setup the second pin for LOW OUTPUT
    gpio.setup(led[1],gpio.OUT)
    gpio.output(led[1],gpio.LOW)

# define an array of pins used as leads
charliePins=[7,11,12]

# Define the top and bottom rows as the number of the 
# LED in the list of LEDs to be created.
top=[0,2,4]
bottom=[1,3,5]

# Define the array of LEDs.  This is normally done
# by defining each pair separately, but I wanted the code
# to be easy to expand, so I went with this method of
# cycling through the pins and creating the pairs.  It
# has the disadvantage of not making them in order for larger
# sets of pairs, but is easier to maintain, IMO.
charlieLEDS=[]
for i in range(0,len(charliePins)-1):
    for j in range(i+1,len(charliePins)):
            charlieLEDS.append([charliePins[i],charliePins[j]])
            charlieLEDS.append([charliePins[j],charliePins[i]])

# setup the GPIO pins to BOARD mode
gpio.setmode(gpio.BOARD)

#Run the code over and over and over again
while 1:
	# First light them in order
    for led in charlieLEDS:
        lightLED(led)
        sleep(.25)

	# Next flash the top and bottom rows
	for flash in range(0,6):
        for light in range(0,100):
            for led in top:
                lightLED(charlieLEDS[led])
                sleep(.001)
        for light in range(0,100):
            for led in bottom:
                lightLED(charlieLEDS[led])
                sleep(.001)
				
	# Finally, flash them randomly
    for counter in range(0,26):
        lightLED(charlieLEDS[randint(0,5)
        sleep(.1)

About The Author

Muhammad Bilal

I am highly skilled and motivated individual with a Master's degree in Computer Science. I have extensive experience in technical writing and a deep understanding of SEO practices.

Scroll to Top