Introduction: Arduino Analog Signal Graphing on a TFT Touch Screen
This video demonstration with source code is an example of analog signal graphing. The project uses an Arduino Mega 2560 and UNO R3 2.8 TFT Touch Screen to display two analog signals as line and bar graphs. One signal is a photo resistor and the second is an audio sample from an Adafruit Electret Microphone Amplifier with Adjustable Gain module. The audio signal is graphically displayed twice; once in the center using a line graph and also on the bottom with a bar graph. The top graph represents the photo resistor signal.
Touching the screen pauses the graph and opens a menu to adjust setting for the graphs. You can change the color and direction of each graph.
Step 1: Download Essential Libraries and Copy the Source Code
Download and install the source code and libraries using the link below. These are needed to interface with the UNO R3 2.8 TFT Touch Screen.
You need to unzip and copy the contents of the libraries folder into the Arduino libraries directory: on windows it is usually \Documents\Arduino\libraries
Watch the video demonstration for more information.
Step 2: Connect Analog Sensors to Arduino Mega 2560
For this project a photo resistor is used for one analog signal. An Adafruit Electret Microphone Amplifier with Adjustable Gain module is used for the second analog signal.
You can view the picture above to see how the connections are made between the Mega and the sensors. Note: there is an extra resistor above the photo resistor that is not being used.
The UNO R3 2.8 TFT Touch Screen covered most of the ports on the Arduino UNO so I used a Mega for this project. The microphone module required 3v -5v and recommended using the less noisy 3v channel on the Arduino. However, the touch screen covered both 3v and 5v ports. So, instead I used digital output 53 as a power source and connected a 220 ohm resistor between the power source and the microphone module. I used a 220 ohm resistor because I just happened to have one on my breadboard. A potentiometer or a higher ohm resistor might work better. However, if you use different voltage or a different resistor, you may need to adjust the code so that the graph displays properly. Changing the strength of the signal will require the data be massaged otherwise the graph spikes won't appear at all (too low) or the whole screen will be filled with the graph (too high).
The microphone module has 3 wires: SIGNAL, GND, and VCC. The GND is connected to the extra GND port on the Arduino (next to pin 53 on my Mega). The signal is connected to analog pin 15 on the Mega.
The photo resistor has one end connected to ground and the other to analog pin 14 on the Mega.
Note: In retrospect, using pin 53 for power is not necessary. The Duino Mega has a 5v output opposite the ground. I am so new to Arduino that I did not know this at the time I wrote the instructable!
Step 3: Upload Sketch and Start Graphing
Once you compile and upload the sketch, the TFT display will begin drawing three graphs. The top graph represents the photo resistor signal and varies depending on light levels. You can easily spike this graph by covering the photo resistor with your finger.
The center graph represents the audio signal. This waveform is drawn as a line graph having a baseline (zero point) at the center of the waveform.
The bottom bar graph is also the audio signal except the data has been modified to flip all negative values positive. If you run the two graphs in the same direction you will see that any spike on the center graph (up or down) will result in an up spike on the bottom graph; a different way of representing the same data.
If you press on the screen a menu will appear with buttons for Top, Center, and Bottom. Below this is a Data Capture area that displays the data from the last touch event. This data can be used to calibrate the touch screen. By pressing on the edges of the display you can determine the raw min and max values for x and y. These values are used in the sketch code and can effect the accuracy of data returned from touch events.
If you press on one of the Top, Center, or Bottom buttons you will see the options for each graph. Here you can set the color of the graph and the direction.
Have fun and experiment with graphing analog signals!