{"id":3781,"date":"2020-02-22T18:13:19","date_gmt":"2020-02-22T18:13:19","guid":{"rendered":"https:\/\/redfrontdoor.org\/blog\/?p=3781"},"modified":"2020-02-23T17:08:54","modified_gmt":"2020-02-23T17:08:54","slug":"binary-email-lights","status":"publish","type":"post","link":"https:\/\/redfrontdoor.org\/blog\/?p=3781","title":{"rendered":"Binary Email Lights"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">[This is a guest post written by Zach.]<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignright size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/redfrontdoor.org\/blog\/wp-content\/uploads\/2020\/02\/intro-photo.jpg\" alt=\"\" class=\"wp-image-3786\" width=\"442\" height=\"294\" srcset=\"https:\/\/redfrontdoor.org\/blog\/wp-content\/uploads\/2020\/02\/intro-photo.jpg 640w, https:\/\/redfrontdoor.org\/blog\/wp-content\/uploads\/2020\/02\/intro-photo-300x200.jpg 300w\" sizes=\"auto, (max-width: 442px) 100vw, 442px\" \/><figcaption>Six unread emails!<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">I\u2019ve been using a Raspberry Pi as a desktop for a while now and it has been working great, but one annoying thing was that I had to turn on both my monitors (in case the mouse is in the wrong one) when I wanted to check my email, so I thought to make a light box to tell me if I had an email. Also, flashing lights are always cool.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I, with my dad, built a display box with three LEDs so it can show up to seven emails in binary.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Hardware<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The hardware side of\nthis project was pleasingly simple because the Raspberry Pi has built\nin GPIO pins.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>What we used:<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">LEDs, resistors,\nethernet cable, heat shrink, header\npin connectors, small, sturdy\ncardboard box, and hot glue\n(lots).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Assembly:<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">We set up the LEDs and resistors like in <a href=\"https:\/\/thepihut.com\/blogs\/raspberry-pi-tutorials\/27968772-turning-on-an-led-with-your-raspberry-pis-gpio-pins\">this Pi Hut tutorial<\/a> with a common ground, and hot glued them into the box. We used a length of ethernet cable to connect between the Raspberry Pi and the LED unit. We connected the ethernet cable to the Raspberry Pi via 3 GPIO pins and one ground that were all right beside each other with the header pin connectors as shown. I have a nice case that leaves the GPIO pins accessible.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/redfrontdoor.org\/blog\/wp-content\/uploads\/2020\/02\/gpio-connection.jpg\" alt=\"\" class=\"wp-image-3783\" width=\"374\" height=\"374\" srcset=\"https:\/\/redfrontdoor.org\/blog\/wp-content\/uploads\/2020\/02\/gpio-connection.jpg 640w, https:\/\/redfrontdoor.org\/blog\/wp-content\/uploads\/2020\/02\/gpio-connection-300x300.jpg 300w, https:\/\/redfrontdoor.org\/blog\/wp-content\/uploads\/2020\/02\/gpio-connection-150x150.jpg 150w\" sizes=\"auto, (max-width: 374px) 100vw, 374px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Software<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">We wrote the software in two pieces; one that got the number of unread emails and one that lit up the lights to show it; breaking it into smaller problems to solve and test.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Email Checker<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">We followed Google&#8217;s <a href=\"https:\/\/developers.google.com\/gmail\/api\/quickstart\/python\">Gmail Quickstart example<\/a><em>, <\/em>which was very easy to read and use. We changed the example a bit, to make it:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li> get the number of unread emails instead of a list of labels <\/li><li> write the output to a file instead of printing it <\/li><li> repeat in a 30-second loop <\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"> <strong>LED Binary Display Driver<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\nThis part of the system:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li> reads the content of the file and turns it into an integer <\/li><li> works out which lights to turn on and turns them on <\/li><li> deals with the special case of there being more than seven unread emails by flashing all three lights <\/li><li> repeats in a one-second loop <\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Race Condition<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Surprisingly, the display driver program occasionally read the file while it was empty and then crashed. We knew this was a possibility, but thought it wouldn\u2019t actually happen. We fudged our way round it by the display driver retrying after two seconds if this happens.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Simulation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Play with the slider:<\/p>\n\n\n\n<div id=\"leds-simulation-container\">\n  <div>\n    <p id=\"slider-container\"><input type=\"range\" min=\"0\" max=\"10\" value=\"0\" class=\"slider\" id=\"myRange\"><\/p>\n    <p id=\"slider-value\">0<\/p>\n  <\/div>\n  <p id=\"leds-simulation-placeholder\">(Loading&#8230;)<\/p>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Future work<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Automatically start the two programs when the Raspberry Pi is booted up.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Code<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The code is available <a href=\"https:\/\/github.com\/bennorth\/rpi-email-LEDs\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[This is a guest post written by Zach.] I\u2019ve been using a Raspberry Pi as a desktop for a while now and it has been working great, but one annoying thing was that I had to turn on both my monitors (in case the mouse is in the wrong one) when I wanted to check my email, so I thought to make a light box to tell me if I had an email. Also, flashing lights are always cool. I, with my dad, built a display box with three LEDs so it can show up to seven emails in binary. Hardware The hardware side of this project was pleasingly simple because the Raspberry Pi has built in GPIO pins. What<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3781","post","type-post","status-publish","format-standard","hentry","category-uncategorized","comments-off"],"_links":{"self":[{"href":"https:\/\/redfrontdoor.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3781","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/redfrontdoor.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/redfrontdoor.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/redfrontdoor.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/redfrontdoor.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3781"}],"version-history":[{"count":17,"href":"https:\/\/redfrontdoor.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3781\/revisions"}],"predecessor-version":[{"id":3808,"href":"https:\/\/redfrontdoor.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3781\/revisions\/3808"}],"wp:attachment":[{"href":"https:\/\/redfrontdoor.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3781"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/redfrontdoor.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3781"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/redfrontdoor.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3781"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}