An oscilloscope is a very handy device to have around for analyzing electrical signals that change over time. These signals may come from microphones (so you can look at the waves produced by music or voice) or from any other sensor you can connect electrically.
In the photo above, you can see a close-up of the oscilloscope screen, showing an 880 Hertz sine wave generated by our previous project, the Arduino Sine Wave Generator.
The parts for the oscilloscope are fairly simple, easing the construction considerably:
We have the 1.8 inch thin-film transistor LCD screen we used in the previous project, and Arduino Nano. a rotary encode (the same one as used in the previous project) and some Dupont ribbon cable for putting the other parts together.
The female ends of the ribbon cable fit nicely onto the pins of the LCD screen. The male ends fit into the holes in the Arduino Nano board, where they are then soldered in place:
|LCD pin||Color||Arduino pin|
|Encoder pin||Color||Arduino pin|
|Bottom right||Blue||Pin 3|
The final steps are to solder the male ends of the encoder wires to the proper holes in the Arduino Nano, and to solder two extra wires (I used white and gray) to be our input connections, where the signal will come in. The gray wire is connected to any of the grounded places. I chose to bend the pin and solder it to the back of the Arduino Nano's ground hole where the brown Dupont wire came through, since we have already used up both of the convenient ground holes on the Nano. If you find it easier to connect the gray wire to either of the leftmost pins on the rotary encoder, that will do nicely, as they are (of course) connected to each other and to the Nano's other ground hole.
The white wire is connected to the A0 pin on the Nano. This is the analog pin where our signal comes in.
The photo above shows the oscilloscope connected to our Sine Wave Generator, which is set to produce a 440 Hz sine wave (in music, that is called an A, or A440). Note that I chose to use the same color scheme (white and gray) for the oscilloscope inputs as for the sine wave generator outputs, to make it easy to remember which wire is signal and which is ground. The sine wave had male outputs, so the oscilloscope has female inputs.
When we double the frequency to 880 Hertz, we get the A an octave above A440, and you can see that we get twice as many sine waves on the screen.
You can power the oscilloscope with a 3.3 volt battery if you like, just as we did with the sine wave generator. Just connect the battery to the 5 volt input hole of the Arduino Nano -- it will run just fine on the lower voltage. I generally don't bother with batteries, finding it more convenient to simply use the Nano's USB programming cable to power it. The photo above shows the two projects together in their quaint wooden boxes (feel free to use commercial plastic project boxes, or 3D printed cases, of course). A smoked-glass or other dark cover will hide imperfections and the LCD bezel, and only the text and lines will show through.
The photo above shows what you get when you use the rotary encoder to select the Trigger menu. The trigger is the green line on the screen, and rotating the encoder clockwise or counterclockwise adjusts the green line up or down. This has the effect of selecting the voltage at which the scan begins. When the signal voltage reaches the trigger setting, the oscilloscope starts recording samples.
The other main menu option is the samples per second setting.
There are four options, 80 thousand samples per second, 40 thousand, 20 thousand, and 10 thousand.
The 80 thousand samples per second option really pushes the limits of the little computer, and it can't actually sample that fast, due to the overhead of interrupt handling, but it gets close. For the same reason, there is very little computing power left over for noticing changes to the rotary encoder settings, so some patience is required to even get out of that mode (of course you can always power it down or reset it, and it will come back in 40,000 samples per second mode).
As you can see in the photo above, when we samples at 20,000 samples per second, we see more of the waveform.
At 10,000 samples per second, we see even more, as shown above. The setting you choose will depend on the frequency of the incoming signal. These photos show 440 Hertz. At frequencies around 20,000 Hertz, you would select 40,000 samples per second, or 80,000, or else the waves would all seem to crowd together.
The source code for the oscilloscope can be found here.
The program has several parts, each in its own file. The menu system resides in the file RotaryMenu.h. The code that actually samples the voltages using the Analog to Digital Converter (ADC) inside the Nano is in ADC.cpp and its header file ADC.h. The code that uses the rotary encoder menu system to control the ADC is in the main file, NanoScope.ino.
This separation of function allows you to more easily use the ADC code or the menu code in other programs.
The oscilloscope uses the Adafruit_GFX and Adafruit_ST7735 libraries like the sine wave generator project does. The detailed instructions for loading and installing those libraries can be found there.