{"id":972,"date":"2019-05-21T22:38:57","date_gmt":"2019-05-22T02:38:57","guid":{"rendered":"https:\/\/www.spikenzielabs.com\/blog\/?p=972"},"modified":"2019-05-21T22:43:50","modified_gmt":"2019-05-22T02:43:50","slug":"use-the-button-64-shield-to-make-a-usb-keyboard","status":"publish","type":"post","link":"https:\/\/www.spikenzielabs.com\/blog\/use-the-button-64-shield-to-make-a-usb-keyboard\/","title":{"rendered":"Use the Button 64 Shield to make a USB Keyboard ?"},"content":{"rendered":"\n<p>The <a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/www.spikenzielabs.com\/Catalog\/arduino\/shields\/64-button\/64-button-shield\" target=\"_blank\">Button 64 Shield<\/a> is an Arduino shield to which you can connect up to 64 buttons. We had a customer inquiry as to whether or not the Button 64 Shield could be used with an Arduino Leonardo so that it could operate as a standard <a rel=\"noreferrer noopener\" aria-label=\"USB HID (opens in a new tab)\" href=\"https:\/\/en.wikipedia.org\/wiki\/USB_human_interface_device_class\" target=\"_blank\">USB HID<\/a> to work like a keyboard or game-controller.<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" src=\"https:\/\/www.spikenzielabs.com\/blog\/wp-content\/uploads\/2019\/05\/SPL016002_LRG.jpg\" alt=\"SpikenzieLabs Button 64 Arduino Shield\" class=\"wp-image-978\" width=\"519\" height=\"519\" srcset=\"https:\/\/www.spikenzielabs.com\/blog\/wp-content\/uploads\/2019\/05\/SPL016002_LRG.jpg 500w, https:\/\/www.spikenzielabs.com\/blog\/wp-content\/uploads\/2019\/05\/SPL016002_LRG-150x150.jpg 150w, https:\/\/www.spikenzielabs.com\/blog\/wp-content\/uploads\/2019\/05\/SPL016002_LRG-300x300.jpg 300w\" sizes=\"(max-width: 519px) 100vw, 519px\" \/><\/figure>\n\n\n\n<p>Great question!<\/p>\n\n\n\n<p>Turns out it is super simple. But it would require a few changes to the demo sketch to work with the Leonardo. We started with an Arduino sketch  that uses the Button 64 Shield with a serial connection to the host Arduino and modified the code a bit. <\/p>\n\n\n\n<p>The <a rel=\"noreferrer noopener\" aria-label=\"Arduino Leonardo (opens in a new tab)\" href=\"https:\/\/www.spikenzielabs.com\/Catalog\/arduino\/boards\/arduino-leonardo-with-headers\" target=\"_blank\">Arduino Leonardo<\/a> is a bit different than other basic Arduinos. For example the Uno uses an extra IC the ATmega16U2 (and Duemilanova an FTDI chip) to connect to USB. The Leonardo, on the other hand, only has one IC chip (ATmega32u4) that does both the connection to the host computer over USB and running your sketch. The benefits of this is that the Leonardo can appear like a keyboard or mouse to your computer.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" width=\"520\" height=\"330\" src=\"https:\/\/www.spikenzielabs.com\/blog\/wp-content\/uploads\/2019\/05\/A000057_featured_2.jpg\" alt=\"Arduino Leonardo\" class=\"wp-image-975\" srcset=\"https:\/\/www.spikenzielabs.com\/blog\/wp-content\/uploads\/2019\/05\/A000057_featured_2.jpg 520w, https:\/\/www.spikenzielabs.com\/blog\/wp-content\/uploads\/2019\/05\/A000057_featured_2-300x190.jpg 300w\" sizes=\"(max-width: 520px) 100vw, 520px\" \/><\/figure><\/div>\n\n\n\n<p>Modifying the basic serial Button 64 Shield demo sketch only required two types of changes.<\/p>\n\n\n\n<p>A. Adding the Arduino keyboard library.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" width=\"166\" height=\"32\" src=\"https:\/\/www.spikenzielabs.com\/blog\/wp-content\/uploads\/2019\/05\/kb_lib.png\" alt=\"\" class=\"wp-image-979\"\/><\/figure><\/div>\n\n\n\n<p>B. Changing the serial commands from Serial.read(); to Serial1.read();<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img loading=\"lazy\" src=\"https:\/\/www.spikenzielabs.com\/blog\/wp-content\/uploads\/2019\/05\/serial0to1.png\" alt=\"\" class=\"wp-image-981\" width=\"245\" height=\"76\"\/><figcaption>Top: from sketch for Uno. Bottom:  shows modification for Leonardo.<br><\/figcaption><\/figure><\/div>\n\n\n\n<p>Unlike other basic Arduinos where serial pins are shared with the chip doing the USB communications, on the Leonardo the Serial command is for the USB port (think serial monitor) and Serial1 command is used for pins RX-0 and TX-1. Note: all instances of Serial. have to be changed to Serial1. to allow the Button 64 to work with the Leonardo. You can also simply download our <a href=\"https:\/\/www.spikenzielabs.com\/learn\/extras\/b64shield\/B64_Serial_Leo.zip\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"demo sketch with the required changes (opens in a new tab)\">demo sketch with the required changes<\/a>.<\/p>\n\n\n\n<p>More information about the Button 64 Shield can be found on our <a href=\"https:\/\/www.spikenzielabs.com\/learn\/button64.html\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"Learn Pages for the Button 64 Shield (opens in a new tab)\">Learn Pages for the Button 64 Shield<\/a>. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Button 64 Shield is an Arduino shield to which you can connect up to 64 buttons. We had a customer inquiry as to whether or not the Button 64 Shield could be used with an Arduino Leonardo so that it could operate as a standard USB HID to work like a keyboard or game-controller. Great question! Turns\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.spikenzielabs.com\/blog\/use-the-button-64-shield-to-make-a-usb-keyboard\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":976,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,9,6],"tags":[7,108,85,112,109,110,111],"_links":{"self":[{"href":"https:\/\/www.spikenzielabs.com\/blog\/wp-json\/wp\/v2\/posts\/972"}],"collection":[{"href":"https:\/\/www.spikenzielabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.spikenzielabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.spikenzielabs.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.spikenzielabs.com\/blog\/wp-json\/wp\/v2\/comments?post=972"}],"version-history":[{"count":10,"href":"https:\/\/www.spikenzielabs.com\/blog\/wp-json\/wp\/v2\/posts\/972\/revisions"}],"predecessor-version":[{"id":989,"href":"https:\/\/www.spikenzielabs.com\/blog\/wp-json\/wp\/v2\/posts\/972\/revisions\/989"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.spikenzielabs.com\/blog\/wp-json\/wp\/v2\/media\/976"}],"wp:attachment":[{"href":"https:\/\/www.spikenzielabs.com\/blog\/wp-json\/wp\/v2\/media?parent=972"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.spikenzielabs.com\/blog\/wp-json\/wp\/v2\/categories?post=972"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.spikenzielabs.com\/blog\/wp-json\/wp\/v2\/tags?post=972"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}