Arduino-Oscilloscope: Why It Works
by MYawar in Circuits > Arduino
4816 Views, 8 Favorites, 0 Comments
Arduino-Oscilloscope: Why It Works
A few years back as I was getting into electronics and studying the basic principles. I found that a scope is the tool that helps you in almost everything. Now that I understood that, I set out to learn the basic principles of the working of a scope, after a few months, I thought to myself, well a oscilloscope is implementable on a micro-controller if I put myself in a learning point of perspective. Why a micro-controller, because it had all the things necessary to build one, like a ADC to take in a signal (but with no control front end), it had GPIO ports which could be used for a lot of purposes, it also has a CPU albeit meek! (I was thinking of a arduino).
I started out with researching about arduino oscilloscopes which were good and very good, but I would have liked a simpler code that is easy to modify and understand. Just as I was searching I came across the base of the current code on the arduino forums from 'vaupell'. I started modifying it and commenting on it and cleaning on the stuff to make it more readable. The original code is from Noriaki Mitsunaga.
So lets see how to setup the hardware and software and how to use it.
I have yet to start writing the explanation for the code on the GitHub wiki. if you have some time to spare do take a look around.
! - This project doesn't detail how to make a oscilloscope, rather it shows you how you can use a simple micro-controller to emulate the behavior of a real world oscilloscope to understand how a Oscilloscope works.
Knowing Your Hardware
The goal of this project is provide a insight into the working of a scope. For that reason I picked the simplest and popular hardware platform arduino. The code is runnable on a arduino uno or a arduino mega, where the latter is preferred because it has more free and accessible pins when a display is installed on it.
So in this project I'll be using a arduino mega (2560).
The next component is the display. This setup uses a arduino TFT 2.5 inch touch shield (the driver id is 0x9341). This gives the ability to display multiple channels on the screen which are distinguishable from each other.
Thats all there is to it. However !, this scope is very limited in its capabilities so dont push it to the edge. Some specific things to care about are;
the arduino ADC cannot handle voltages above 5 volts very well and neither can it handle voltages below 0 volts well. Why, because it is designed so.
acquiring data from multiple channels simultaneously reduces the effective sampling rate of a single channel because the samples are taken alternatively from the multiple channels.
the sampling rate is very low (for a single channel acquisition it might go upto 10kSps, but with two channels it falls off to 5kSps/channel). This can be mitigated by setting the ADC reference frequency (setting the prescalar) to a lower value. However, this has its own problems of bad resolution.
Also dont forget a computer to upload the code to the arduino.
Setup
The setup is very simple;
Attach the display shield to the Arduino Mega so that the power pins on both the boards align.
connect the board to the computer using a USB cable.
Open the arduino IDE and add the TFT display library SPFD5408 (0x9341), if it is not already present.
Now upload the code file from github to the Arduino.
There you have it! . You can tinker with the code by setting channels 8 (ch0) and 15 (ch1) ON or OFF in the code channel setup section. You can change the rate variable to a value from the rate array to set the time/division of the scope. You can set trigger type to auto or single in the trigger section of the code.
The following step shows a ADXL335 3 axis accelerometer being powered and read by the Arduino-Oscilloscope, as is seen in the first video.
Example - ADXL335 Reading the Accelerometer
Power the accelerometer module from the 5V DC and GND of the arduino board on the far right at top and bottom. Now connect the x-out pin of the adxl335 module to the pin A8 of the arduino board as can be seen in the pictures. if the x-axis of the accelerometer is pointed downwards the data-line on the scope screen will be offset from zero since the adxl module will be reading acceleration due to gravity. try shaking it in the x-direction as marked on the adxl-board, the spikes will show up on the screen.
To learn more about the scope and its functioning see the GitHub Wiki
Contribute?
If you would like to contribute to the wiki documentation, you are more than welcome. Oscilloscope is a fantastic piece of equipment and I think its a good STEM tool!.
I am currently working on a small front end with a dummy PGA and an offset control and would add a control for the time/div and maybe reading low voltage AC signals.