3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

5x4 LED display matrix using a Basic Stamp 2 (bs2) and Charlieplexing

5x4 LED display matrix using a Basic Stamp 2 (bs2) and Charlieplexing
Have a Basic Stamp 2 and some extra LEDs sitting around? Why not play around with the concept of charlieplexing and create an output using just 5 pins.

For this instructable I will be using the BS2e but any member of the BS2 family should work.

 
Remove these adsRemove these ads by Signing Up
 

Step 1Charlieplexing: What, Why, and How

Let's get the why out of the way first.

Why use charlieplexing with a Basic Stamp 2?
---Proof of concept: Learn how charlieplexing works and learn something about the BS2. This may be useful to me later using faster 8-pin chips (only 5 of them will be i/o).
---Useful reason: Basically there is none. The BS2 is far too slow to display without noticeable flickering.

What is charlieplexing?
---Charlieplexing is a method of driving a large number of LEDs with a small number of microprocessor i/o pins. I learned about charlieplexing from www.instructables.com and you can too:
Charlieplexing LEDs- The theory
How to drive a lot of LEDs from a few microcontroller pins.
Also at wikipedia: Charlieplexing

How can I drive 20 leds with 5 i/o pins?
---Please read through the three links under "What is charlieplexing?". That explains it better than I ever could. Charlieplexing is different from traditional multiplexing which needs one i/o pin for each row and each column (that would be a total of 9 i/o pins for a 5/4 display).
« Previous StepDownload PDFView All StepsNext Step »
11 comments
Sep 8, 2009. 8:27 AMricecooker7654 says:
first of all, this is amazin. but i'm having trouble. when i try to light up either led 11-12 group led 5-6 light up. looking over at the schematic i see they both share the same pins and i'm stuck. same for the 13-14 and 7-8 group. any help would be greatly appreciated.
Oct 7, 2010. 4:15 PManarky2k says:
jaja, maybe this is a little late, but i hade the same problem, so i connected the cathode of led 11/anode of led 12 to R1....same with led 13 and 14, just connected it to R1
Oct 8, 2010. 3:38 PManarky2k says:
i also had to switch R1 and R2.......
Dec 29, 2009. 3:49 PMJesse.Hawkins says:
Howdy,

I used your project to further my understanding of Charlieplexing - thanks for writing it!  That being said, I already had a breadboard built with a functioning 20 LED grid when I arrived at your project.  I wanted to understand how to efficiently display information on the grid without doing it all manually by hand.  I had a bit of trouble initially because your code did not match my hardware design - my LEDs were in a completely different order.  I liked what I saw so I decided to work your code over a bit.

Changes:

[1] Added construction notes at the top of the file to aid in breadboard design (for new builders) or re-writing of the code should someone else show up (as I did) with a different layout.

[2] Rewrote the 'SELECT rowC' routine to accomidate the layout I already had working.  It also matches the added comments I added to the top of the file.

[3] Added the rest of the English alphabet.

[4] Cleaned up whitespace/formatting a little bit.

Hope that someone finds this useful.  Good luck!

-------------------------------------
' {$STAMP BS2}
' {$PBASIC 2.5}

' Circuit Construction Guide: This code assume that you are using a 4-wide x 5-tall
' grid of LEDs, configured as follows:
'
' (01) (02) (03) (04)
' (05) (06) (07) (08)
' (09) (10) (11) (12)
' (13) (14) (15) (16)
' (17) (18) (19) (20)
'
' Pins P0 though P4 are used.  The +PIN -> LED -> -PIN assignment is applied in logical order:
'
' LED -> +PIN, -PIN
'  01 -> +P0 , -P1
'  02 -> +P1 , -P0
'  03 -> +P1 , -P2
'  04 -> +P2 , -P1
'  05 -> +P2 , -P3
'  06 -> +P3 , -P2
'  07 -> +P3 , -P4
'  08 -> +P4 , -P3
'  09 -> +P0 , -P2
'  10 -> +P2 , -P0
'  11 -> +P0 , -P3
'  12 -> +P3 , -P0
'  13 -> +P0 , -P4
'  14 -> +P4 , -P0
'  15 -> +P1 , -P3
'  16 -> +P3 , -P1
'  17 -> +P1 , -P4
'  18 -> +P4 , -P1
'  19 -> +P2 , -P4
'  20 -> +P4 , -P2

repC       VAR Byte 'Counts character flashes (how long to display each character)
charC      VAR Byte 'what character is currently being displayed
rowC       VAR Byte 'Counter to track which row is being flashed
display    VAR Byte 'Binary to display on the currently scanning row
maxC       CON 10   'Maximum character flashes before moving to next character
charsInLib CON 36   'Total characters in the library

'Variables used for reading in each of a five row character
ROW1       VAR Byte
ROW2       VAR Byte
ROW3       VAR Byte
ROW4       VAR Byte
ROW5       VAR Byte

