You may have come across this 16×24 LED matrix board on eBay or at Sure Electronics. Each board has three 8×8 LED blocks and a controller to drive them. A simple three-wire serial interface toggles each LED and configures the overall brightness of the board. Up to four boards can be chained through 2×10 pin headers on the back, a connector cable was included with each board.

We used the Bus Pirate to test the board and learn its protocol before using it with the web platform (more on that later). Grab the datasheet and follow along below.

This is the first of a new weekly series that demonstrates devices with the Bus Pirate. Come back next Monday for another all new demo.


Device: Sure LED matrix board.
Bus: 3 wire, SPI-like bus (use pull-up resistors for 5volt interfacing).
Power requirements: 5 volts.
References: datasheet [PDF], demo code.
Complete Bus Pirate session log for this demonstration.

Bus Pirate Sure LED matrix
MOSI DATA
CLOCK WR
CS1 CS1
+5volts out +5volts in
GND GND
Vpullup +5volt in

We connected the Bus Pirate to the board as shown in the table above.

A 5volt supply powers the LEDs and controller, we used the Bus Pirate’s on-board supply. The controller requires 5volt signal levels, but the Bus Pirate’s output is only 3.3volts. No problem, we used the on-board pull-up resistors and high-impedance output mode to interface the controller at 5volts. Remember to connect the Vpu pin to the 5volt power supply.

Three wires control the matrix. Data is entered on the data pin, and each bit is read when the WR pin is high. The chip select (CS) signal activates the data interface on the LED controller chip.

Multiple matrix boards can be chained together, but each needs a separate CS signal. On the front of the PCB there’s a DIP switch that sets the chip select number for that board. Be sure to set it to the CS pin number you’re using, we used CS1. You could use the Bus Pirate AUX pin to toggle a second chip select on another board.

Bus Pirate setup

We used raw3wire mode to interface the board because some of the commands require single-bit operations that aren’t supported in the SPI library.  Open the mode menu (m) and choose raw3wire. Configure it for any speed, with open drain/high-impedance outputs.

In raw3wire mode turn on the power supply (W), and enable the pull-up resistors (P). Get a voltage report (v) to make sure the pull-up resistors (Vpu) are correctly powered at 5volts.

LED board configuration

We need to configure the controller before playing with the LEDs. The data sheet isn’t entirely clear about the setup sequence and proper values. We couldn’t have done it without following this sample source code.

RAW3WIRE>[-^_^^ 24 ^ ]
CS ENABLED
DATA OUTPUT, 1
0x01 CLOCK TICKS
DATA OUTPUT, 0
0x01 CLOCK TICKS
0x01 CLOCK TICKS
WRITE: 0x18
0x01 CLOCK TICKS
CS DISABLED
RAW3WIRE>

[ lowers the chip select pin and tells the controller to listen for data.

Each configuration command begins with a three bit sequence of one high bit (1) and two low bits (0). The Bus Pirate syntax for this is -^_^^. – raises the data line to 1, ^ raises and lowers the clock line to enter the high bit. _ lowers the data line, and ^^ ticks the clock twice to enter two low bits.

Decimal value 24 configures the controller clock, we enter it as a number and 8bits are sent. Commands end with one more clock pulse (^), though the data values is ignored. ] raises the chip select signal which disables the controller data interface and activates the new command.

A list of configuration commands follows, the Bus Pirate output looks similar to that above.

Command Note
[-^_^^ 44 ^ ] PMOS16=44-red. Sure electronics DE-DP016
[-^_^^ 8 ^ ] BLINK_OFF
[-^_^^ 1 ^ ] SYS_EN
[-^_^^ 3 ^ ] LED_ON
[-^_^^ 174 ^ ] Brightness PWM
[-^_^^ 160 ^ ] Set brightness to low

The only really interesting command is the one that sets the PWM brightness level. See the table on page 12 and 13 of the datasheet.

Control the LEDs

RAW3WIRE>[-^_^-^ _^:7 0b11111111:48]
CS ENABLED
DATA OUTPUT, 1
0x01 CLOCK TICKS
DATA OUTPUT, 0
0x01 CLOCK TICKS
DATA OUTPUT, 1
0x01 CLOCK TICKS
DATA OUTPUT, 0
0x07 CLOCK TICKS
WRITE: 0xFF , 0x30 TIMES
CS DISABLED
RAW3WIRE>

