{"id":125,"date":"2011-04-04T11:19:23","date_gmt":"2011-04-04T09:19:23","guid":{"rendered":"http:\/\/wordpress1\/?page_id=125"},"modified":"2011-04-07T09:25:40","modified_gmt":"2011-04-07T07:25:40","slug":"arduino-usbkeyboard-for-cubase","status":"publish","type":"page","link":"https:\/\/www.xenoworld.org\/?page_id=125","title":{"rendered":"Arduino USBKeyboard for Cubase"},"content":{"rendered":"<p><strong>Description<\/strong><br \/>\nI recently ordered the book <a href=\"http:\/\/www.practicalarduino.com\/\" target=\"_blank\">Practical Arduino<\/a>. It has lots of small neat Arduino projects, and one that really caught my eye; a <a href=\"http:\/\/www.practicalarduino.com\/projects\/virtual-usb-keyboard\" target=\"_blank\">virtual USB keyboard<\/a>.<\/p>\n<p><span style=\"color: #ff0000;\">After testing the device while recording, it became clear that some reprogramming is needed. One should be able to just record, and not always send a Ctrl-Z (undo) command. To be updated. \/XeNo-07.04.11<\/span><\/p>\n<p>After spending a lot of time recording both albums and preproductions in Steinberg Cubase (from SX up to 5) I&#8217;ve grown tired of having to use the same keyboard shortcuts over and over (and over) again to record, stop, undo and relocate the locator (repeat x number of times until you have the take you want :P). I wanted a device to to that for me, preferably using a foot pedal. When you&#8217;re playing guitars and you&#8217;re really in the zone, it&#8217;s frustrating and screws up the concentration having to move your hands back and forth from the guitar to the keyboard all the time.<\/p>\n<p>I had a Behringer foot-pedal that came with a V-Amp 2. The pedal had two switches, and connected through a TRS (stereo) jack-plug. I wanted to use this pedal to start recording, stop recording and &#8216;reset&#8217; Cubase for a new take.<\/p>\n<div id=\"attachment_147\" style=\"width: 160px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/dockerdmz:8081\/wp-content\/uploads\/2011\/04\/cubase5.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-147\" class=\"size-thumbnail wp-image-147  \" title=\"cubase5\" src=\"http:\/\/dockerdmz:8081\/wp-content\/uploads\/2011\/04\/cubase5-150x150.jpg\" alt=\"\" width=\"150\" height=\"150\" \/><\/a><p id=\"caption-attachment-147\" class=\"wp-caption-text\">Cubase 5<\/p><\/div>\n<p><strong>Circuit<\/strong><br \/>\nThe circuit for the USB-part itself is very simple; in addition toan Arduino you need three resistors, two zener diodes and a USB B-socket. The latter available from an electronics shop like for instance <a href=\"http:\/\/www.elfa.se\" target=\"_blank\">ELFA<\/a>. I connected the outputs of button 1 and 2 on pins 6 and 7 on the Arduino, as well as the common ground to ground.<strong><\/strong><strong><\/strong><\/p>\n<div id=\"attachment_132\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/dockerdmz:8081\/wp-content\/uploads\/2011\/04\/virtual-usb-keyboard-schematic.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-132\" class=\"size-medium wp-image-132   \" title=\"virtual-usb-keyboard-schematic\" src=\"http:\/\/dockerdmz:8081\/wp-content\/uploads\/2011\/04\/virtual-usb-keyboard-schematic-300x174.jpg\" alt=\"\" width=\"300\" height=\"174\" srcset=\"https:\/\/www.xenoworld.org\/wp-content\/uploads\/2011\/04\/virtual-usb-keyboard-schematic-300x174.jpg 300w, https:\/\/www.xenoworld.org\/wp-content\/uploads\/2011\/04\/virtual-usb-keyboard-schematic.jpg 970w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-132\" class=\"wp-caption-text\">The USB circuit \u00a9 Practical Arduino<\/p><\/div>\n<p><strong>Build<br \/>\n<\/strong>I used a bit of experiment board to make sort of an Arduino shield to plug the Arduino into. The enclosure I had at hand was a bit small and the mounting spacers inside weren&#8217;t that great, so the shideld ended up a bit askew after mounting. No biggie. Here&#8217;s the enclosure with and without the Arduino:<\/p>\n<p><a href=\"http:\/\/dockerdmz:8081\/wp-content\/uploads\/2011\/04\/IMG_6965.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-122\" title=\"Cubase Keyboard Controller without Arduino\" src=\"http:\/\/dockerdmz:8081\/wp-content\/uploads\/2011\/04\/IMG_6965-225x300.jpg\" alt=\"\" width=\"225\" height=\"300\" srcset=\"https:\/\/www.xenoworld.org\/wp-content\/uploads\/2011\/04\/IMG_6965-225x300.jpg 225w, https:\/\/www.xenoworld.org\/wp-content\/uploads\/2011\/04\/IMG_6965-768x1024.jpg 768w, https:\/\/www.xenoworld.org\/wp-content\/uploads\/2011\/04\/IMG_6965.jpg 1200w\" sizes=\"auto, (max-width: 225px) 100vw, 225px\" \/><\/a> <a href=\"http:\/\/dockerdmz:8081\/wp-content\/uploads\/2011\/04\/IMG_6967.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-123\" title=\"Cubase Keyboard Controller with Arduino\" src=\"http:\/\/dockerdmz:8081\/wp-content\/uploads\/2011\/04\/IMG_6967-225x300.jpg\" alt=\"\" width=\"225\" height=\"300\" srcset=\"https:\/\/www.xenoworld.org\/wp-content\/uploads\/2011\/04\/IMG_6967-225x300.jpg 225w, https:\/\/www.xenoworld.org\/wp-content\/uploads\/2011\/04\/IMG_6967-768x1024.jpg 768w, https:\/\/www.xenoworld.org\/wp-content\/uploads\/2011\/04\/IMG_6967.jpg 1200w\" sizes=\"auto, (max-width: 225px) 100vw, 225px\" \/><\/a><\/p>\n<p>The TRS-connector:<br \/>\n<a href=\"http:\/\/dockerdmz:8081\/wp-content\/uploads\/2011\/04\/IMG_6962.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-120\" title=\"Cubase Keyboard Controller 4\" src=\"http:\/\/dockerdmz:8081\/wp-content\/uploads\/2011\/04\/IMG_6962-300x207.jpg\" alt=\"\" width=\"300\" height=\"207\" srcset=\"https:\/\/www.xenoworld.org\/wp-content\/uploads\/2011\/04\/IMG_6962-300x207.jpg 300w, https:\/\/www.xenoworld.org\/wp-content\/uploads\/2011\/04\/IMG_6962-1024x708.jpg 1024w, https:\/\/www.xenoworld.org\/wp-content\/uploads\/2011\/04\/IMG_6962.jpg 1381w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><strong>Code<\/strong><em><br \/>\n<\/em>The essence in the code is that when button 1 (left on the pedal) is pressed, it sends Ctrl-Z (undo) , Numpad 0 (move locator to previous location) and Numpad * (record) in quick succession. Button 2 (right on the pedal) sends Space (stop\/pause). I&#8217;ve also added some logics that Ctrl-Z will not be sent the first time since that usually means there is nothing to undo, as well as only being able to press any button once.<\/p>\n<p><em>(I&#8217;m no programmer, so forgive me if there are any obvious errors\/amateur mistakes)<\/em><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\/**\r\n* Jon Ivar Larsen\/XeNo - www.xenoworld.org - 2011\r\n*\r\n* Derived from this project\r\n* http:\/\/www.practicalarduino.com\/projects\/virtual-usb-keyboard\r\n*\/\r\n\r\n\/\/ Requires the use of the &quot;UsbKeyboard&quot; library available from\r\n\/\/ http:\/\/code.google.com\/p\/vusb-for-arduino\/\r\n#include &quot;UsbKeyboard.h&quot;\r\n\r\n\/\/ Define the inputs to use for buttons\r\n#define BUTTON_1 6\r\n#define BUTTON_2 7\r\n\r\n\/\/ Use the on-board LED as an activity display\r\nint ledPin = 13;\r\n\r\n\/\/ Variable for what button was last pressed\r\nint previous = 2; \/\/Set to 2 since Button 2 should not be allowed to be pressed first\r\n\r\n\/\/ Variable to check if the Arduino\/Keyboard was recently started\/reset\r\nbool recentlyStarted;\r\n\r\n\/**\r\n* Configure button inputs and set up the USB connection to the host\r\n*\/\r\nvoid setup()\r\n{\r\n \/\/ Set up the activity display LED\r\n pinMode (ledPin, OUTPUT);\r\n digitalWrite (ledPin, LOW);\r\n\r\n \/\/ Set the button pins to inputs\r\n pinMode (BUTTON_1, INPUT);\r\n pinMode (BUTTON_2, INPUT);\r\n\r\n \/\/ Enable the CPU's internal 20k pull-up resistors on the button\r\n \/\/ inputs so they default to a &quot;high&quot; state\r\n digitalWrite (BUTTON_1, HIGH);\r\n digitalWrite (BUTTON_2, HIGH);\r\n\r\n \/\/ Disable timer0 since it can mess with the USB timing. Note that\r\n \/\/ this means some functions such as delay() will no longer work.\r\n TIMSK0&amp;=!(1&lt;&lt;TOIE0);\r\n\r\n \/\/ Clear interrupts while performing time-critical operations\r\n cli();\r\n\r\n \/\/ Force re-enumeration so the host will detect us\r\n usbDeviceDisconnect();\r\n delayMs(250);\r\n usbDeviceConnect();\r\n\r\n \/\/ Set interrupts again\r\n sei();\r\n\r\n recentlyStarted = true;\r\n}\r\n\r\nvoid loop()\r\n{\r\n UsbKeyboard.update();\r\n\r\n if (digitalRead(BUTTON_1) == LOW) {\r\n if (previous != 1) {\r\n if (recentlyStarted == false) { \/\/ If it is the first time button 1 is pressed,\r\n                                 \/\/ it should not run Ctrl-Z or Numpad 0 (Ins)\r\n UsbKeyboard.sendKeyStroke(KEY_Z, MOD_CONTROL_LEFT); \/\/Ctrl-Z\r\n UsbKeyboard.sendKeyStroke(98); \/\/Numpad 0 (Ins)\r\n UsbKeyboard.sendKeyStroke(85); \/\/Numpad *\r\n }\r\n if (recentlyStarted == true)\u00a0 { \/\/ ...but only Numpad * (Cubase Record)\r\n UsbKeyboard.sendKeyStroke(85); \/\/Numpad *\r\n recentlyStarted = false;\r\n }\r\n\r\n blinkLED();\r\n previous = 1;\r\n }\r\n }\r\n\r\n if (digitalRead(BUTTON_2) == LOW) {\r\n if (previous != 2) {\r\n UsbKeyboard.sendKeyStroke(KEY_SPACE);\r\n\r\n blinkLED();\r\n previous = 2;\r\n }\r\n }\r\n\r\n}\r\n\r\n\/**\r\n* Define our own delay function so that we don't have to rely on\r\n* operation of timer0, the interrupt used by the internal delay()\r\n*\/\r\nvoid delayMs(unsigned int ms)\r\n{\r\n for (int i = 0; i &lt; ms; i++) {\r\n delayMicroseconds(1000);\r\n }\r\n}\r\n\r\n\/**\r\n* Routine to blink the LED\r\n*\/\r\nvoid blinkLED()\r\n{\r\n digitalWrite(ledPin, HIGH);\r\n delayMs(250);\r\n digitalWrite(ledPin, LOW);\r\n}\r\n\r\n<\/pre>\n<p style=\"text-align: center;\"><strong>The finished build<\/strong><br \/>\nSome pictures of the enclosure. The last one with an USB-cable and the footpedal connected.<br \/>\n<a href=\"http:\/\/dockerdmz:8081\/wp-content\/uploads\/2011\/04\/IMG_6953.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-118\" title=\"Cubase Keyboard Controller 1\" src=\"http:\/\/dockerdmz:8081\/wp-content\/uploads\/2011\/04\/IMG_6953-300x208.jpg\" alt=\"\" width=\"300\" height=\"208\" srcset=\"https:\/\/www.xenoworld.org\/wp-content\/uploads\/2011\/04\/IMG_6953-300x208.jpg 300w, https:\/\/www.xenoworld.org\/wp-content\/uploads\/2011\/04\/IMG_6953.jpg 706w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><a href=\"http:\/\/dockerdmz:8081\/wp-content\/uploads\/2011\/04\/IMG_6957.jpg\"> <img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-119\" title=\"Cubase Keyboard Controller 5\" src=\"http:\/\/dockerdmz:8081\/wp-content\/uploads\/2011\/04\/IMG_6957-300x207.jpg\" alt=\"\" width=\"300\" height=\"207\" srcset=\"https:\/\/www.xenoworld.org\/wp-content\/uploads\/2011\/04\/IMG_6957-300x207.jpg 300w, https:\/\/www.xenoworld.org\/wp-content\/uploads\/2011\/04\/IMG_6957.jpg 880w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\n<a href=\"http:\/\/dockerdmz:8081\/wp-content\/uploads\/2011\/04\/IMG_6970.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-124 aligncenter\" title=\"Cubase Keyboard Controller 2\" src=\"http:\/\/dockerdmz:8081\/wp-content\/uploads\/2011\/04\/IMG_6970-225x300.jpg\" alt=\"\" width=\"225\" height=\"300\" srcset=\"https:\/\/www.xenoworld.org\/wp-content\/uploads\/2011\/04\/IMG_6970-225x300.jpg 225w, https:\/\/www.xenoworld.org\/wp-content\/uploads\/2011\/04\/IMG_6970-768x1024.jpg 768w, https:\/\/www.xenoworld.org\/wp-content\/uploads\/2011\/04\/IMG_6970.jpg 1200w\" sizes=\"auto, (max-width: 225px) 100vw, 225px\" \/><\/a><\/p>\n<p><strong>Sources<\/strong><br \/>\nPractical Arduino &#8211; <a href=\"http:\/\/www.practicalarduino.com\/projects\/virtual-usb-keyboard\">http:\/\/www.practicalarduino.com\/projects\/virtual-usb-keyboard<\/a><br \/>\nvusb-for-arduino &#8211; <a href=\"http:\/\/code.google.com\/p\/vusb-for-arduino\/\" target=\"_blank\">http:\/\/code.google.com\/p\/vusb-for-arduino\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Description I recently ordered the book Practical Arduino. It has lots of small neat Arduino projects, and one that really caught my eye; a virtual USB keyboard. After testing the device while recording, it became clear that some reprogramming is &hellip;<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/www.xenoworld.org\/?page_id=125\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-125","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.xenoworld.org\/index.php?rest_route=\/wp\/v2\/pages\/125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xenoworld.org\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.xenoworld.org\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.xenoworld.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xenoworld.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=125"}],"version-history":[{"count":43,"href":"https:\/\/www.xenoworld.org\/index.php?rest_route=\/wp\/v2\/pages\/125\/revisions"}],"predecessor-version":[{"id":130,"href":"https:\/\/www.xenoworld.org\/index.php?rest_route=\/wp\/v2\/pages\/125\/revisions\/130"}],"wp:attachment":[{"href":"https:\/\/www.xenoworld.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}