Uncategorized

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

ចោរសមុទ្រឡានក្រុង
Button pad

Miso
Miso

Mosi
Mosi

នាលិការោតិ៍
SCK

ស៊ីអេស
ស៊ីអេស

+5volts
VCC

វីសនីដុង
វីសនីដុង

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) ហើយ idles Idles នៅពេលដែលសញ្ញាខ្ពស់ (5volts); នេះជាធម្មតាត្រូវបានគេរាប់បញ្ចូលដោយ / ស៊ីអេសអេស, #cs, ឬ! CS ។ ផ្ទុយទៅវិញឧបករណ៍បញ្ជាប៊ូតុងសកម្មនៅពេលស៊ីអេសគឺខ្ពស់។

ប្រតិបត្តិការ 64byte កំណត់ពណ៌ដែលបានដឹកនាំហើយទាញយកស្ថានភាពប៊ូតុង។ កម្មវិធី 16 ប៊ីតទី 1 កម្រិតក្រហមសម្រាប់អំពូល LED នីមួយៗបន្ទាប់មកមានពណ៌បៃតងទំហំ 16bytes និងពណ៌ខៀវ 16bytes ។ បញ្ចប់ដោយការអាន 16bytes ពីក្តារដើម្បីទទួលបានស្ថានភាពនៃប៊ូតុងនីមួយៗ។ ប៊ូតុងប៊ូតុងត្រូវបានផ្ញើជា 0x00 ប្រសិនបើចុច 0xFF ប្រសិនបើមិនបានចុច។ សំណុំបែបបទ Datasheet ផ្តល់អនុសាសន៍ឱ្យពន្យាពេល 400us ពន្យាពេលរវាងការសរសេរស៊ុមពណ៌ហើយអានទិន្នន័យប៊ូតុងប៉ុន្តែ Pirate ឡានក្រុងយឺតល្មមដែលយើងមិនបារម្ភអំពីរឿងនោះទេ។

ពិធីសារគឺសាមញ្ញគ្រប់គ្រាន់ប៉ុន្តែមានការចាប់ដ៏សំខាន់មួយ។ បន្ទាត់នាឡិកាត្រូវតែខ្ពស់មុនពេលចិញ្ចឹមស៊ីអេសអេស, ឬការបូកសរុប Bytestream នឹងត្រូវបានបិទដោយ 1 ប៊ីត។ សម្រាប់ហេតុផលនេះម៉ូឌុលផ្នែករឹងនៃផ្នែករឹងជាច្រើននឹងមិនដំណើរការជាមួយក្តារទេ។ នេះមិនមែនជាបញ្ហាទេប្រសិនបើក្រេឌីតរបស់អ្នកអនុញ្ញាតឱ្យអ្នកធ្វើឱ្យអ្នកមានម្ជុលភ្លោះដែលត្រូវបានគ្រប់គ្រងដោយម៉ូឌុលផ្នែករឹងប៉ុន្តែ “micros ដែលយើងបានធ្វើការជាមួយមិនអនុញ្ញាតនេះ។

