Make An Oscilloscope Using The SainSmart Mega2560

Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

http://www.instructables.

com/id/Make-an-Oscilloscope-Using-the-SainSmart-Mega2560-/
Food Living Outside Play Technology Workshop
Make an Oscilloscope Using the SainSmart Mega2560 with the TFT LCD shield
and the 3.5 "color touch screen
by johnag on July 19, 2013
Table of Contents
Make an Oscilloscope Using the SainSmart Mega2560 with the TFT LCD shield and the 3.5 "color touch screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Intro: Make an Oscilloscope Using the SainSmart Mega2560 with the TFT LCD shield and the 3.5 "color touch screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Step 1: UPDATE: Sketch to convert Oscope to 3 Channel DVM with graphic display + Lego enclosure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Step 2: Parts list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Step 3: Build the hardware. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Step 4: The software: UTFT library test. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Step 5: The software: UTouch library test. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Step 6: The Oscilloscope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Step 7: Video of the Oscope in action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Step 8: Another video . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
How to make an Arduino oscilloscope probe by NeoRecasata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
http://www.instructables.com/id/Make-an-Oscilloscope-Using-the-SainSmart-Mega2560-/
Intro: Make an Oscilloscope Using the SainSmart Mega2560 with the TFT LCD shield and the 3.5 "color touch screen
This instructable will show you how to build a portable Touch Screen
Oscilloscope for less than 40 U$!
The oscilloscope is one of the most powerful electronic instruments that
is available to electronics hobbyist, experimenters, and engineers. It is
mainly used to measue time-varying signals. Any time you have a signal
that varies with time( slowly, quickly, and /or periodically ) you can use
an oscilloscope to measure it , visualize it, and to find any unexpected
features in it.
We can use an oscilloscope to observe and study signal characteristics
that we could otherwise not see .
You will learn about the Arduino mega analog to digital converter( ADC).
We will be using the Arduino analog A0 input to sample and capture time
varying signals by Writing a program that will also display those signals
in a 3.8" TFT LCD touch display, and we will input data to modify the
oscilloscope behavior, using the touch capabilities of the screen display.
Before we start building and programming, lets review some basic
characteristics of an oscilloscope.
These are functions you can control on most oscilloscopes:
Sweep speed. Sweep speed is usually measured in units of time per distance,
like milliseconds/centimeter or milliseconds per division.This might also
be referred to as the horizontal sensitivity.
Vertical sensitivity. That's the measure of how sensitive the display dot
is to voltage applied to the input terminals. It is usually measured in
volts/centimeter or volts per division.
A trigger signal can be generated when the signal value reaches some
particular level - the trigger level. In most cases you can set the trigger
level to a voltage value of your choosing. A trigger is used to capture and
stabilize the waveform on the screen, or to wait for an event before
capturing the data
.
The oscilloscope, like my 4 channel DC DVM, will not be as accurate as
a commercial unit, but it works pretty good for low voltage and low frequencies.
Image Notes
1. Triangle Wave from 555 Multivibrator
2. Delay touch button
3. Trigger touch button
4. Horizontal position touch button
5. Reserved for menu or vertical sensitivity
6. Voltage peak to peak
7. Instantaneous voltage
8. Sample capture time display
9. 555 IC circuit running as astable multivibrator
10. LM317 variable voltage regulator
11. Jumper wirer from A0 used as test probe
12. jumper wire From GND pin, connect to ground of circuit under test.
13. USB cable connected to Computer
14. Sainsmart ArduinoMega with shield and TFT LCD touch Display kit
http://www.instructables.com/id/Make-an-Oscilloscope-Using-the-SainSmart-Mega2560-/
Step 1:UPDATE: Sketch to convert Oscope to 3 Channel DVM with graphic display + Lego enclosure
Thank you to all who voted for me! This Instructable won 3rd prize in the Arduino contest, and first prize in the Gadget contest...
Included are pictures and code to convert your oscope to a 3 Channel DVM and to show the output of each channel individually in the scope display by pressing a soft
key on the display. ( the third button from the top)
you will need an L shaped female pin connector if you want to have the flexibility of inserting jumpers, otherwise, just bend the pins on one side of the jumpers to insert
them in the analog channels (A0- A3) to use them as your probes.
Just download the sketch and upload it to the Arduino.
You can label each channel individually, just change the wording in the sketch.
I have also made a lego enclosure for the scope..check out the pictures.
http://www.instructables.com/id/Make-an-Oscilloscope-Using-the-SainSmart-Mega2560-/
Image Notes
1. Lego enclosure for the scope
2. Te three signal voltages in A0-A3
3. Softswitch to change the input channei that is graphed
http://www.instructables.com/id/Make-an-Oscilloscope-Using-the-SainSmart-Mega2560-/
http://www.instructables.com/id/Make-an-Oscilloscope-Using-the-SainSmart-Mega2560-/
http://www.instructables.com/id/Make-an-Oscilloscope-Using-the-SainSmart-Mega2560-/
File Downloads
OscopemegavwDVM.ino (7 KB)
[NOTE: When saving, if you see .tmp as the file ext, rename it to 'OscopemegavwDVM.ino']
http://www.instructables.com/id/Make-an-Oscilloscope-Using-the-SainSmart-Mega2560-/
Step 2:Parts list
You will need :
A Sainsmart mega2560 board with 3.5" tft lcd touch module display and shield kit
A PC with the arduino IDE and a free USB port.
A USB cable
Jumper cables
UTFT library and the UTouch library from Henning Karlsen. web: http://www.henningkarlsen.com/electronics
Image Notes
1. SainSmart 3.2" TFT LCD Display is a LCD touch screen module.
2. SainSmart Mega 2560
3. SainSmart 3.2 inch LCD shield
Step 3:Build the hardware.
Construction of the Oscilloscope is fairly simple. You just have to put the parts of the Sainsmart kit together. All you need to do is add two jumpers; one for ground, and
the other to use as your oscilloscope test probe.
You will need to bend the pins on one side of the jumper wires, and insert them into the A0 pin and GND pin of the Arduino (see pictures for detail), before installing the
display shield, as the display shield will cover the ports once it's in place.
Plug the Shield into the Arduino , then plug the display into the shield, and you're done!!!
Now let's test the display before we turn it into an oscilloscope.
Image Notes
1. Sainsmart kit
Image Notes
1. Kit put together and plugged into USB
http://www.instructables.com/id/Make-an-Oscilloscope-Using-the-SainSmart-Mega2560-/
Image Notes
1. Display inserted in shield
Image Notes
1. Display plugged into shield, side view
Image Notes
1. Side view of display,shield and Mega
Image Notes
1. Front view of Display, shield and Mega
Image Notes
1. Close up view of the kit. Notice the space between the free mega connectors
2. Space to insert bent pins
3. Space to insert bent pins
Image Notes
1. Arduino Mega
2. Jumper with bent pin inserted to GND
3. Jumper inserted to A0 pin used as test probe
http://www.instructables.com/id/Make-an-Oscilloscope-Using-the-SainSmart-Mega2560-/
Image Notes
1. View of Mega with jumper pins bent for insertion to connectors
Step 4:The software: UTFT library test.
If you finished putting your kit together, plug it into the USB cable that connects to your PC running the Arduino IDE.
If you haven't done so, download the UTFT and UTouch Libraries, and copy them to the libraries folder where you have the arduino IDE installed.
If the libraries installed properly, you will see the UTFT and the UTouch options when you click on the Files option, and scroll down to examples.
If the UTFT option is in your menu list, select it, then select arduino, and finally, UTFT_Demo_320x240. This will load the cool demo program.
With the program loaded in the IDE, scroll down to view the following code:
// Uncomment the next line for Arduino 2009/Uno
//UTFT myGLCD(ITDB32S,19,18,17,16); // Remember to change the model parameter to suit your display module!
// Uncomment the next line for Arduino Mega
UTFT myGLCD(ITDB32S,38,39,40,41); // Remember to change the model parameter to suit your display module!
Comment out the command for the UNO , and uncomment the command for the Mega ,as I did.
Now, go to the tools menu, click on board, and select Arduino Mega 2560 or Mega ADK , if not already selected.
Click on verify to compile the program. If there are no errors, click on upload to load and execute the program.
If everything is Ok, you will see a cool demo program running. Pictures in this step, show screenshots of the demo running.
http://www.instructables.com/id/Make-an-Oscilloscope-Using-the-SainSmart-Mega2560-/
http://www.instructables.com/id/Make-an-Oscilloscope-Using-the-SainSmart-Mega2560-/
Step 5:The software: UTouch library test.
Now we need to test the Utouch Library
Go to the files menu and select ; Examples>UTouch>Arduino>Utouch_ButtonTest and load the program to the IDE.
Verify and run the program.
You should see a keypad show up in the display, and, as you press the number keys, they should show up at the bottom of the screen.
If all went well, we are ready to load the Oscilloscope software.
Image Notes
1. press the buttons and you should see them at the bottom of the display
Step 6:The Oscilloscope
Below, you will find the sketch for the Oscilloscope. Before we copy and paste the program, let's review some limitations and explain the program.
I've had to do a fair amount of research to come up with the code, and many snippets have been "borrowed" from several sources.
I divided the program into several subrutines to make it easier to understand. The code is well documented, but, if you have trouble understanding it, leave a comment
and I'll try to explain it.
The Oscilloscope bandwidth is limited to about 1 khz, but there is room for improvement.
The input is limited to a 5volt peak to peak waveform, unless you use a voltage divider at the input, and also limited to positive waveforms from 0 to 5 volts.
I used some code I found at: http://www.microsmart.co.za/technical/2014/03/01/advanced-arduino-adc/ to adjust the ADC sample time.
The graphics and touch functions were modified, and borrowed, from the Henning Karlsen examples provided in his libraries.
I used a LM 317 voltage regulator, and a 555 IC timer as an astable ocillator, to create the signals used to test the oscilloscope input.
Hope you enjoyed reading and hopefully building this instructable. If you find it useful, please vote for me in the contests.
Copy and paste the sketch to your Arduino IDE
//----------------------START PROGRAM
http://www.instructables.com/id/Make-an-Oscilloscope-Using-the-SainSmart-Mega2560-/
/*--------------------------------------------------------------
Program: OscopetouchLCDmega
Description: Digital Oscilloscope with data displayed
on Color TFT LCD with touch screen
Hardware: sainsmart mega2560 board with 3.5" tft lcd touch module display and shield kit
http://www.sainsmart.com/home-page-view/sainsmart-mega2560-board-3-5-tft-lcd-module-display-shield-kit-for-atmel-atmega-avr-16au-atmega8u2.html
Software: Developed using Arduino 1.0.3 software
This program requires the UTFT library and the
UTouch library from Henning Karlsen.
web: http://www.henningkarlsen.com/electronics
Version 1.00
Date: 5 April 2014
Author: johnag
--------------------------------------------------------------*/
#include <UTFT.h>
#include <UTouch.h>
// Declare which fonts we will be using
extern uint8_t SmallFont[];
// Initialize Screen and touch functions
UTFT myGLCD(ITDB32S,38,39,40,41);
UTouch myTouch(6,5,4,3,2);
// Declare variables
char buf[12];
int x,y;
int Input = 0;
byte Sample[320];
byte OldSample[320];
int StartSample = 0;
int EndSample = 0;
int Max = 100;
int Min = 100;
int mode = 0;
int dTime = 1;
int tmode = 0;
int Trigger = 0;
int SampleSize = 0;
int SampleTime = 0;
int dgvh;
int hpos = 50; //set 0v on horizontal grid
int vsens = 4; // vertical sensitivity
// Define various ADC prescaler
const unsigned char PS_16 = (1 << ADPS2);
const unsigned char PS_32 = (1 << ADPS2) | (1 << ADPS0);
const unsigned char PS_64 = (1 << ADPS2) | (1 << ADPS1);
const unsigned char PS_128 = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);
//------------Start Subrutines------------------------------------
//--------draw buttons sub
void buttons(){
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect (250, 1, 310, 50);
myGLCD.fillRoundRect (250, 55, 310, 105);
myGLCD.fillRoundRect (250, 110, 310, 160);
myGLCD.fillRoundRect (250, 165, 310, 215);
}
//-------touchscreen position sub
void touch(){
while (myTouch.dataAvailable())
{
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
delay(500);
if ((y>=1) & (y<=50)) // Delay row
{
if ((x>=250) & (x<=300)) // Delay Button
waitForIt(250, 1, 310, 50);
mode= mode ++ ;
{
myGLCD.setColor(255, 0, 0);
myGLCD.drawRoundRect (250, 1, 310, 50);
// Select delay times
if (mode == 0) dTime = 0;
if (mode == 1) dTime = 1;
if (mode == 2) dTime = 2;
if (mode == 3) dTime = 5;
if (mode == 4) dTime = 10;
if (mode == 5) dTime = 20;
http://www.instructables.com/id/Make-an-Oscilloscope-Using-the-SainSmart-Mega2560-/
if (mode == 6) dTime = 30;
if (mode == 7) dTime = 50;
if (mode == 8) dTime = 100;
if (mode == 9) dTime = 200;
if (mode == 10) dTime = 500;
if (mode > 10) mode = 0;
}}
if ((y>=70) & (y<=120)) // Trigger row
{
if ((x>=250) & (x<=300)) // Trigger Button
waitForIt(250, 55, 310, 105);
tmode= tmode ++;
{
myGLCD.setColor(255, 0, 0);
// Select Software trigger value
myGLCD.drawRoundRect (250, 55, 310, 105);
if (tmode == 1) Trigger = 0;
if (tmode == 2) Trigger = 10;
if (tmode == 3) Trigger = 20;
if (tmode == 4) Trigger = 30;
if (tmode == 5) Trigger = 50;
if (tmode > 5)tmode = 0;
}}
if ((y>=130) & (y<=180)) // H position row
{
if ((x>=250) & (x<=300)) // H position Button
waitForIt(250, 110, 310, 160);
hpos= hpos ++;
{
myGLCD.setColor(255, 0, 0);
myGLCD.drawRoundRect (250, 110, 310, 160);
myGLCD.clrScr();
buttons();
if (hpos > 60)hpos = 50;
}}}}
//----------wait for touch sub
void waitForIt(int x1, int y1, int x2, int y2)
{
while (myTouch.dataAvailable())
myTouch.read();
}
//----------draw grid sub
void DrawGrid(){
myGLCD.setColor( 0, 200, 0);
for( dgvh = 0; dgvh < 5; dgvh ++){
myGLCD.drawLine( dgvh * 50, 0, dgvh * 50, 240);
myGLCD.drawLine( 0, dgvh * 50, 245 ,dgvh * 50);
}
myGLCD.drawLine( 245, 0, 245, 240);
myGLCD.drawLine( 0, 239, 245, 239);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (250, 1, 310, 50);
myGLCD.drawRoundRect (250, 55, 310, 105);
myGLCD.drawRoundRect (250, 110, 310, 160);
myGLCD.drawRoundRect (250, 165, 310, 215);
}
// ------ Wait for input to be greater than trigger sub
void trigger(){
while (Input < Trigger){ Input = analogRead(A0)*5/100;
}}
//---------------End Subrutines ----------------------
void setup() {
myGLCD.InitLCD();
myGLCD.clrScr();
myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
buttons();
pinMode(0, INPUT);
// set up the ADC
ADCSRA & ~PS_128; // remove bits set by Arduino library
// you can choose a prescaler from below.
// PS_16, PS_32, PS_64 or PS_128
ADCSRA |= PS_64; // set our own prescaler
}
http://www.instructables.com/id/Make-an-Oscilloscope-Using-the-SainSmart-Mega2560-/
void loop() {
while(1) {
DrawGrid();
touch();
trigger();
// Collect the analog data into an array
StartSample = micros();
for( int xpos = 0;
xpos < 240; xpos ++) { Sample[ xpos] = analogRead(A0)*5/102;
delayMicroseconds(dTime);
}
EndSample = micros();
// Display the collected analog data from array
for( int xpos = 0; xpos < 239;
xpos ++)
{
// Erase previous display
myGLCD.setColor( 0, 0, 0);
myGLCD.drawLine (xpos + 1, 255-OldSample[ xpos + 1]* vsens-hpos, xpos + 2, 255-OldSample[ xpos + 2]* vsens-hpos);
if (xpos == 0) myGLCD.drawLine (xpos + 1, 1, xpos + 1, 239);
// Draw the new data
myGLCD.setColor (255, 255, 255);
myGLCD.drawLine (xpos, 255-Sample[ xpos]* vsens-hpos, xpos + 1, 255-Sample[ xpos + 1]* vsens-hpos);
}
// Determine sample voltage peak to peak
Max = Sample[ 100];
Min = Sample[ 100];
for( int xpos = 0;
xpos < 240; xpos ++)
{
OldSample[ xpos] = Sample[ xpos];
if (Sample[ xpos] > Max) Max = Sample[ xpos];
if (Sample[ xpos] < Min) Min = Sample[ xpos];
}
// display the sample time, delay time and trigger level
myGLCD.setBackColor( 0, 0, 255);
myGLCD.setFont( SmallFont);
myGLCD.setBackColor( 0, 0, 255);
myGLCD.print("Delay", 260, 5);
myGLCD.print(" ", 270, 20);
myGLCD.print(itoa ( dTime, buf, 10), 270, 20);
myGLCD.print("Trig.", 260, 60);
myGLCD.print(" ", 270, 75);
myGLCD.print(itoa( Trigger, buf, 10), 270, 75);
myGLCD.print("H Pos.", 260, 120);
myGLCD.print( itoa( hpos, buf, 10), 270, 135);
//myGLCD.setBackColor( 0, 0, 0);
SampleTime =( EndSample-StartSample)/1000;
myGLCD.print("Sec.", 205, 210);
myGLCD.print(" ", 280, 30);
myGLCD.print(itoa( SampleTime, buf, 10), 205, 220);
// Range of 0 to 64 * 78 = 4992 mV
SampleSize =( Max-Min)*78;
myGLCD.print("mVolt", 5, 210);
myGLCD.print( itoa( SampleSize, buf, 10),5, 220);
myGLCD.print(itoa( analogRead(A0)*4.15/10.23, buf, 10),110 ,220);
}}
//-------------------------END PROGRAM
http://www.instructables.com/id/Make-an-Oscilloscope-Using-the-SainSmart-Mega2560-/
Step 7:Video of the Oscope in action
Step 8:Another video
Related Instructables
My Second
Project: Arduino
2.4" TFT by
Rookie P
Mini Arduino
environment
monitor **
UPDATE -
Added RTC ***
by johnag
Mini Arduino
Multi Function
Controller w/
LCD Display by
johnag
Make a Mini
Arduino
programmable 4
channel DC-
DVM by johnag
Moving My
Second Project:
2.4" TFT
Forward by
Rookie P
Mini Arduino
Portable EEG -
Brain Wave
Monitor + by
johnag
Advertisements
Comments
48 comments Add Comment
grumpyboots says: Apr 20, 2014. 5:52 PM REPLY
neato! thanks, maybe ill see what uses i can for this
johnag says: Apr 20, 2014. 7:02 PM REPLY
Cool grumpyboots.. thanks for sharimg!
http://www.instructables.com/id/Make-an-Oscilloscope-Using-the-SainSmart-Mega2560-/
rroque5 says: Jul 7, 2014. 2:39 PM REPLY
Is to do this using a nano aruino v3.0?
johnag says: Jul 8, 2014. 7:56 PM REPLY
I don't.think. so, sorry
rroque5 says: Jul 8, 2014. 8:56 PM REPLY
Thanks!
alejandroym93 says: May 13, 2014. 4:30 PM REPLY
Nice work! Only one thing, how did you solved the problem of the negative part of the signal when you plug in the function generator?
johnag says: May 13, 2014. 6:15 PM REPLY
check tis instructabel to giv you an idea:
How to make an Arduino
oscilloscope probe by
NeoRecasata
http://m.instructables.com/id/How-to-make-an-Arduino-oscilloscope-probe/
alejandroym93 says: May 14, 2014. 4:01 PM REPLY
indeed it graph most part of the signal with the probe, but it keeps cutting a minimum part of the signal.
johnag says: May 14, 2014. 5:00 PM REPLY
the signal needs to be "conditioned " to be between 0 and 5 volts before it is input into the arduino analog input. You may need to attenuate the
signal and float it on a dc voltage. Use two resistors in series connect one end to ground and the other to the 5 volt arduino pin, connect a
capacitor to the junction and to your function generator. Connect a jumper from the junction to the analog pin. This will float the waveform on a dc
of 2.5 volts. You can use two 1 meg resistors and a .47 micro farad capacitor. Remember the voltage. From your function generator has to be 5
volts peak to peak,if it is not, you. Will need to attenuate it using a potentiometer..
alejandroym93 says: May 16, 2014. 7:48 PM REPLY
thank you a lot man, it worked perfectly:)
johnag says: May 17, 2014. 4:44 PM REPLY
glad to help...click the I made it button and share a picture if you want...
johnag says: May 13, 2014. 5:40 PM REPLY
Use a voltage divider and a capacitor at the input.
Jan_Henrik says: May 1, 2014. 10:20 PM REPLY
Awesome project, I love it!!!
johnag says: May 7, 2014. 8:11 PM REPLY
thanks...you've got some awesome projects too!
Jan_Henrik says: May 8, 2014. 10:32 PM REPLY
Thank you! :)
Mr. E says: May 4, 2014. 1:34 PM REPLY
Nicely done ! Something every work bench should have.
http://www.instructables.com/id/Make-an-Oscilloscope-Using-the-SainSmart-Mega2560-/
johnag says: May 7, 2014. 7:47 AM REPLY
Thanks Mr. E, By the way, I tried your http://www.instructables.com/id/Donut-Protection-Device-Advanced-Arduino-Technique/ , another awesome
project, thanks for sharing
wisconsinjimmy says: May 2, 2014. 9:23 AM REPLY
OK I see where the pins go, from the PDF it did not show this and now looking at your design on the Instructables Interweb site I must have been off in well
thanks and sorry to have bothered you.
Jim
murfmv says: Apr 30, 2014. 9:12 AM REPLY
Johnag, Thought I was having trouble compiling because of different Arduino versions, but then realized where are the libraries after the include statement
and also problems cutting and IDE code. It's up and running and can't to test something. Always wanted an oscilloscope, now I have one and will be
following ur blog.
Great Job!!
johnag says: Apr 30, 2014. 10:47 AM REPLY
Glad you worked out the problem. Take a picture, and click on the I made it button! Have fun using it.
dustint2004 says: Apr 23, 2014. 8:05 PM REPLY
Sooo. If you have specific parameters already set.
Does PC still need to be connected to test or capture data?
johnag says: Apr 30, 2014. 10:44 AM REPLY
no it doesn't need to be connected to the PC, and you can vary some of the parameters with the touch screen buttons.
murfmv says: Apr 30, 2014. 7:14 AM REPLY
Hello Johnag,
Great thing I'm unable to compile your program in version 1.05 after running the TFT examples. I've gotten no errors, but suspect that might be the problem.
I'm certainly looking forward making this work!
30-06 says: Apr 21, 2014. 6:36 AM REPLY
Could this read from 10Hz to 20kHz?
johnag says: Apr 21, 2014. 7:46 AM REPLY
Probably not without an external ADC due to the limitations of the Arduino. But, the fundamentals of human voices are roughly in the range of 80 Hz to
1100 Hz, so you can use it to monitor voice patterns for stress and lie detection. The audio range of the human ear is from 20 hz to 20 khz which, I
presume, is what you want to monitor.
I haven't finished tweaking the code, so if I figure out a way to increase the bandwidth without additional hardware I will update the instructuble.
grumpyboots says: Apr 20, 2014. 6:02 PM REPLY
what would be the usable limits for this scope, without dividers and such I mean?
Volts peak to peak etc
freq?
johnag says: Apr 20, 2014. 7:30 PM REPLY
The Oscilloscope bandwidth is limited to about 1 khz
The input is limited to a 5volt peak to peak waveform, unless you use a voltage divider at the input, and also limited to positive waveforms from 0 to 5
volts.
you can build an oscillator with a 555 timer IC and watch square and triangle waves, or you you can use a thermistor with a resistor to see temperature
changes, or with a photo resistor to see light variations or just touch the probe and you should the a sine wave from the electrical power. at 60 hz if you
are in the states, 50 hz if you live in europe. have fun!!!
http://www.instructables.com/id/Make-an-Oscilloscope-Using-the-SainSmart-Mega2560-/
bob3030 says: Apr 17, 2014. 10:39 PM REPLY
Interesting thanks for posting.
johnag says: Apr 20, 2014. 5:28 PM REPLY
you're. Welcome
Treknology says: Apr 20, 2014. 3:12 PM REPLY
A very nice little project. I still use a 20MHz analog scope for most of my work, although if working in lower frequency ranges, your project would save
considerable electricity.
I'm actually proposing a reverse project. I have some old 6" (maybe only 4") black & white TVs that are useless in the digital age (the don't even have
composite inputs). As many people with CROs who don't know how to use them properly and ultimately end up wasting them by attaching them to the
stereo, I'm going to convert these TVs into "sloppy" CROs for just that purpose!
johnag says: Apr 20, 2014. 5:26 PM REPLY
thanks, and good luck with your projects, if you do make them, share them I'd lik to see them.
dirty_valentine says: Apr 20, 2014. 6:52 AM REPLY
Nice project. I think your scope could really use an adjustable trigger so that the waveform is not jumping all over the screen. A good trigger is hard to design
though. Ideally you would use an interrupt input to trigger sampling, but that would require an external comparator an reference. The next best way would be
to sample at the highest rate and do a compare to detect the threshold crossing. Then start sampling at the scope rate. Don't change the avr sample rate,
just drop the samples you don't need. This will probably work for slow moving input signals, but will fall apart as you approach the avr sampling rate.
johnag says: Apr 20, 2014. 5:24 PM REPLY
the scope has a software trigger, but you're right maybe I'll. try some thing like what you suggest, but my proggramimg skills aren't that great.
alzie says: Apr 20, 2014. 8:06 AM REPLY
Scool project!
Its tough making a good scope.
Also, check out:
http://www.seeedstudio.com/depot/DSO-Nano-v3-p-135...
I have their V2 nano scope.
Works well, i love it, is portable, and
is isolated from the AC line for power measurements.
johnag says: Apr 20, 2014. 5:20 PM REPLY
Yea, there are some pretty cool oscopes sainsmart has some too, and they cost less than 100. One that caught. My attemtion and it cost only 50$
ismtheXMEGA XProtolab
It fits in your breadboard and is multu functional. Check it out here:
harleyrogengineer says: Apr 19, 2014. 9:43 AM REPLY
There is a due kit version available from sainsmart...would this work and be faster??
Just wondering?
Otherwise i'll be building this Very soon! Excellent instructable Sir!
johnag says: Apr 20, 2014. 5:12 PM REPLY
I was reading about the due in http://arduino.cc/en/Main/arduinoBoardDue
This paragraph caught. My attention.
Before you buy the kit make sure it will work for you.
Warning: Unlike other Arduino boards, the Arduino Due board runs at
3.3V. The maximum voltage that the I/O pins can tolerate is 3.3V.
Providing higher voltages, like 5V to an I/O pin could damage the
http://www.instructables.com/id/Make-an-Oscilloscope-Using-the-SainSmart-Mega2560-/
board.
johnag says: Apr 19, 2014. 11:07 PM REPLY
I haven't tried it because I don"t have a due, but I don't see why it wouldn't. Work. The due, however, has a much higher clock speed and the ADC is 12
bits. You might have to play with the sketch a little to make it work.
carlos66ba says: Apr 11, 2014. 3:16 PM REPLY
Very cool! What is the maximum speed it can capture?
nqtronix says: Apr 16, 2014. 3:29 AM REPLY
An atmega2560 is the core of this "ocilloscope". The ADC (Analog to Digital Converter, just in case you're wondering) supports up to 76.9kSPS (Samples
Per Second). However I doubt that this speed can be archieved. If the atmega wpuld run at its maximum speed of 20Mhz roughly 260 operations could
be done to store, calculate and display each value. Plus the controller has to manage all inputs (touchscreen).
The maximum frequency of a signal (bandwith) an ocilloscope can measure acurate enough for practical purposes is roughly 10% of the sampling rate,
thus a bandwith of roughly 8khz can be expected, at best (!). Even for "home purposes" this thing is partical unsusable. This thing is simply not made to
be an ocilloscope.
Don't get me wrong, beside the functionality of this "ocilloscope" the project isn't bad at all and I'm sure you learnt much during the process. And if you
decide anytime to buy a proper ocilloscope (they start @ ~200, for 535 you get the cheapest 4 channel scope, the rigol1052Z) you can still reuse this
project and just slam other code on to turn it into something new :)
johnag says: Apr 16, 2014. 8:10 AM REPLY
The AVR ADC has a recommended clock speed of between 50 kHz and 200 kHz when 10 bit resolution is desired. This is 50,000 to 200,000 cycles
per second. Any faster and the resolution will start to degrade. There is a prescaler to control the ADC clock. This means that it is prescaled down by
some factor from the core clock speed.
To set the prescaling, the ADPS bits (2..0) in the ADCSRA register are set. Prescaler values of 2, 4, 8, 16, 32, 64 & 128 are provided. A typical core
clock speed is 16 MHz, although the core can run up to 20 MHz. So if you are running your Arduino or other AVR board at 16Mhz, you can set the
ADC clock to one of the following values:
16 MHz / 2 = 8 MHz
16 MHz / 4 = 4 MHz
16 MHz / 8 = 2 MHz
16 MHz / 16 = 1 MHz
16 MHz / 32 = 500 kHz
16 MHz / 64 = 250 kHz
16 MHz / 128 = 125 kHz
Since the ADC clock needs to be between 50 kHz & 200 kHz for 10 bit accuracy, we can only use the 128 prescaler and can achieve a 125 kHz ADC
clock. If our core was at 20 Mhz and we use the 128 prescaler our ADC would be running at about 156 kHz.
To achieve a higher ADC clock, we could slow down the core. A core running at 12 Mhz with a prescaler of 64 will achieve an ADC clock of around
187 kHz. These are the tradeoffs we make when designing a system.
A normal conversion in the ADC takes 13 ADC clock cycles. The first conversion takes 25 clock cycles. So our ADC clock speed needs to be
factored down by 13 to figure out how many samples we will be able to achieve per second.
You can run the ADC in parallel mode using the PINC command and capture the data from a front end ADC chip to achieve a bandwidth of more
than 200khz. Granted it's no industrial oscilloscope, but as I mentioned, its for hobby use and you can view many waveforms that you could
otherwise not see, like the charging of a capacitor, etc...
Like you mention, it is programable, and you can reuse the hardware for many other projects. something you can't do with a dedicated oscilloscope
nqtronix says: Apr 16, 2014. 8:51 AM REPLY
In the official datasheet for the atmega2560 (here: http://www.atmel.com/Images/Atmel-2549-8-bit-AVR-M... ) in chapter 26 page 268 the
maximum speed of the ADC is defined as "up to 76.9kSPS (Up to 15kSPS at Maximum Resolution)". Near all low to mid range ocilloscopes use
only 8 bit resolution, I calculated with the maximum sampling rate. Sure, you can run the whole thing out of specefication, but the precision will
decrease. I honestly didn't knew the avr chip series support parallel mode of the ADCs, but that sounds like a huge improvement to me.
So, if you don't mind, I'd like to see a "real waveform" displayed, that should make things clearer. I don't think you own a funktion generator so
what about generating 20khz sine with the soundcard of your computer? I'd offer a video proof of the 1074Z as comparison (yeah, I know, pretty
unfair, but still).
johnag says: Apr 16, 2014. 9:53 AM REPLY
The CA3306 Flash analog to digital converter can be used as a front end ADC to increase the bandwidth to 5MHZ you would need to modify
the sketch to read the ADCoutput in parallel. The resolution will be 6 bits. but, this will add cost and complexity to the project. I wanted to keep
the instructable as simple and low cost as possible.
http://www.instructables.com/id/Make-an-Oscilloscope-Using-the-SainSmart-Mega2560-/
nqtronix says: Apr 16, 2014. 10:10 AM REPLY
Sure you can add additional parts to increase the spec in any way, but that was not what carlos66ba had asked for. I just wanted to point
out the limitations of the current design without going too far into the details.
carlos66ba says: Apr 18, 2014. 3:19 AM REPLY
Thanks for the detailed answers! I think that for a scope, 8 bit suffices so you can probably bump the clock a bit higher than the
recommended specs.
johnag says: Apr 16, 2014. 12:12 PM REPLY
well, in that case, the maximum bandwidth is about 1Khz, as mentioned in the Instructable. carlos66ba I hope this clarifies your
question. Thanks for your comments nqtronix it's always good to have some feedback .
nqtronix says: Apr 16, 2014. 4:05 AM REPLY
Well, 2 small corrections:
1. The atmega2560 runs at 16Mhz max, that would result in only 208 operations.
2. I meant the rigol 1074Z...
What a shame instructables doesn't support editing of comments...
mrandle says: Apr 12, 2014. 11:15 AM REPLY
the kit comes with an arduino mega and its only 40 bucks! Sweet deal!

You might also like