'Variables used to set pin directions
direc1     VAR Byte
direc2     VAR Byte

'Variables used to set pin outputs
outp1      VAR Byte
outp2      VAR Byte
outp3      VAR Byte
outp4      VAR Byte

charC = 0

'Main Program
DO
  GOSUB ReadChar
  GOSUB LightLED
  DIRS = 0
  charC = charC + 1 'increment up to the next character
  IF charC > charsInLib - 1 THEN
    charC = 0
  ENDIF
LOOP

'Subroutine to read in character
ReadChar:
  READ letters + (charC * 5), ROW1
  READ letters + (charC * 5) + 1, ROW2
  READ letters + (charC * 5) + 2, ROW3
  READ letters + (charC * 5) + 3, ROW4
  READ letters + (charC * 5) + 4, ROW5
  RETURN

'Subroutine to display character
LightLED:

  'In depth explanation:
  '5x4 led matrix interpreter functions by row of 4 leds
  'Each SELECT is a different column and each case (1-16) corresponds
  'to one of the 16 states possible for the column of leds.
  '
  'Binary should then be read out of memory and handed straight to the
  'interpreter for output display.
  '
  'case 0    %0000
  'case 1    %0001
  'case 2    %0010
  'case 3    %0011
  'case 4    %0100
  'case 5    %0101
  'case 6    %0110
  'case 7    %0111
  'case 8    %1000
  'case 9    %1001
  'case 10   %1010
  'case 11   %1011
  'case 12   %1100
  'case 13   %1101
  'case 14   %1110
  'case 15   %1111

  DO
    rowC = 1 'Start with row 1
    IF repC > maxC THEN 'How long to display the character before returning to main
      repC = 0
      RETURN
    ENDIF
    FOR rowC=1 TO 5 'Cycle through each of 5 rows
      SELECT rowC
        CASE 1
          outp1 = %00001
          outp2 = %00010
          outp3 = %00010
          outp4 = %00100
          direc1 = %00011
          direc2 = %00110
          display = ROW1
        CASE 2
          outp1 = %00100
          outp2 = %01000
          outp3 = %01000
          outp4 = %10000
          direc1 = %01100
          direc2 = %11000
          display = ROW2
        CASE 3
          outp1 = %00001
          outp2 = %00100
          outp3 = %00001
          outp4 = %01000
          direc1 = %00101
          direc2 = %01001
          display = ROW3
        CASE 4
          outp1 = %00001
          outp2 = %10000
          outp3 = %00010
          outp4 = %01000
          direc1 = %10001
          direc2 = %01010
          display = ROW4
        CASE 5
          outp1 = %00010
          outp2 = %10000
          outp3 = %00100
          outp4 = %10000
          direc1 = %10010
          direc2 = %10100
          display = ROW5
      ENDSELECT
      DIRS = 0
      SELECT display
        CASE 0
          PAUSE 0
        CASE 1
          OUTS = outp4
          DIRS = direc2
          PAUSE 1
        CASE 2
          OUTS = outp3
          DIRS = direc2
          PAUSE 1
        CASE 3
          OUTS = outp3
          DIRS = direc2
          PAUSE 1
          OUTS = outp4
          PAUSE 1
        CASE 4
          OUTS = outp2
          DIRS = direc1
          PAUSE 1
        CASE 5
          OUTS = outp2
          DIRS = direc1
          PAUSE 1
          DIRS = 0
          OUTS = outp4
          DIRS = direc2
          PAUSE 1
        CASE 6
          OUTS = outp2
          DIRS = direc1
          PAUSE 1
          DIRS = 0
          OUTS = outp3
          DIRS = direc2
          PAUSE 1
        CASE 7
          OUTS = outp2
          DIRS = direc1
          PAUSE 1
          DIRS = 0
          OUTS = outp3
          DIRS = direc2
          PAUSE 1
          OUTS = outp4
          PAUSE 1
        CASE 8
          OUTS = outp1
          DIRS = direc1
          PAUSE 1
        CASE 9
          OUTS = outp1
          DIRS = direc1
          PAUSE 1
          DIRS = 0
          OUTS = outp4
          DIRS = direc2
          PAUSE 1
        CASE 10
          OUTS = outp1
          DIRS = direc1
          PAUSE 1
          DIRS = 0
          OUTS = outp3
          DIRS = direc2
          PAUSE 1
        CASE 11
          OUTS = outp1
          DIRS = direc1
          PAUSE 1
          DIRS = 0
          OUTS = outp3
          DIRS = direc2
          PAUSE 1
          OUTS = outp4
          PAUSE 1
        CASE 12
          OUTS = outp1
          DIRS = direc1
          PAUSE 1
          OUTS = outp2
          PAUSE 1
        CASE 13
          OUTS = outp1
          DIRS = direc1
          PAUSE 1
          OUTS = outp2
          PAUSE 1
          DIRS = 0
          OUTS = outp4
          DIRS = direc2
          PAUSE 1
        CASE 14
          OUTS = outp1
          DIRS = direc1
          PAUSE 1
          OUTS = outp2
          PAUSE 1
          DIRS = 0
          OUTS = outp3
          DIRS = direc2
          PAUSE 1
        CASE 15
          OUTS = outp1
          DIRS = direc1
          PAUSE 1
          OUTS = outp2
          PAUSE 1
          DIRS = 0
          OUTS = outp3
          DIRS = direc2
          PAUSE 1
          OUTS = outp4
      ENDSELECT
    NEXT
    repC = repC + 1
  LOOP
