{"id":372,"date":"2024-11-25T11:17:39","date_gmt":"2024-11-25T11:17:39","guid":{"rendered":"https:\/\/fletch.scot\/wp\/?p=372"},"modified":"2024-11-25T11:31:08","modified_gmt":"2024-11-25T11:31:08","slug":"adding-track-info-display-part-2","status":"publish","type":"post","link":"https:\/\/fletch.scot\/wp\/?p=372","title":{"rendered":"Adding Track Info Display (part 2)"},"content":{"rendered":"<p>\u00a0<\/p>\n<p>In my previous post, I outlined some improvements I wanted to implement for the track display project using the Yamaha R-N602. This time, I\u2019ve tackled two key enhancements: supporting non-ASCII characters and displaying the time when the receiver is off. Here\u2019s how it came together.<\/p>\n<h3>Handling Non-ASCII Characters<\/h3>\n<p>I enjoy a wide range of music, some of which isn\u2019t in English. This often means track titles, artist names, and album titles include characters the LCD display doesn\u2019t render correctly. The R-N602 provides these details as UTF-8 encoded JSON but my LCD display can\u2019t handle non-ASCII characters. Since I couldn\u2019t find an Arduino library to convert UTF-8 to ASCII, I decided to write my own solution.<\/p>\n<p>The implementation is straightforward. I created helper lambda functions to assist the processDetails function. A small map translates specific UTF-8 characters to their ASCII equivalents\u2014for example, the character \u00e8 becomes e. The map is intentionally kept short to optimize performance as it\u2019s searched linearly. So some characters aren\u2019t mapped.<\/p>\n<p>Two lambda helpers complete the setup:<\/p>\n<ol>\n<li>One maps individual characters.<\/li>\n<li>The other replicates the behaviour of strncpy, applying the mapping to entire strings.<\/li>\n<\/ol>\n<p>This approach allowed me to seamlessly replace strncpy calls in processDetails with my helper function. Now, a track title like Florence sur les Champs-\u00c9lys\u00e9es appears as Florence sur les Champs-Elysees on the display. While this transformation sacrifices accents, it significantly improves readability\u2014though a French speaker might disagree!<\/p>\n<h3><strong>Adding a Time Display<\/strong><\/h3>\n<p>I also added functionality to display the current time, day, and date when the R-N602 is turned off. This feature uses two Arduino pins which my LCD display shield exposes.<\/p>\n<ul>\n<li>Pin A1: Toggles between GMT and BST (British Summer Time), the two time zones in Scotland. The default is GMT, but pulling the pin low switches to BST.<\/li>\n<li>Pin A2: Controls whether the time display is always active. By default, the display shows track details, but pulling this pin low forces the clock to display.<\/li>\n<\/ul>\n<p>With these additions, the project doubles as a clock.<\/p>\n<p>For simplicity, the time is fetched from an NTP server since the Arduino doesn\u2019t have a real-time clock module. Accuracy isn\u2019t perfect\u2014it can drift by up to 30 seconds\u2014but it\u2019s sufficient for this use case.<\/p>\n<p>Initially, I tried using an existing Arduino library to handle the time, but I encountered issues with the day() function, which appeared unavailable probably due to a misconfiguration in my setup. Rather than spending more time troubleshooting (I\u2019ve already dealt with my fair share of library issues), I opted to reuse some lambda functions from a previous project. Functional programming really shines here: self-contained, global-free functions are easy to repurpose with minimal effort.<\/p>\n<h3><strong>Bug Fixes Along the Way<\/strong><\/h3>\n<p>While working on these features, I also fixed a few bugs. The most significant was a scrolling issue: the last two characters of a scrolling text string weren\u2019t displaying due to a -1 where there should have been a +1. A small fix, but it made a big difference in usability.<\/p>\n<h3><strong>Wrapping Up<\/strong><\/h3>\n<p>That\u2019s it for now. These enhancements have made the track display project much more functional and user-friendly. If you\u2019re interested, the updated code is available here: <a title=\"yamaha-song.ino.zip\" href=\"https:\/\/fletch.scot\/wp\/wp-content\/uploads\/2024\/11\/yamaha-song.ino_-1.zip\">yamaha-song.ino.zip<\/a>.<\/p>\n<p>I hope this inspires some ideas for your own projects! If you\u2019ve got questions or suggestions, feel free to share in the comments.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 In my previous post, I outlined some improvements I wanted to implement for the track display project using the Yamaha R-N602. This time, I\u2019ve tackled two key enhancements: supporting non-ASCII characters and displaying the time when the receiver is off. Here\u2019s how it came together. Handling Non-ASCII Characters I enjoy a wide range of &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/fletch.scot\/wp\/?p=372\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Adding Track Info Display (part 2)&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-372","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/posts\/372","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=372"}],"version-history":[{"count":4,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/posts\/372\/revisions"}],"predecessor-version":[{"id":377,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/posts\/372\/revisions\/377"}],"wp:attachment":[{"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=372"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=372"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=372"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}