Digital Product Management Forrester Uncategorized PARTS: 4×4 RGB button PAD CONTROLLER SPI

PARTS: 4×4 RGB button PAD CONTROLLER SPI

We covered SparkFun’s new RGB button pad controller a few weeks ago. This is a full-color clone of the monome interface; a 4×4 grid of buttons with tri-color LEDs underneath. Each LED has 24bits of color control, for more than 16million color combinations. up to 10 panels can be chained together to create substantial button grids, like SparkFun’s Tetris table. We previously used a smaller version in our RGB combination lock.

We asked SparkFun to send us the SPI version of the button controller to test. This is a new product developed in-house at SparkFun, with open source hardware and software. read about our experience interfacing this board below.

4×4 RGB button pad controller SPI (SparkFun #WIG-09022, $39.95)

The button pad controller is a bare PCB, we also received a button pad cover (SparkFun #COM-07835, $9.95), and two of each bezel (SparkFun #COM-08747, #COM-08746, $3.95).  The SPI version we’re working with can be driven directly by a microcontroller, or by a USB ‘master’. The USB controller version has an additional microcontroller and FTDI USB->serial converter for PC connectivity.

When the button pad arrived, we right away sat down with the datasheet and tried to interface the board with our Bus Pirate universal serial interface. The protocol described in version 1 of the datasheet didn’t work, at all.

SparkFun open sourced this project, so we determined the correct interface protocol from the source code for the button pad SPI (ZIP) and the button pad USB controller (ZIP). We figured out most of the protocol from the source, but it still took help from SparkFun’s engineers to uncover some of the undocumented, finer points of interfacing the board. version 2 of the datasheet (PDF) accurately depicts the interface protocol.

Connections

Bus Pirate
Button pad

MISO
MISO

MOSI
MOSI

Klocka
SCK

Cs
Cs

+5volts
VCC

GND
GND

The button pad’s SPI signals are described as they relate to the on-board microcontroller, which is opposite the usual notation. The MOSI (master out, slave in) signal is actually the board’s data output, and MISO (master in, slave out) is the data input.

We tested the button pad with the Bus Pirate, but the same basic principals apply to any custom microcontroller code. The board runs at 5volts, so we powered it from the Bus Pirate’s on-board 5volt power supply. The SPI interface operates at 5volt logic levels, so we connected the Bus Pirate’s pull-up resistors to the 5volt power supply and enabled them on all signal lines.

We interfaced the button board using the Bus Pirate’s raw3wire library. Raw3wire is a software SPI library with bit-wise operations. The hardware SPI library only allows full byte operations which aren’t granular enough to interface the board. We put the Bus Pirate in raw3wire mode (menu option M), and chose the HiZ pin option because the pull-up resistors will hold the bus at 5volts.

RAW3WIRE>l <–configure bit order 1. MSB first 2. LSB first MODE>2 <–least significant bit first LSB SET: least SIG bit FIRST RAW3WIRE>W <–enable power supply VOLTAGE supplies ON RAW3WIRE>

The button pad communicates least significant bit first, so we also configured the library to communicate LSB first. Finally, we hit capital ‘W’ to enable the Bus Pirate’s power supplies. The button board will flash each color momentarily as part of its power-on self-test.

Single/multiple button board setup

Each board needs to be configured for single or multi-board use. Boards come pre-programmed for single-board operation, but it might be a good idea to set the configuration anyways. The board configuration is permanently stored in EEPROM, so it only has to be done once.

RAW3WIRE>[\_ <–take all signals low CS enabled <–CS enabled is 0volts CLOCK, 0 DATA OUTPUT, 0 RAW3WIRE>

A special sequence places the board in configuration mode. begin with all signal lines low (]\_).

RAW3WIRE>-^ 1 1 <–set single board operation DATA OUTPUT, 1 <–data high 0x01 CLOCK TICKS <–one clock tick WRITE: 0x01 <–config option 1, number of boards WRITE: 0x01 <–set the number of boards RAW3WIRE>w <–small ‘w’, power off VOLTAGE supplies OFF RAW3WIRE>W <–capital ‘W’, power on VOLTAGE supplies ON RAW3WIRE>

To enter configuration mode, take the data line high (-) and send one clock pulse (^), but leave chip select low. The board is now ready to accept configuration settings.

The first byte sent after entering configuration mode tells the board which setting to modify. Currently, only the number of boards can be configured (0x01). Next, send the number of connected boards, between 1 and 10. we sent 1 because we’re interfacing a single board. Reset the board and it will light a LED corresponding to the programmed number of boards.

Set colors and read button status

Now we’re ready to send color data to the board and read the button status. First, note that the CS (chip select) signal is opposite normal conventions. usually CS activates a chip when the signal is loW (0Volts) och går tomgångar när signalen är hög (5 volter); Detta brukar betecknas av / cs, #cs, eller! cs. Istället är knappkontrollen aktiv när CS är hög.

En 64Byte-transaktion ställer in LED-färgerna och hämtar knappens status. Det första 16Bytesprogrammet är den röda nivån för varje LED, följt av 16 bytes gröna och 16 bytor blå. Avsluta genom att läsa 16bytes från brädet för att få status för varje knapp. Knappar Data skickas som 0x00 om den trycks in och 0xff om inte tryckt. Databladet rekommenderar en 400US fördröjning mellan att skriva färgramarna och läsa knappdata, men busspiratet är långsamt nog att vi inte kommer att oroa oss för det.

Protokollet är enkelt nog, men det finns en stor fångst. Klocklinjen måste vara hög innan du höjer CS, eller byteStream kommer att vara avstängd med 1 bit. Av den anledningen kommer många Hardware Spi-moduler inte att fungera med styrelsen. Det här är inte ett problem om din mikrokontroller låter dig twiddle Pins som styrs av en hårdvarumodul, men de mikroder vi har arbetat med tillåter inte det här.

RAW3WIRE> /] 255: 16 255: 16 255: 16 R: 16 [
Klocka, 1 <-klocka måste vara hög före höjning av CS CS-funktionshindrade <-CS till 5Volts, motsatt normal användning Bulk Skriv 0xFF, 0x10 gånger <-Red LED Bulk skriv 0xff, 0x10 gånger <-Green LED Bulk Skriv 0xFF, 0x10 gånger <-BLUE LED Bulk Läs 0x10 byte: <-Read Button State 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF CS aktiverade <-CS till 0Volts, motsatt normal användning RAW3WIRE>

Detta kommando sätter varje färg på varje lysdiod till full och läser tillbaka 16-knappens byte.

Vi sätter först klockan högt (/), och då kan vi bara höja CS till 5Volts (]) och börja datatransaktionen. 255: 16 är ett upprepat kommando som skickar värdet 255 sexton gånger. Eftersom varje färgkanal har 8bits av intensitetskontroll är 255 100% på. Vi skickar 255 totalt 48 gånger, en gång för varje färg på varje lysdiod. Slutligen hämtar vi en 16Byte-ram av knappdata (R: 16) och lägre CS för att avsluta transaktionen ([). Knappvärdena är alla 0xFF, vilket indikerar att inga knappar trycks in.

RAW3WIRE> /] 0:16 0:16 128: 16 R: 16 [
Klocka, 1
Cs inaktiverade
Bulk skriv 0x00, 0x10 gånger
Bulk skriv 0x00, 0x10 gånger
Bulk skriv 0x80, 0x10 gånger <-all blå till 50% Bulk Läs 0x10 byte: 0x00 0xFF 0xFF 0xFF 0xFF 0XFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF CS aktiverade RAW3WIRE>

Här ställer vi in ​​den blå nivån av varje ledd till 50% (128) och stäng av alla andra färger. Knapputgången visar nu att knappen 0 trycks in.

RAW3WIRE> /] 0 0 0 0 255 255 255 255 0 0 0 0 0 0 0 0 0:16 0:16 R: 16 [
Klocka, 1
Cs inaktiverad
Skriv: 0x00 <- röd LED 0, OFF ...

Detta exempel visar hur man adresserar enstaka lysdioder. Den här gången skriver vi faktiskt alla 16 byte av den röda färgramen. Knappar 0-3 och 8-15 har ett rött värde av 0 (röd av), knapparna 4-7 är inställda på 100% röda (255). Alla gröna och blåa lysdioder är avstängda (0, 0%).

Slutsats

Det var verkligen frustrerande att få denna styrelse att arbeta eftersom den första versionen av databladet hade så många fel. Sparkfuns ingenjörer och support var verkligen hjälpsamma och skickat en korrigerad datablad inom dagar. Så länge du har den uppdaterade databladet, är det ett lättbord att arbeta med.

Vi skulle vilja se en firmwareuppdatering som eliminerar behovet av att hålla klocksignalen hög innan du höjer CS. Denna quirk gör styrelsen som är inkompatibel med många spi-moduler med hårdvara och lämnar långsamma rutiner som det enda gränssnittsalternativet. Lyckligtvis är källkoden öppen och tillgänglig för alla som vill göra denna förändring.

Knappen Pad Controller är en riktigt snygg styrelse, och vi ser fram emot att använda den i ett framtida projekt.

Hack A Day Review Upplysning: Vi bad om en gratis styrelse och SparkFun skickade det till oss. Vi hade en hemsk tid att få den att arbeta med instruktionerna i den första versionen av databladet, vi dokumenterade den erfarenheten här.

Leave a Reply

Your email address will not be published. Required fields are marked *