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.

روابط

حافلة القراصنة
Button pad

MISO
MISO

موسي
موسي

ساعة حائط
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)، وأوضاع ذلك عندما تكون الإشارة مرتفعة (5Volts)؛ عادة ما يتم تشبه ذلك / cs، #cs، أو! cs. بدلا من ذلك، فإن وحدة تحكم الزر نشطة عندما تكون CS عالية.

تعمل معاملة 64BYTE ألوان LED وتسترجع حالة الزر. أول 16BYTES برنامج المستوى الأحمر لكل LED، تليها 16bytes من الأخضر، و 16bytes من اللون الأزرق. الانتهاء من خلال قراءة 16bytes من اللوحة للحصول على حالة كل زر. يتم إرسال بيانات الأزرار ك 0x00 إذا ضغطت، و 0xFF إذا لم يتم الضغط عليها. توصي ورقة البيانات بتأخير 400US بين كتابة إطارات الألوان وقراءة بيانات الزر، لكن قراصنة الحافلة بطيئة بما فيه الكفاية لأننا لن تقلق بشأن ذلك.

البروتوكول بسيط بما فيه الكفاية، ولكن هناك مصيد رئيسي واحد. يجب أن يكون خط الساعة مرتفعا قبل رفع CS، أو سيتم إيقاف تشغيله بواسطة 1 بت. لهذا السبب، لن تعمل العديد من وحدات SPI للأجهزة مع اللوحة. هذه ليست مشكلة في حالة تتيح لك متحكمك الميكروكسي مسامير Twiddle التي يتم التحكم فيها بواسطة وحدة نمطية للأجهزة، لكننا نجحنا مع عدم السماح بذلك.

RAW3WIRE> /] 255: 16 255: 16 255: 16 ص: 16 [
على مدار الساعة، 1 <-Clock يجب أن تكون عالية قبل رفع CS CS تعطيل <-CS إلى 5Volts، عكس الاستخدام العادي السائبة اكتب 0xFF، 0x10 مرات <- المصابيح LED السائبة اكتب 0xFF، 0x10 مرات <المصابيح -Green السائبة الكتابة 0xFF، 0x10 مرات <-Blue LEDS Bulk Read 0x10 بايت: <-Read State State 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff تمكين CS <-CS إلى 0Volts، عكس الاستخدام العادي Raw3wire>

يحدد هذا الأمر كل لون من كل لون يصل إلى كامل، ويقرأ مرة أخرى بايت حالة الزر 16.

نقوم أولا بتعيين ساعة عالية (/)، ثم فقط يمكننا رفع CS إلى 5Volts (]) وتبدأ معاملة البيانات. 255: 16 هو أمر متكرر يرسل القيمة 255 ستة عشر مرة. نظرا لأن كل قناة ملونة لديها 8bits من التحكم في الكثافة، فإن 255 هو 100٪. نرسل 255 ما مجموعه 48 مرة، مرة واحدة لكل لون من كل أدى. أخيرا، نسترجع إطار واحد 16byte لبيانات الزر (R: 16) وخفض CS لإنهاء المعاملة ([). قيم الزر كلها 0XFF، مما يشير إلى أنه لا يتم الضغط على أزرار.

Raw3wire> /] 0:16 0:16 128: 16 ص: 16 [
على مدار الساعة، 1.
cs المعوقين
السائبة كتابة 0x00، 0x10 مرات
السائبة كتابة 0x00، 0x10 مرات
السائبة كتابة 0x80، 0x10 مرات <-ll الأزرق إلى 50٪ السائبة قراءة 0x10 بايت: 0x00 0xfx 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff تمكين CS Raw3wire>

هنا، وضعنا المستوى الأزرق من كل أدى إلى 50٪ (128) وإيقاف جميع الألوان الأخرى. يظهر إخراج الزر الآن هذا الزر 0 مضغوط.

Raw3wire> /] 0 0 0 0 0 255 255 255 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0:16 0:16 ص: 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 15، إيقاف السائبة اكتب 0x00، 0x10 مرات <- جميع المصابيح الخضراء الكتابة بالجملة 0x00، 0x10 مرات <جميع المصابيح الزرقاء Bulk Read 0x10 Bytes: <-Read الحالة 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff تمكين CS Raw3wire>

يوضح هذا المثال كيفية معالجة المصابيح الفردية. هذه المرة، نكتمل بالفعل جميع البايتات 16 من إطار اللون الأحمر. أزرار 0-3 و 8-15 لها قيمة حمراء من 0 (أحمر قبالة)، يتم تعيين الأزرار 4-7 إلى أحمر 100٪ (255). جميع المصابيح الخضراء والأزرق خارج (0، 0٪).

خاتمة

كان من المحبط حقا الحصول على هذا اللوحة يعمل لأن الإصدار الأول من ورقة البيانات كان لديه الكثير من الأخطاء. كانت مهندسو ودعم Sparkfun مفيدة حقا، ونشرت ورقة بيانات تصحيح في غضون أيام. طالما أن لديك ورقة البيانات المحدثة، فهذا هو لوحة سهلة للعمل معها.

نود أن نرى تحديث البرامج الثابتة التي تزيل الحاجة إلى الحفاظ على ارتفاع إشارة الساعة قبل رفع CS. يجعل هذا Quirk المجلس غير متوافقا مع العديد من وحدات SPI للأجهزة، مما يترك إجراءات بطيئة BOWN-BOWN كخيار الواجهة الوحيد. لحسن الحظ، فإن شفرة المصدر مفتوحة ومتاحة لأي شخص يريد إجراء هذا التغيير.

وحدة تحكم Pad Bord هي لوحة أنيقة حقا، ونحن نتطلع إلى استخدامه في مشروع مستقبل.

اختراق ليوم الاستعراض الكشف: لقد طلبنا من لوحة مجانية وإرساله سبارك إلينا. كان لدينا وقت فظيع الحصول عليه للعمل مع التعليمات في الإصدار الأول من ورقة البيانات، وثقت تلك التجربة هنا.