[Working] Arduino X Y Oscilloscope (vector scope)

Hello, I created an Oscilloscope sketch for stereo audio vector visualization on X and Y axis.

GitHub link to download the sketch XY-Scope.ino

It’s working, all you need is a <TFT.h> library compatible SPI screen (plugged in hardware SPI) and coupling capacitors and a resistor tension divider on analog input D1 and D2. See example below:

Simple input circuit (see in raw text):
                   Vin (5v)
                      |
                     10k
                      |
Audio Source - 10µF - + - Analog Input
                      |
                     10k
                      |
                   Ref (0V)

Note: this is not a regular oscilloscope, this is X-Y mode oscilloscope to be used as a vector monitor.

The inspiration came from a YouTube video Techmoan when he bought a vintage tuner with a cool CRT vector scope, and his video on drawing images on the scope using Jerobeam Fenderson’s audio files. I thought that would be cool to have but not at that expansive price point!
I couldn’t find what I was looking for on Arduino so I made it myself.

I am posting it here for people who wants to try nice audio visualisation and for those who would like to help me optimize it even more to increase the sample rate to the MAX!

Here’s the checklist:

  • Optimize the ADC frequency from default 125KHz (10bit precision) to 1MHz (~8bit precision equivalent) through registers DONE
  • Reduce wasted cycles by replacing analogRead() for resister manipulation with an interrupt service routine for the ADC completion DONE
  • Extremely verbose comments in the sketch DONE
  • Create debug outputs to see if the code actually enters the waiting loops while(!readflag). If not, that means the ADC finishes before the other code is done, so that reduces the sample rate.
  • Push the sample rate even higher by trying an ADC frequency of 2,4 and 8MHz (MAX) and see if the display is too noisy
  • Use trial and error to find out how many samples should be kept on the screen at all time through #define samplenumber X
  • Make a version optimized for screens of less than 255 to use unsigned char (8bits) variables instead of unsigned int (16bits) (since the Atmega is an 8bit processor) (may not be an issue, but may help if the ADC is fast enough to keep up with the other code)
  • Make the ADC only fill the most significant 8bits in only one register (since ADC clock higher than 1MHz has a lower precision than 8bits)
  • Find other ideas to enhance the visual experience during playback of Jerobeam Fenderson’s audio files (see on YouTube)

Tell me what you think!
GitHub link to download the sketch XY-Scope.ino