#Finally got my new alarm clock built.

1 messages · Page 1 of 1 (latest)

plain quartz
#

This was one of those fairly long projects that was one issue after another, but I was finally able to get them all solved and have a working clock.

#

The first thing I knew, before even starting was that the ESP32-S2 would not do interrupt based playback with the Music Maker. That's noted in the learn guide. The solution turned out to be relatively easy in principle, but still took a little care and attention.

#

I started from the feather-player sample sketch found in the Adafruit_VS1053_Library library, and went to work on that. Since I wasn't ever going to just play a file "blocking" I immediately removed the call to musicPlayer.playFullFile found on line 110, and instead set up to use musicPlayer.startPlayingFile for everything.

#

I then #if 0ed out the section between lines 98 and 106 to completely disable interrupt usage.

#

Then, probably as a result of working under PlatforIO rather than the Arduino IDE, I found that it was selecting the pin definition using lines 20 through 23. Those didn't work, so I just #if 0ed out all the board specific pin selections, and forced it to use the definitions on lines 54 through 58.

#

The last change needed was to add the following routine:

void FeedMusic()
{
    // Feed the VS1053.  This **MUST** be done on a regular basis, I
    // don't know how big the buffers on the chip are, but I want to
    // keep it well fed to ensure flawless playback.
    if (!musicPlayer.stopped() && musicPlayer.readyForData())
    {
        musicPlayer.feedBuffer();
    }
}

and call it on every pass through loop()

#

This collection of changes got successful music playback happening, despite the lack of interrupt capability.

#

"Great!" I think, we're just about done. Hook up the TFT and it's plain sailing. So I attach the SPI side of the TFT to the hardware SPI pins, and test that out.

#

Cutting a long story very short, I could not get music playback to work successfuly if I started drawing the digits of the clock. I tried eveyrhing imaginable, but I could find a reliable solution.

#

Time for plan B: software "bit-bang" SPI for the TFT. That worked, although I had to draw the digits a few rows at a time, to allow for the required calls to FeedMusic() above. After a quick but of hacking of a custom version of the drawBitmap routine in the graphics library, I had it working, but at a speed that was unacceptably slow.

#

This turned out to be one of those "sleep on it" problems, something I'd seen looking around the graphics driver had caught my attention, there was this routine writeFasstVLine. So I took the raw bitmap data I'd been using, and wrote a quick script to convert it to RLE encoded vertical line segments. Long story short: that worked: even with the software SPI, use of the fast line fill meant that a digit redraw took place at a reasonable speed. As can be seen at about 9 seconds into the video.

#

I'm using the same optimization on this clock that I set up on the earlier ESP8266 desk clocks, in that I don't bother to draw a character that hasn't changed. So every minute it tries to redraw all four digits of the clock, including the leading space in the hours. But since 90% of the time only the units digit of the minutes has changed, the redraw is pretty fast.

#

And of course, it sets itself from the NTP server on my network, and is aware of the timezone we live in, so it has the necessary information to switch to and from daylight savings fully automatically.

#

Setting the alarm time is done using a lightweight custom protocol I dreamed up, that has the ability to find the clock, no matter what IP address the router has assigned it.
The final piece was to read the VEML 7700 on a regular basis, and use the value to determine when to dim the backlight. The PWM capability of the WSP32-S2 made that a relatively trivial task.

#

And just to wrap up, this is the back view showing the ESP32-S2 stacked on top of the Music Maker. I found that a necessity, otherwise it would have been almost impossible to reprogram the ESP32-S2. That's because I need to hit both buttons on top of it, and with both the STEMMA QT and the headers in use, it's a little crowded around the Bootsel button.

zenith frigate
#

@plain quartz Why vertical lines instead of horizontal so that it refreshes top to bottom? Less data per column to process instead of rows for faster refresh?