{"id":13434,"date":"2016-04-27T09:00:03","date_gmt":"2016-04-27T16:00:03","guid":{"rendered":"https:\/\/blog.digilentinc.com\/?p=13434"},"modified":"2016-04-27T08:40:49","modified_gmt":"2016-04-27T15:40:49","slug":"raspberry-pi-rainbow-ruler","status":"publish","type":"post","link":"https:\/\/digilent.com\/blog\/raspberry-pi-rainbow-ruler\/","title":{"rendered":"Raspberry Pi Rainbow Ruler"},"content":{"rendered":"<p><a href=\"https:\/\/www.instagram.com\/p\/BB8eWo-yliu\/?taken-by=digilentinc\" target=\"_blank\">Check out a video of the project on the Digilent Instagram<\/a>!<\/p>\n<p>With the new LINX 3.0 release, I thought it would be a cool idea to do a project with the Raspberry Pi 2 and LabVIEW!\u00a0This project uses a <a href=\"https:\/\/digilent.com\/shop\/raspberry-pi-2\/\" target=\"_blank\">Raspberry Pi 2<\/a>, a <a href=\"https:\/\/digilent.com\/shop\/pmodacl2-3-axis-mems-accelerometer\/\" target=\"_blank\">PmodACL2<\/a>, an RGB LED, a <a href=\"https:\/\/digilent.com\/shop\/digilent-pcb-ruler\/\" target=\"_blank\">Digilent PCB Ruler<\/a>, and <a href=\"https:\/\/www.labviewmakerhub.com\/doku.php?id=libraries:linx:start\" target=\"_blank\">LabVIEW MakerHub LINX<\/a> in order to change the color of the LED depending on the acceleration measured. The front panel is also updated to reflect the measurements of the red, green, and blue colors as well as the expected LED color!<\/p>\n<p>If you want to make this project yourself, <a href=\"http:\/\/www.instructables.com\/id\/Raspberry-Pi-Rainbow-Ruler\/\" target=\"_blank\">check out the Instructable<\/a>\u00a0and see <a href=\"http:\/\/www.instructables.com\/id\/Getting-Started-With-the-Raspberry-Pi-2-LabVIEW\/\" target=\"_blank\">this Instructable for info on how to setup your Raspberry Pi or BeagleBone Black<\/a>. If you haven&#8217;t seen LINX in action, check out the LabVIEW MakerHub LINX 3.0 intro video below!<\/p>\n<div class=\"jetpack-video-wrapper\"><iframe loading=\"lazy\" width=\"735\" height=\"413\" src=\"https:\/\/www.youtube.com\/embed\/Cpfo9zJVBEM?feature=oembed\" frameborder=\"0\" allow=\"autoplay; encrypted-media\" allowfullscreen><\/iframe><\/div>\n<p>If you&#8217;re a maker and you&#8217;re interested in using LabVIEW, Digilent sells a Raspberry Pi and <a href=\"https:\/\/digilent.com\/shop\/labview-home-bundle\/\" target=\"_blank\">LabVIEW Home Bundle<\/a>\u00a0together\u00a0called the <a href=\"https:\/\/digilent.com\/shop\/labview-physical-computing-kit-for-raspberry-pi-2\/\" target=\"_blank\">Raspberry Pi 2 Physical Computing Kit<\/a>.<\/p>\n<p>The first step for this project (and most time consuming step, in my opinion), is to start soldering. Because we&#8217;re connecting the RGB LED and the PmodACL2 to the Raspberry Pi, we&#8217;ll need wires from the PCB ruler\u00a0 connected on to the Raspberry Pi 2. These wires allow the Raspberry Pi 2 to get the acceleration values from the PmodACL2 and update the colors of the RGB LED on the ruler.\u00a0We&#8217;ll need to solder 3.3V and ground on the right side of the ruler, and we&#8217;ll also need 3 wires for the RGB LED and 4 wires for the SPI communication with the PmodACL2.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-13676 aligncenter\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/04\/20160225_160926-1-600x338.jpg\" alt=\"20160225_160926\" width=\"600\" height=\"338\" srcset=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/04\/20160225_160926-1-600x338.jpg 600w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/04\/20160225_160926-1-768x432.jpg 768w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/04\/20160225_160926-1-1024x576.jpg 1024w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/04\/20160225_160926-1-800x450.jpg 800w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>Each of the\u00a0RGB legs corresponds to a different color, and the fourth and longest leg is the common anode for the LED. When you drive one of the color legs low, that color will light up. You can also mix colors by turning on multiple colors at once.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-13672 size-medium aligncenter\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/04\/wireSetup-e1461690682902-600x338.jpg\" alt=\"wireSetup\" width=\"600\" height=\"338\" srcset=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/04\/wireSetup-e1461690682902-600x338.jpg 600w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/04\/wireSetup-e1461690682902-768x432.jpg 768w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/04\/wireSetup-e1461690682902-1024x576.jpg 1024w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/04\/wireSetup-e1461690682902-800x450.jpg 800w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>Once all the wires are soldered, we connect the wires to the Raspberry Pi! Check out the <a href=\"https:\/\/www.labviewmakerhub.com\/doku.php?id=learn:libraries:linx:device:raspberry-pi-2-b\" target=\"_blank\">LINX pinout here<\/a> for the board. Chip select of the Pmod (the first pin) is connected to pin 7 on the Raspberry Pi. Ground is to pin 9, LED blue to pin 11, LED green to pin 13, LED red to pin 15, power to pin 17, MOSI to pin 19, MISO to pin 21, and SCK to pin 23. The connections should all be in one row like it is pictured above.<\/p>\n<p>Here&#8217;s what the LabVIEW front panel looks like:<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-13671 aligncenter\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/04\/front-panel-600x273.png\" alt=\"front panel\" width=\"600\" height=\"273\" srcset=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/04\/front-panel-600x273.png 600w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/04\/front-panel-768x350.png 768w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/04\/front-panel-1024x466.png 1024w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/04\/front-panel-800x364.png 800w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/04\/front-panel.png 1206w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>And here is our block diagram:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-13670 aligncenter\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/04\/block-diagram-600x198.png\" alt=\"block diagram\" width=\"600\" height=\"198\" srcset=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/04\/block-diagram-600x198.png 600w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/04\/block-diagram-768x253.png 768w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/04\/block-diagram-1024x338.png 1024w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/04\/block-diagram-800x264.png 800w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/04\/block-diagram.png 1182w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/>The LabVIEW code opens a reference to the LINX device and the PmodACL2. The PmodACL2 is set to record a scale of \u00b12g with CS on pin 7, SPI channel 0, and a output data rate of 100Hz. Next we enter a while loop. For each loop, we read the acceleration values from each axis and display them in a chart on the front panel. We then take the absolute value of the acceleration values\u00a0and\u00a0compare each axis acceleration value to 0.4g. If the acceleration is less than 0.4, the corresponding axis color is written high (this is because the LED color turns on when we drive the leg low not high!). When the acceleration is above 0.4g, the corresponding LED color is written low and the color turns on. To display our resulting color on the front panel, we use a select block to determine if each color is on or off (there&#8217;s no PWM on the RPI so it&#8217;s all on or all off).Then we write the RGB colors and combine them to give the expected color from the RGB led on an indicator on the front panel. Once the while loop is ended, we write all the RGB legs high to turn off the RGB LED and then close the PmodACL2 and LINX references.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-13682 aligncenter\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/04\/20160225_1648500-600x338.jpg\" alt=\"20160225_164850(0)\" width=\"600\" height=\"338\" srcset=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/04\/20160225_1648500-600x338.jpg 600w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/04\/20160225_1648500-768x432.jpg 768w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/04\/20160225_1648500-1024x576.jpg 1024w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/04\/20160225_1648500-800x450.jpg 800w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>One way to improve this project would be to add PWM instead of just turning a color all the way on or all the way off. This would allow for even more color combinations! In the LabVIEW code, you could take a percentage of 1g as the PWM value and then you could take this percent of 255 to get the corresponding RGB values to display the color on the front panel!<\/p>\n<div class='watch-action'><div class='watch-position align-left'><div class='action-like'><a class='lbg-style6 like-13434 jlk' data-task='like' data-post_id='13434' data-nonce='b99b93a390' rel='nofollow'><img src='https:\/\/digilent.com\/blog\/wp-content\/plugins\/wti-like-post-pro\/images\/pixel.gif' title='Like' \/><span class='lc-13434 lc'>0<\/span><\/a><\/div><div class='action-unlike'><a class='unlbg-style6 unlike-13434 jlk' data-task='unlike' data-post_id='13434' data-nonce='b99b93a390' rel='nofollow'><img src='https:\/\/digilent.com\/blog\/wp-content\/plugins\/wti-like-post-pro\/images\/pixel.gif' title='Unlike' \/><span class='unlc-13434 unlc'>0<\/span><\/a><\/div><\/div> <div class='status-13434 status align-left'>Be the 1st to vote.<\/div><\/div><div class='wti-clear'><\/div>","protected":false},"excerpt":{"rendered":"<p>Raspberry, Pi, Rainbows&#8230;what may sound like part of an awesome new chidrens cereal are actually key components of Dharshan&#8217;s latest project using Labview Makerhub!<\/p>\n","protected":false},"author":33,"featured_media":13680,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1561],"tags":[],"ppma_author":[4481],"class_list":["post-13434","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-applications"],"jetpack_featured_media_url":"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/04\/20160224_161818-2.jpg","jetpack_sharing_enabled":true,"authors":[{"term_id":4481,"user_id":33,"is_guest":0,"slug":"sudharsan-sukumar","display_name":"Sudharsan Sukumar","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/a14d4c855a4738a3b7d04f48ab9936a38ea5a056ea75b4761a407b53dac5597b?s=96&d=mm&r=g","1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":"","9":"","10":""}],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/13434","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/users\/33"}],"replies":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/comments?post=13434"}],"version-history":[{"count":0,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/13434\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/media\/13680"}],"wp:attachment":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/media?parent=13434"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/categories?post=13434"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/tags?post=13434"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=13434"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}