RETURN

'1
letters DATA %0110,
             %0110,
             %0110,
             %0110,
             %0110,
'2
             %0110,
             %1001,
             %0010,
             %0100,
             %1111,
'3
             %0111,
             %0001,
             %0011,
             %0001,
             %0111,
'4
             %1010,
             %1010,
             %1111,
             %0010,
             %0010,
'5
             %0111,
             %0100,
             %0111,
             %0001,
             %0111,
'6
             %0111,
             %0100,
             %0111,
             %0101,
             %0111,
'7
             %1111,
             %1001,
             %0010,
             %0100,
             %0100,
'8
             %0110,
             %1001,
             %0110,
             %1001,
             %0110,
'9
             %0111,
             %0101,
             %0111,
             %0001,
             %0111,
'0
             %0110,
             %1001,
             %1001,
             %1001,
             %0110,
'A
             %0110,
             %1001,
             %1001,
             %1111,
             %1001,
'B
             %1110,
             %1001,
             %1110,
             %1001,
             %1110,
'C
             %0110,
             %1001,
             %1000,
             %1001,
             %0110,
'D
             %1110,
             %1001,
             %1001,
             %1001,
             %1110,
'E
             %1110,
             %1000,
             %1100,
             %1000,
             %1110,
'F
             %1110,
             %1000,
             %1100,
             %1000,
             %1000,
'G
             %1111,
             %1001,
             %1000,
             %1011,
             %1111,
'H
             %1001,
             %1001,
             %1111,
             %1001,
             %1001,
'I
             %1111,
             %0110,
             %0110,
             %0110,
             %1111,
'J
             %0001,
             %0001,
             %0001,
             %1001,
             %1111,
'K
             %1001,
             %1010,
             %1100,
             %1010,
             %1001,
'L
             %1000,
             %1000,
             %1000,
             %1000,
             %1111,
'M
             %1001,
             %1111,
             %1001,
             %1001,
             %1001,
'N
             %1001,
             %1101,
             %1011,
             %1001,
             %1001,
'O
             %1111,
             %1001,
             %1001,
             %1001,
             %1111,
'P
             %1111,
             %1001,
             %1111,
             %1000,
             %1000,
'Q
             %1111,
             %1001,
             %1001,
             %1011,
             %1111,
'R
             %1111,
             %1001,
             %1111,
             %1010,
             %1001,
'S
             %1111,
             %1000,
             %1111,
             %0001,
             %1111,
'T
             %1111,
             %0110,
             %0110,
             %0110,
             %0110,
'U
             %1001,
             %1001,
             %1001,
             %1001,
             %1111,
'V
             %1001,
             %1001,
             %1001,
             %1001,
             %0110,
'W
             %1001,
             %1001,
             %1001,
             %1111,
             %0110,
'X
             %1001,
             %1001,
             %0110,
             %1001,
             %1001,
'Y
             %1001,
             %1001,
             %0110,
             %0110,
             %0110,
'Z
             %1111,
             %0010,
             %0100,
             %1000,
             %1111
-------------------------------------

Jan 24, 2009. 12:19 PMakatsuki666 says:
do you have to use a breadbord?????????????????????????
Oct 10, 2009. 4:58 PMApplebohn says:

No you don't have to use a bread board its just there for convenience.

Jul 23, 2009. 2:37 PMfredrikher says:
Hi, good project. I have a same project but only with 3x3 LED. I use an Basic Stamp 2 and have trouble with programming it, can you post some program codes to me please?
Feb 5, 2009. 2:47 PMakatsuki666 says:
it sais error everythime i try to put in the code
Jan 21, 2008. 3:19 PMGorillazMiko says:
Haha, nice account name! By the way, this Instructable is awesome. I always want to do this, but it's really hard to me, but still, it's awesome, great job.
May 9, 2008. 8:00 PMEbay says:
(removed by author or community request)
May 9, 2008. 8:07 PMGorillazMiko says:
...Random, but okay.

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
41
Followers
6
Author:barney_1