25 25 25 25 25 25 25 ៈ 16 ម: 16 [
នាឡិកា 1 <-Flock ត្រូវតែខ្ពស់មុនពេលចិញ្ចឹមសត្វ CS CS បានបិទ -C ទៅ 5volts, ផ្ទុយពីការប្រើប្រាស់ធម្មតា ភាគច្រើនសរសេរ 0xFF, 0x10 ដង <-RED LED LED ភាគច្រើនសរសេរ 0xFF, 0x10 ដង <-green LED ភាគច្រើនសរសេរ 0xff, 0x10 ដង <-blue LED ភាគច្រើនអាន 0x10 បៃ: <ប៊ូតុងប៊ូតុង <- អាន 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff $ 0xff ស៊ីអេសអេសអេសអេសអេសអេសអេសអេសអេសអេសអេសអេសអេសអេសអេស, ទល់មុខការប្រើប្រាស់ធម្មតា raw3wire>

ពាក្យបញ្ជានេះកំណត់គ្រប់ពណ៌ទាំងអស់របស់នីមួយៗដែលនាំឱ្យពេញហើយអានបៃចេញ 16 ប៊ូតុង។

ដំបូងយើងកំណត់នាឡិកាខ្ពស់ (/) ហើយមានតែពេលនោះទេដែលយើងអាចលើក CS ទៅ 5volts (]) ហើយចាប់ផ្តើមប្រតិបត្តិការទិន្នន័យ។ 255: 16 គឺជាពាក្យបញ្ជាម្តងហើយម្តងទៀតដែលផ្ញើតម្លៃ 255 ដប់ប្រាំមួយដង។ នៅពេលឆានែលពណ៌នីមួយៗមាន 8bits នៃការគ្រប់គ្រងអាំងតង់ស៊ីតេ 255 គឺ 100% ។ យើងផ្ញើ 255 ពិន្ទុសរុប 48 ដងម្តងសម្រាប់ពណ៌នីមួយៗនៃអំពូល LED នីមួយៗ។ ចុងបញ្ចប់យើងទាញយកទិន្នន័យមួយសន្លឹកទំហំមួយសន្លឹក (R: 16) និង CS ទាបជាងនេះដើម្បីបញ្ចប់ប្រតិបត្តិការ ([) ។ តម្លៃប៊ូតុងមាន 0xff ទាំងអស់ដែលបង្ហាញថាគ្មានប៊ូតុងត្រូវបានចុចទេ។

0:16 0:16 128 ៈ 16 R: 16 [
នាឡិកា 1
CS ពិការ
Bull សរសេរ 0x00, 0x10 ដង
Bull សរសេរ 0x00, 0x10 ដង
ភាគច្រើនសរសេរ 0x80, 0x10 ដង <-all ពណ៌ខៀវទៅ 50% ភាគច្រើនអាន 0x10 បៃ: 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff $ 0xff បានបើកដំណើរការ CS raw3wire>

នៅទីនេះយើងបានកំណត់កម្រិតពណ៌ខៀវគ្រប់រូបដែលនាំឱ្យមានរហូតដល់ 50% (128) ហើយបិទពណ៌ផ្សេងទៀតទាំងអស់។ លទ្ធផលប៊ូតុងឥឡូវបង្ហាញប៊ូតុងនោះ 0 ត្រូវបានចុច។

0 0 0 0 0 25 25 25 25 25 0 0 0 0 0 0 0 0 0 0 0:16-6 R: 16 [
នាឡិកា 1
CS ពិការ
សរសេរ: 0x00 <- ក្រហម LED 0, បិទ ... <-More ដូចគ្នា សរសេរ: 0x00 <- ក្រហម LED 3, បិទ សរសេរ: 0xff <- ក្រហម LED 4, 100% លើ សរសេរ: 0xff <- ក្រហម LED 5, 100% លើ សរសេរ: 0xff <- ក្រហម LED 6, 100% លើ សរសេរ: 0xff <- ក្រហម LED 7, 100% លើ សរសេរ: 0x00 <- ក្រហម LED 8, បិទ ... <-More ដូចគ្នា សរសេរ: 0x00 <- ក្រហម LED 4, បិទ ភាគច្រើនសរសេរ 0x00, 0x10 ដង <- បៃតងពណ៌បៃតងទាំងអស់បិទ ភាគច្រើនសរសេរ 0x00, 0x10 ដង <-all blue blue បានបិទ ភាគច្រើនអាន 0x10 បៃ: <ប៊ូតុងប៊ូតុងប៊ូតុងអាន 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff $ 0xff បានបើកដំណើរការ CS raw3wire>

ឧទាហរណ៍នេះបង្ហាញពីរបៀបដោះស្រាយ LED តែមួយ។ លើកនេះយើងពិតជាសរសេរបៃពណ៌ក្រហម 16 បៃ។ ប៊ូតុង 0-3 និង 8-15 មានតម្លៃក្រហម 0 (ក្រហមបិទ) ប៊ូតុង 4-7 ត្រូវបានកំណត់ទៅក្រហម 100% (255) ។ អំពូល LED ពណ៌បៃតងនិងខៀវទាំងអស់ត្រូវបានបិទ (0 0 0%) ។

ការបហ្ចប់

វាពិតជាគួរឱ្យធុញទ្រាន់ណាស់ក្នុងការទទួលបានក្តារនេះដែលធ្វើការពីព្រោះកំណែដំបូងនៃ datasheet មានកំហុសជាច្រើន។ វិស្វករនិងការគាំទ្ររបស់ Sparkfun ពិតជាមានប្រយោជន៍ហើយបានបង្ហោះសំណុំទិន្នន័យដែលបានកែតម្រូវក្នុងរយៈពេលប៉ុន្មានថ្ងៃ។ ដរាបណាអ្នកមានទិន្នន័យសំណុំរឿងដែលបានធ្វើឱ្យទាន់សម័យនេះគឺជាក្តារងាយស្រួលក្នុងការធ្វើការជាមួយ។

យើងចង់ឃើញការធ្វើបច្ចុប្បន្នភាពកម្មវិធីបង្កប់ដែលលុបបំបាត់តម្រូវការក្នុងការរក្សាសញ្ញានាឡិកាខ្ពស់មុនពេលចិញ្ចឹមសត្វ។ quirk នេះធ្វើឱ្យក្តារមិនឆបគ្នាជាមួយនឹងម៉ូឌុល Spi ផ្នែករឹងជាច្រើនដោយបន្សល់ទុកនូវទម្លាប់ប៊ីងយឺត ៗ ដែលជាជម្រើសតែមួយគត់។ ជាសំណាងល្អកូដប្រភពបើកចំហហើយមានសម្រាប់អ្នកដែលចង់ធ្វើការផ្លាស់ប្តូរនេះ។

ឧបករណ៍បញ្ជាបន្ទះរបស់បន្ទះគឺជាក្តារដែលពិតជាស្អាតហើយយើងទន្ទឹងរងចាំប្រើប្រាស់វានៅក្នុងគម្រោងអនាគត។

ការ Hack ការពិនិត្យឡើងវិញថ្ងៃនៃការបង្ហាញ: យើងបានស្នើសុំក្រុមប្រឹក្សាភិបាលឥតគិតថ្លៃហើយ Sparkfun បានផ្ញើវាមកយើង។ យើងមានពេលវេលាដ៏គួរឱ្យភ័យខ្លាចក្នុងការធ្វើឱ្យវាធ្វើការជាមួយការណែនាំនៅក្នុងកំណែដំបូងរបស់ datasheet, យើងបានចងក្រងឯកសារថាបទពិសោធន៍នៅទីនេះ។