Adding Track Info Display (part 2)

 

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’ve tackled two key enhancements: supporting non-ASCII characters and displaying the time when the receiver is off. Here’s how it came together.

Handling Non-ASCII Characters

I enjoy a wide range of music, some of which isn’t in English. This often means track titles, artist names, and album titles include characters the LCD display doesn’t render correctly. The R-N602 provides these details as UTF-8 encoded JSON but my LCD display can’t handle non-ASCII characters. Since I couldn’t find an Arduino library to convert UTF-8 to ASCII, I decided to write my own solution.

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—for example, the character è becomes e. The map is intentionally kept short to optimize performance as it’s searched linearly. So some characters aren’t mapped.

Two lambda helpers complete the setup:

  1. One maps individual characters.
  2. The other replicates the behaviour of strncpy, applying the mapping to entire strings.

This approach allowed me to seamlessly replace strncpy calls in processDetails with my helper function. Now, a track title like Florence sur les Champs-Élysées appears as Florence sur les Champs-Elysees on the display. While this transformation sacrifices accents, it significantly improves readability—though a French speaker might disagree!

Adding a Time Display

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.

  • 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.
  • 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.

With these additions, the project doubles as a clock.

For simplicity, the time is fetched from an NTP server since the Arduino doesn’t have a real-time clock module. Accuracy isn’t perfect—it can drift by up to 30 seconds—but it’s sufficient for this use case.

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’ve 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.

Bug Fixes Along the Way

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’t displaying due to a -1 where there should have been a +1. A small fix, but it made a big difference in usability.

Wrapping Up

That’s it for now. These enhancements have made the track display project much more functional and user-friendly. If you’re interested, the updated code is available here: yamaha-song.ino.zip.

I hope this inspires some ideas for your own projects! If you’ve got questions or suggestions, feel free to share in the comments.

CategoriesUncategorised

Leave a Reply

Your email address will not be published. Required fields are marked *