{"id":459,"date":"2011-11-25T19:10:02","date_gmt":"2011-11-25T17:10:02","guid":{"rendered":"http:\/\/tomashg.com\/?p=459"},"modified":"2012-02-15T15:57:57","modified_gmt":"2012-02-15T13:57:57","slug":"sp-button-pad-controller-act-i-latency-is-a-biatch","status":"publish","type":"post","link":"https:\/\/tomashg.com\/?p=459","title":{"rendered":"SP Button Pad Controller ACT I (latency is a biatch)"},"content":{"rendered":"<p><a href=\"https:\/\/tomashg.com\/wp-content\/uploads\/2011\/11\/DSC01046X.jpg\"><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-medium wp-image-484\" title=\"DSC01046X\" src=\"https:\/\/tomashg.com\/wp-content\/uploads\/2011\/11\/DSC01046X-300x225.jpg\" alt=\"\" width=\"300\" height=\"225\" srcset=\"https:\/\/tomashg.com\/wp-content\/uploads\/2011\/11\/DSC01046X-300x225.jpg 300w, https:\/\/tomashg.com\/wp-content\/uploads\/2011\/11\/DSC01046X-1024x768.jpg 1024w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Next step for my project, were the Button Pad Controllers. There are two boards, SPI slave board, and a USB master board with USB API. Should be straight forward, or so I thought..<\/p>\n<p>The USB board had two <a href=\"http:\/\/www.sparkfun.com\/products\/9240\" target=\"_blank\">JST connectors<\/a>, one for the USB cable and one for 5V Power. To make my life slightly easier, I also got a <a href=\"http:\/\/www.sparkfun.com\/products\/9109\" target=\"_blank\">USB breakout board<\/a> and finding out which was the right way to solder the cables was matter of reading through the product comments since it was not documented.<\/p>\n<blockquote><p><em>With the board oriented with the LEDs down, and the ICs facing up, turn it so that the USB JST connector is on the left side<\/em><br \/>\n<em> The pins (from top to bottom) are:<\/em><br \/>\n<em> USB Data &#8211;<\/em><br \/>\n<em> Vcc<\/em><br \/>\n<em> Gnd<\/em><br \/>\n<em> USB Data +<\/em><\/p><\/blockquote>\n<p>Now the tricky part was that each board had to be individually configured for the number of boards in the whole system, for the USB, big deal, just send $0302\\r over serial and job done. Now the SPI board is a different story. The documentation showed a waveform diagram of signals it had to\u00a0receive\u00a0to activate the command mode. After blankly staring at it for a while, I finally realized that it showed the bit sequence, 1 followed by 0x01 which is the set board command followed by 0x02 which is the command parameter ( in this case 2 boards)But the bits had to be sent in Least Significant Bit First order.<\/p>\n<p><a href=\"https:\/\/tomashg.com\/wp-content\/uploads\/2011\/11\/commandsequence.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-464\" title=\"commandsequence\" src=\"https:\/\/tomashg.com\/wp-content\/uploads\/2011\/11\/commandsequence.png\" alt=\"\" width=\"636\" height=\"135\" srcset=\"https:\/\/tomashg.com\/wp-content\/uploads\/2011\/11\/commandsequence.png 636w, https:\/\/tomashg.com\/wp-content\/uploads\/2011\/11\/commandsequence-300x63.png 300w\" sizes=\"(max-width: 636px) 100vw, 636px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>After\u00a0aimlessly\u00a0looking for more specific documentation or code examples, I started poking around with Arduino&#8217;s <a href=\"http:\/\/arduino.cc\/en\/Reference\/SPI\" target=\"_blank\">SPI library<\/a> and <a href=\"http:\/\/arduino.cc\/en\/Reference\/ShiftOut\" target=\"_blank\">shiftOut()<\/a> command and successfully came up with this:<\/p>\n<pre class=\"brush:cpp\">#define CS 10\r\n#define MISO 12\r\n#define SCK 13\r\n\r\nvoid setup()\r\n{\r\n  pinMode(CS, OUTPUT);\r\n  pinMode(MISO, OUTPUT);\r\n  pinMode(SCK, OUTPUT);\r\n  digitalWrite(CS, LOW); \r\n\r\n  delayMicroseconds(10);\r\n  shiftOut(MISO,SCK,LSBFIRST,0b01);\r\n  shiftOut(MISO,SCK,MSBFIRST,0b10000000);\r\n  shiftOut(MISO,SCK,MSBFIRST,0b01000000);\r\n}  \r\n\r\nvoid loop(){\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>Now the actual USB API is quite generic, and not very usefully in my purpose. The device just sits there doing nothing, waiting for a command. So you have to manually\u00a0call for buttons status and manually set led colors by sending different commands and it again, every time it would return the buttons status. Now this created a great deal of latency.. I made a Processing sketch to drive the whole thing, but it is slow, by slow I mean SLOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOW&#8230;<\/p>\n<p>The idea was to\u00a0analize\u00a0the\u00a0receiving button status, send back a set color command to light up the pressed button, and then transform the parameters into MIDI data and forward it to the virtual MIDI port. Here is how all this worked out:<\/p>\n<p><iframe width=\"560\" height=\"315\" src=\"http:\/\/www.youtube.com\/embed\/OeRHaXscqhA\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p>Part II:<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Next step for my project, were the Button Pad Controllers. There are two boards, SPI slave board, and a USB master board with USB API. Should be straight forward, or so I thought.. The USB board had two JST connectors, one for the USB cable and one for 5V Power. To make my life slightly [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[79,112,32],"tags":[80,102,94,93,99,100,101],"class_list":["post-459","post","type-post","status-publish","format-standard","hentry","category-arduino","category-controllers","category-technology","tag-arduino-2","tag-button-pad","tag-midi","tag-monome","tag-sparkfun","tag-spi","tag-usb"],"_links":{"self":[{"href":"https:\/\/tomashg.com\/index.php?rest_route=\/wp\/v2\/posts\/459","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tomashg.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tomashg.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tomashg.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tomashg.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=459"}],"version-history":[{"count":18,"href":"https:\/\/tomashg.com\/index.php?rest_route=\/wp\/v2\/posts\/459\/revisions"}],"predecessor-version":[{"id":530,"href":"https:\/\/tomashg.com\/index.php?rest_route=\/wp\/v2\/posts\/459\/revisions\/530"}],"wp:attachment":[{"href":"https:\/\/tomashg.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=459"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tomashg.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=459"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tomashg.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}