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

Buspiraat
Button pad

Miso
Miso

Mosi
Mosi

Klok
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), en idilt het wanneer het signaal hoog is (5volts); Dit wordt meestal aangeduid met / CS, #cs, of! CS. In plaats daarvan is de knopcontroller actief wanneer CS hoog is.

Een 64byt-transactie stelt de LED-kleuren in en haalt de knopstatus op. Het eerste 16Bytes-programma het rode niveau voor elke LED, gevolgd door 16Bytes groen en 16Bytes van blauw. Eindig met het lezen van 16Bytes van het bord om de status van elke knop te krijgen. Knoppengegevens worden verzonden als 0x00 indien ingedrukt, en 0xFF zo niet ingedrukt. De datasheet beveelt een 400US-vertraging aan tussen het schrijven van de kleurframes en het lezen van de knopgegevens, maar de buspiraat is traag genoeg dat we daar geen zorgen over maken.

Het protocol is eenvoudig genoeg, maar er is een belangrijke vangst. De kloklijn moet hoog zijn voordat het verhoogt CS, of de bytestream zal met 1 bit worden uitgeschakeld. Om deze reden zullen veel hardware-spi-modules niet met het bord werken. Dit is geen probleem als uw Microcontroller u laat, kunt u pinnen die worden bestuurd door een hardwaremodule, maar de micro’s waarmee we hebben gewerkt, laten dit niet toe.

Raw3Wire> /] 255: 16 255: 16 255: 16 R: 16 [
Klok, 1 <-clock moet hoog zijn voorafgaand aan het verhogen van CS CS gehandicapt <-Cs tot 5volts, tegenover normaal gebruik Bulk Schrijf 0xFF, 0x10 keer <-red LED's Bulk Schrijf 0xFF, 0x10 keer <-groene LED's Bulk Schrijf 0xFF, 0x10 keer <-Blue LED's Bulk lezen 0x10 bytes: <-Read-knopstatus 0xFF 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff CS ingeschakeld <-Cs tot 0volts, tegenover het normale gebruik RAW3WIRE>

Deze opdracht stelt elke kleur van elk LED tot volledig in en leest de 16-knopsstatus bytes terug.

We stellen eerst klokhoogte (/), en kunnen we alleen CS naar 5Volts (]) verhogen en beginnen met de gegevenstransactie. 255: 16 is een herhaald commando die de waarde 255 zestien keer verzendt. Omdat elk kleurkanaal 8 bits van intensiteitscontrole heeft, is 255 100% op. We sturen 255 in totaal 48 keer, eenmaal voor elke kleur van elke LED. Ten slotte halen we een 16Byste-koetsgegevens (R: 16) op en lagere CS om de transactie ([) te beëindigen. De knopwaarden zijn allemaal 0xFF, wat aangeeft dat er geen knoppen worden ingedrukt.

Raw3Wire> /] 0:16 0:16 128: 16 R: 16 [
Klok, 1
CS uitgeschakeld
Bulk Schrijf 0x00, 0x10 keer
Bulk Schrijf 0x00, 0x10 keer
Bulk Schrijf 0x80, 0x10 keer <-All blue to 50% Bulk lezen 0x10 bytes: 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff CS ingeschakeld RAW3WIRE>

Hier stellen we het blauwe niveau van elke leiding tot 50% (128) en schakelen alle andere kleuren uit. De knopuitvoer is nu aan dat knop 0 wordt ingedrukt.

RAW3Wire> /] 0 0 0 255 255 255 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0:16 0:16 R: 16 [
Klok, 1
CS uitgeschakeld
Schrijf: 0x00 <- Rode LED 0, Uit ...

Dit voorbeeld laat zien hoe u afzonderlijke LED’s kunt aanpakken. Deze keer schrijven we daadwerkelijk alle 16 bytes van het rode kleurenframe uit. Knoppen 0-3 en 8-15 hebben een rode waarde van 0 (rood uit), knoppen 4-7 zijn ingesteld op 100% rood (255). Alle groene en blauwe LED’s zijn uit (0, 0%).

Conclusie

Het was echt frustrerend om dit bord te laten werken omdat de eerste versie van de datasheet zoveel fouten had. Sparkfun’s ingenieurs en ondersteuning waren erg behulpzaam en plaatsten binnen enkele dagen een gecorrigeerde datasheet. Zolang je de bijgewerkte datasheet hebt, is dit een eenvoudig bord om mee te werken.

We willen graag een firmware-update zien die de noodzaak elimineert om het kloksignaal hoog te houden voordat u CS verhoogt. Deze quirk maakt het bord onverenigbaar met vele hardware SPI-modules, waardoor trage bit-bang-routines is als de enige interface-optie. Gelukkig is de broncode open en beschikbaar voor iedereen die deze verandering wil maken.

De Buttel Pad-controller is een echt nette bord en we kijken er naar uit om het te gebruiken in een toekomstig project.

Hack A Day Review Openbaarmaking: we vroegen om een ​​gratis bord en Sparkfun stuurde het naar ons. We hadden een vreselijke tijd om het te laten werken met de instructies in de eerste versie van de datasheet, we hebben die ervaring hier gedocumenteerd.

Leave a Reply

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