{"id":380,"date":"2014-06-16T21:20:17","date_gmt":"2014-06-16T21:20:17","guid":{"rendered":"http:\/\/interactingobjects.com\/?p=380"},"modified":"2014-12-15T20:56:58","modified_gmt":"2014-12-15T20:56:58","slug":"sparkfuns-4x4-button-led-matrix-part-2-connecting-to-an-arduino-mega","status":"publish","type":"post","link":"https:\/\/interactingobjects.com\/?p=380","title":{"rendered":"Sparkfun\u2019s 4\u00d74 Button &#038; LED Matrix \u2013 Part 2 \u2013 Connecting to an Arduino Mega"},"content":{"rendered":"<p>I described,<a href=\"http:\/\/interactingobjects.com\/?p=347\"> in a previous post<\/a>, how to assemble a 4&#215;4 Sparkun&#8217;s button and led matrix. Let see how to connect it.<\/p>\n<p>Because of the (quite) large number of leds and button, I will be using an Arduino MEGA. That will allow to drive RGB leds and button\u00a0without any additionnal \u00a0component. Well&#8230; almost : we&#8217;ll still need<\/p>\n<ul>\n<li>12 150\u03a9 resistor for the RGB leds<\/li>\n<li>a few jumper wires<\/li>\n<li>3 small breadboards<\/li>\n<li>an Arduino MEGA of course<\/li>\n<\/ul>\n<h1>RGB led and Arduino<\/h1>\n<p><a href=\"http:\/\/interactingobjects.com\/wp-content\/uploads\/2014\/06\/RGB-LED-details.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft wp-image-383\" src=\"http:\/\/interactingobjects.com\/wp-content\/uploads\/2014\/06\/RGB-LED-details.png\" alt=\"RGB LED details\" width=\"211\" height=\"265\" \/><\/a>An RGB led is actually&#8230; 3 leds : 1 Red, 1 Green and 1 Blue (thus RGB). They all share a common cathode and have 3 anodes, 1 per color.<\/p>\n<p>Choosing the voltage applied to each color allows to choose the brightness of each color, allowing, in turn, to display a broad range of colors.<\/p>\n<p>An Arduino does not have analog outputs. Only digital ones. So we&#8217;ll use digital output to &#8220;simulate&#8221; \u00a0analog ones using a technique called PWM. For more details on PWM see <a href=\"http:\/\/arduino.cc\/en\/Tutorial\/PWM\">here<\/a>.<\/p>\n<h1>Wiring the button &amp; led matrix<\/h1>\n<p>Without the matrix, we would need 3&#215;16=48 PWM pins&#8230; that&#8217;s a lot. With the matrix, we only have 4 rows, each row being connected to 4 leds. This implies some limitations but we now only need 3&#215;4=12 PWM pins and Arduino MEGA 2560 has&#8230; 15 of it. Phew&#8230;<\/p>\n<p>In addition of connecting the anodes to PWM pins, we also need to connect the cathodes to \u00a0simples digital pins. We only need 4 of them because we have 4 columns, each column being populated with 4 leds sharing the GND.<\/p>\n<p>And then, we&#8217;ll need 4 digital pins for button GND (cols) and 4 more for signal (rows)<\/p>\n<p><a href=\"http:\/\/interactingobjects.com\/wp-content\/uploads\/2014\/06\/button-pad-connection.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-385\" src=\"http:\/\/interactingobjects.com\/wp-content\/uploads\/2014\/06\/button-pad-connection.png\" alt=\"button pad connection\" width=\"934\" height=\"583\" srcset=\"https:\/\/interactingobjects.com\/wp-content\/uploads\/2014\/06\/button-pad-connection.png 934w, https:\/\/interactingobjects.com\/wp-content\/uploads\/2014\/06\/button-pad-connection-300x187.png 300w, https:\/\/interactingobjects.com\/wp-content\/uploads\/2014\/06\/button-pad-connection-480x300.png 480w\" sizes=\"auto, (max-width: 934px) 100vw, 934px\" \/><\/a><\/p>\n<p>You&#8217;ll find an interresting article about about keyboard matrix <a href=\"http:\/\/www.dribin.org\/dave\/keyboard\/one_html\/\">here<\/a>.<\/p>\n<h1>And put it in a box !<\/h1>\n<p>I used the box in which my <a title=\"NetAtmo : now they have a connected thermostat !\" href=\"http:\/\/interactingobjects.com\/netatmo-more-than-just-a-weather-station\/\">netatmo thermostat<\/a> was provided : a nice cube with the perfect size ! I&#8217;ve done a bit of cut in the box and the spacers and here is the final result :<\/p>\n<p><a href=\"http:\/\/interactingobjects.com\/wp-content\/uploads\/2014\/06\/In-the-box-closed.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-386\" src=\"http:\/\/interactingobjects.com\/wp-content\/uploads\/2014\/06\/In-the-box-closed.png\" alt=\"In the box closed\" width=\"247\" height=\"186\" srcset=\"https:\/\/interactingobjects.com\/wp-content\/uploads\/2014\/06\/In-the-box-closed.png 640w, https:\/\/interactingobjects.com\/wp-content\/uploads\/2014\/06\/In-the-box-closed-300x225.png 300w, https:\/\/interactingobjects.com\/wp-content\/uploads\/2014\/06\/In-the-box-closed-400x300.png 400w\" sizes=\"auto, (max-width: 247px) 100vw, 247px\" \/><\/a><a href=\"http:\/\/interactingobjects.com\/wp-content\/uploads\/2014\/06\/In-the-box-opened.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-387\" src=\"http:\/\/interactingobjects.com\/wp-content\/uploads\/2014\/06\/In-the-box-opened.png\" alt=\"In the box opened\" width=\"248\" height=\"188\" \/><\/a><\/p>\n<h1>\u00a0A simple test program<\/h1>\n<p>We&#8217;we wired evrything up, we can start programming the gizmo and see what it can do. You will find a test program here.<\/p>\n<p>[youtube]https:\/\/www.youtube.com\/watch?v=MkMSSoQJhq4[\/youtube]<\/p>\n<p>As you see, it is quite simple : at startup, it senquentially lights up all leds then, on each button press, it light up the corresponding led, changing color each time.<\/p>\n<p>It is just for testing. I&#8217;ll work on some more interresting programs and post them !<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I described, in a previous post, how to assemble a 4&#215;4 Sparkun&#8217;s button and led matrix. Let see how to connect it. Because of the (quite) large number of leds and button, I will be using an Arduino MEGA. That &hellip; <a href=\"https:\/\/interactingobjects.com\/?p=380\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[111,86],"tags":[88,94,95,93,91,96],"class_list":["post-380","post","type-post","status-publish","format-standard","hentry","category-4x4-button-pad","category-arduino-2","tag-arduino-mega","tag-com-07835","tag-com-08033","tag-led-matrix","tag-rgb-led","tag-sparkfuns-button-pad"],"_links":{"self":[{"href":"https:\/\/interactingobjects.com\/index.php?rest_route=\/wp\/v2\/posts\/380","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/interactingobjects.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/interactingobjects.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/interactingobjects.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/interactingobjects.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=380"}],"version-history":[{"count":17,"href":"https:\/\/interactingobjects.com\/index.php?rest_route=\/wp\/v2\/posts\/380\/revisions"}],"predecessor-version":[{"id":574,"href":"https:\/\/interactingobjects.com\/index.php?rest_route=\/wp\/v2\/posts\/380\/revisions\/574"}],"wp:attachment":[{"href":"https:\/\/interactingobjects.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=380"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/interactingobjects.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=380"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/interactingobjects.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}