Write commands start with the 3 bit sequence 101, and a 7 bit address representing a cluster of LEDs to modify. Each address is mapped to a group of four LEDs in the matrix, a minimum of four LEDs are set with each write command.

We create the write command with -^_^-^_:7. This is similar to the configuration syntax. -^_^-^ sends 101, _:7 sends the LED write address 0000000. We use a repeat command (^:7) to send seven clock pulses instead of typing each one. With 96 LEDs to address, the repeat command will come in very handy.

In these examples we always start writing from the first LED, but you can use the 7 bit address to modify any LED cluster in the matrix. For example 101 0000001 (-^_^-^ _:6 -^) begins modification of the second LED cluster (LEDs 5, 6, 7, and 8).

The LEDs have a simple on-off control. Each bit following the command and address sequence controls one LED. There are 6, 8×8 matrices, or 384 LEDs. Each LED is controlled by one bit, so 48 bytes (384/8) are needed to set every LED on the board. We set all the LEDs on by writing 0b11111111 forty-eight times.

RAW3WIRE>[-^_^-^ _^:7 0x00:48]
CS ENABLED
DATA OUTPUT, 1
0x01 CLOCK TICKS
DATA OUTPUT, 0
0x01 CLOCK TICKS
DATA OUTPUT, 1
0x01 CLOCK TICKS
DATA OUTPUT, 0
0x07 CLOCK TICKS
WRITE: 0x00 , 0x30 TIMES
CS DISABLED
RAW3WIRE>

Next we turn the LEDs off by clocking in all 0 bits.

RAW3WIRE>[-^_^-^  _^:7   -^_^^^]
CS ENABLED
DATA OUTPUT, 1
0x01 CLOCK TICKS
DATA OUTPUT, 0
0x01 CLOCK TICKS
DATA OUTPUT, 1
0x01 CLOCK TICKS
DATA OUTPUT, 0
0x07 CLOCK TICKS
DATA OUTPUT, 1
0x01 CLOCK TICKS
DATA OUTPUT, 0
0x01 CLOCK TICKS
0x01 CLOCK TICKS
0x01 CLOCK TICKS
CS DISABLED
RAW3WIRE>

The LEDs are not individually addressable, but they can be toggled in chunks of four. In this command we set the first LED on (-^) and the remaining three LEDs in the group off (_^^^).

RAW3WIRE>[-^_^-^  _^:7   _^-^_^^]
CS ENABLED
DATA OUTPUT, 1
0x01 CLOCK TICKS
DATA OUTPUT, 0
0x01 CLOCK TICKS
DATA OUTPUT, 1
0x01 CLOCK TICKS
DATA OUTPUT, 0
0x07 CLOCK TICKS
DATA OUTPUT, 0
0x01 CLOCK TICKS
DATA OUTPUT, 1
0x01 CLOCK TICKS
DATA OUTPUT, 0
0x01 CLOCK TICKS
0x01 CLOCK TICKS
CS DISABLED
RAW3WIRE>

This command lights the second LED, and disables the first, third, and fourth.

RAW3WIRE>[-^_^-^  _^:7   -^^^^]
CS ENABLED
DATA OUTPUT, 1
0x01 CLOCK TICKS
DATA OUTPUT, 0
0x01 CLOCK TICKS
DATA OUTPUT, 1
0x01 CLOCK TICKS
DATA OUTPUT, 0
0x07 CLOCK TICKS
DATA OUTPUT, 1
0x01 CLOCK TICKS
0x01 CLOCK TICKS
0x01 CLOCK TICKS
0x01 CLOCK TICKS
CS DISABLED
RAW3WIRE>

Finally, a command to turn all LEDs in the first cluster of four. This could also be entered with the repeat command as [-^_^-^  _^:7   -^:4].

Notes

Like the Sure Microchip PICkit2 clone photographed by Scorpia, this Sure device was covered in flux.

If you have any demonstration requests, please leave them in the comments. If we demo your device, we’ll send you a free PCB.

Advertisements