Unripe (Ada)fruit?

I’ve always been an Adafruit fan, gladly supporting their open source contributions by buying their products. But recently, I was very disappointed by the bad performance of their TCA9548A 1-to-8 I2C Expander.

I had bought it to be able to drive two identical SH1106 OLED displays without having to solder on one of the displays in order to give it a different I2C address.

First I ran an I2C scanner, and the result looked promising: all connected I2C devices were detected with their correct I2C address. But then, driving a single display only worked if it was connected to channel 0 of the expander. And even then, the display would often show errors.

Then I tried a DS3231 Real Time Clock, because there’s very little I2C traffic involved in reading  the time from this simple and reliable chip. Even when connected to channel 0, setting the clock didn’t work well and readings of a correctly set clock were mostly  messed up. Since this expander seemed unable to reliably drive a single device, there was no sense in trying to connect multiple devices.

I’ve tried several sketches on 5V Arduinos and 3.3V ESPs, using different sets of wires and with delays added after the channel select function. Nothing really worked, so either my copy of the expander is broken, or this board is not Lady Ada’s best fruit in the basket.

Since my earlier posts on the Adafruit forum never got answered, I will not even bother to ask them this time. Guess I’ll have to solder that 0 Ohm bridge on one of the SH1106 displays after all.

 

Pseudostatic Ram (PSRAM)

 

Just got me a second LOLIN D32 Pro v.2, this time with the newer ESP32-WROVER-B module on board. For just € 1,- extra, it has 4x more RAM and 2x more PSRAM. But what is this PSRAM, and could I use it for memory-hungry sketches, like the ones where AI or pathfinding algorithms are involved?

Searching the Internet gave me a first idea of what it is, but more important: I found out how to use it, which luckily turned out to be remarkably simple.

Below is a simple demo sketch that shows how to address PSRAM. It allocates a 1 MB buffer in PSRAM and then starts writing random integers at random positions, reading them back again for control. Make sure that PSRAM is enabled when you compile it, otherwise the ESP32 will panic! (it’s an option in the Tools menu of the Arduino IDE after a WROVER based ESP32 board has been selected).

[edit: a more useful application can be found in this later post]

Note that GPIO pins 16 and 17 are used for communication between ESP32 and PSRAM, so WROVER-based boards will not have these pins broken out.

Also note that content in PSRAM will be lost after the ESP32 loses power (still have to figure out what happens during deep sleep).

My search for information on PSRAM triggered a more general interest in the chip’s architecture. Espressif’s documentation has been very helpful.

 

Spectrum Analyzer Revisited

Encouraged by the happy ending of the Swinging Needles project, I decided to revisit an earlier audio spectrum analyzer. This time, instead of programmatically processing analog signals, I used a VS1053 plugin to let the chip do the Fourier stuff.

Before even starting to read actual frequency band values, I wanted to test my sketch by reading the plugin’s default frequency settings from VS1053’s memory. However, some of these readings made no sense at all, up to the point that I suspected a faulty chip. It took me some time to find out that the chip needs a few seconds of audio input before it will tell you something useful, even if it concerns a fixed setting like number of frequency bands.

Once the above mystery was solved, things became very straightforward. What a versatile chip this VS1053 is! While playing a 320 Kbps internet radio station, it can easily handle 14 frequency bands and let an esp8266 at 160 MHz show the results on a 128×64 Oled display. Part of the credits should go to the authors of the libraries that I used.

 

First impression produced by the sketch below; better videos with sound (and colors?) will follow.

 

Here’s an esp8266 demo sketch for a basic internet radio (fixed station, no metadata, no audio buffer), just to show a 14 band spectrum analyzer on a 128×64 SH1106 Oled display. Used pins are for the rather rare Wemos D1 R1, so you’ll probably have to change them.

 

This is the content of the plugin.h file that needs to be in the directory of the sketch: