Introduction: Oscilloscope! THE EASY WAY! DIY

About: Hey YOU! Yeah, I'm talking to you who is reading this. Send me ideas for instructables, like things that you are wondering how to make or build, or really anything electronically related, and I'll get back to …

Oscilloscopes are all so EXPENSIVE! So one day, December 4, 2011, I was thinking of something to do because I was bored and had done all of my schoolwork. I decided, because I have been wanting an Oscope (Oscilloscope) for a year now, but my parents never got around to buying me one, I just made one! With that said, being only 14 in 8th grade, I do not make much of an allowance, if not any. I thought that maybe sharing this with the world would be helpful for those, like me, do not either make much money or have a tough budget. Although I may have a simple Oscope, it does the job. Please read all of the instructions first.

Step 1: Supplies

There are not many supplies needed to build this Oscope, but you will need the following: an Arduino (any kind will work), a computer (just to program one thing and to see your Oscope, you will not need to use it for this project forever), and two jumper cables.

Step 2: Setting Up Arduino

All you need is you need out is your Arduino and your computer on both processing, and Arduino IDE. You can find these programs at processing.org and at arduino.cc. Plug your Arduino in and get ready to program! Use your two jumper cables by plugging one into RX and the other into GND on your Arduino. You will use these to make your Oscope work!

Step 3: Programming Processing

THIS IS THE PROCESSING PROGRAM! YOU WILL ALSO NEED TO ADD THE FONT TO THE DATA FOLDER THING... To add the font you go to Sketch -> Add File... -> then add my attached font.

/*
* Oscilloscope
* Gives a visual rendering of analog pin 0 in realtime.
*
*
* (c) 2011 "simonfrfr" (newtonlabs@bellsouth.net)
*/

import processing.serial.*;

color currentcolor;
boolean locked = false;
boolean Herr = false;
boolean serialt = false;
CircleButton circle1, circle2, circle3;
Serial port;  // Create object from Serial class
int val;      // Data received from the serial port
int[] values;
float zoom;
PFont fontA;

void setup()
{
  fontA = loadFont("Ziggurat-HTF-Black-32.vlw");
  textFont(fontA, 32);

  // Only draw once
  //noLoop();
  size(1280, 480);

  color buttoncolor = color(153);
  color highlight = color(102);
  ellipseMode(CENTER);
  circle3 = new CircleButton(50, 50, 50, buttoncolor, highlight);
  circle2 = new CircleButton(50, 50, 50, buttoncolor, highlight);
  circle1 = new CircleButton(50, 50, 50, buttoncolor, highlight);
  // Open the port that the board is connected to and use the same speed (9600 bps)
  port = new Serial(this, Serial.list()[0], 9600);
  values = new int[width];
  zoom = 1.0f;
  smooth();
}

int getY(int val) {
  return (int)(height - val / 1023.0f * (height - 1));
}

int getValue() {
  int value = -1;
  while (port.available() >= 3) {
    if (port.read() == 0xff) {
      value = (port.read() << 8) | (port.read());
    }
  }
  return value;
}

void pushValue(int value) {
  for (int i=0; i<width-1; i++)
    values[i] = values[i+1];
  values[width-1] = value;
}

void drawLines() {
  stroke(255);

  int displayWidth = (int) (width / zoom);

  int k = values.length - displayWidth;

  int x0 = 0;
  int y0 = getY(values[k]);
  for (int i=1; i<displayWidth; i++) {
    k++;
    int x1 = (int) (i * (width-1) / (displayWidth-1));
    int y1 = getY(values[k]);
    line(x0, y0, x1, y1);
    x0 = x1;
    y0 = y1;
  }
}

void drawGrid() {
  stroke(255, 255, 255);
  line(0, height/2, width, height/2);
  line(0, height/2+1, width, height/2+1);
  line(0, height/2+2, width, height/2+2);
  line(0, height/2+3, width, height/2+3);
  line(0, height/2+4, width, height/2+4);
  line(0, height/2+5, width, height/2+5);
}

void keyReleased() {
  switch (key) {
    case '+':
      zoom *= 2.0f;
      println(zoom);
      if ( (int) (width / zoom) <= 1 )
        zoom /= 2.0f;
      break;
    case '-':
      zoom /= 2.0f;
      if (zoom < 1.0f)
        zoom *= 2.0f;
      break;
  }
}

void draw()
{
  serialcheck();
  if (serialt == true) {
  if (Herr != false) {
  background(19, 134, 209);
  fill(255);
  text("- zoom out", 100, 60);
  text("+ zoom in", 100, 95);
  update(mouseX, mouseY);
  //circle1.display();
  //circle2.display();
  circle3.display();
  drawGrid();
  val = getValue();
  if (val != -1) {
    pushValue(val);
  }
  drawLines();
  }
  else {
        fill(42, 88, 87);
        rect(0, 0, 1280, 480);
        circle3.display();
        update(mouseX, mouseY);
  }
  }
     else {
  background(0);
  fill(255);
  text("SORRY, THE CONNECTION HAS BEEN LOST, ", 100, 60);
  text("ATTEMPTING TO CONNECT TO SERIAL PORT.", 100, 95);
  text("IF YOU RECONNECT YOUR SERIAL PORT AND THIS", 100, 130);
  text("MESSAGE DOES NOT GO AWAY THEN EXIT THE ", 100, 165);
  text("PROGRAM AND REOPEN IT AND IT WILL WORK,", 100, 200);
  text("OTHERWISE IT ISA PROBLEM WITH YOUR HARDWARE", 100, 235);
  text("OR YOUR PROGRAMMING.", 100, 280);
}
}

void serialcheck()
{
  delay(12);
  if (port.available() >= 1) {
    serialt = true;
  }
   else {
     serialt = false;
}
}

void update(int x, int y)
{
  if(locked == false) {
  //  circle1.update();
  //  circle2.update();
    circle3.update();
   // rect1.update();
  //  rect2.update();
  }
  else {
    locked = false;
  }

  if(mousePressed) {
    if(circle1.pressed()) {
      currentcolor = circle1.basecolor;
    }
    else if(circle2.pressed()) {
      currentcolor = circle2.basecolor;
    }
    else if(circle3.pressed()) {
      if (Herr == true) {
        Herr = false;
      }
            else {
        Herr = true;
      }
    }
  }
}


class Button
{
  int x, y;
  int size;
  color basecolor, highlightcolor;
  color currentcolor;
  boolean over = false;
  boolean pressed = false;  

  void update()
  {
    if(over()) {
      currentcolor = highlightcolor;
    }
    else {
      currentcolor = basecolor;
    }
  }

  boolean pressed()
  {
    if(over) {
      locked = true;
      return true;
    }
    else {
      locked = false;
      return false;
    }   
  }

  boolean over()
  {
    return true;
  }

  boolean overRect(int x, int y, int width, int height)
  {
    if (mouseX >= x && mouseX <= x+width &&
      mouseY >= y && mouseY <= y+height) {
      return true;
    }
    else {
      return false;
    }
  }

  boolean overCircle(int x, int y, int diameter)
  {
    float disX = x - mouseX;
    float disY = y - mouseY;
    if(sqrt(sq(disX) + sq(disY)) < diameter/2 ) {
      return true;
    }
    else {
      return false;
    }
  }

}

class CircleButton extends Button
{
  CircleButton(int ix, int iy, int isize, color icolor, color ihighlight)
  {
    x = ix;
    y = iy;
    size = isize;
    basecolor = icolor;
    highlightcolor = ihighlight;
    currentcolor = basecolor;
  }

  boolean over()
  {
    if( overCircle(x, y, size) ) {
      over = true;
      return true;
    }
    else {
      over = false;
      return false;
    }
  }

  void display()
  {
    stroke(255);
    fill(currentcolor);
    ellipse(x, y, size, size);
  }
}

class RectButton extends Button
{
  RectButton(int ix, int iy, int isize, color icolor, color ihighlight)
  {
    x = ix;
    y = iy;
    size = isize;
    basecolor = icolor;
    highlightcolor = ihighlight;
    currentcolor = basecolor;
  }

  boolean over()
  {
    if( overRect(x, y, size, size) ) {
      over = true;
      return true;
    }
    else {
      over = false;
      return false;
    }
  }

  void display()
  {
    stroke(255);
    fill(currentcolor);
    rect(x, y, size, size);
  }
}

Step 4: Programming Arduino

Super short code, just to make it simple. Just copy paste this code.

#define ANALOG_IN 0

void setup() {
  Serial.begin(9600);
}

void loop() {
  int val = analogRead(ANALOG_IN);
  Serial.print( 0xff, BYTE);
  Serial.print( (val >> 8) & 0xff, BYTE);
  Serial.print( val & 0xff, BYTE);
}

Step 5: Running the Code.

Since I have made this as simple as possible, all you have to do now is go to the page you pasted my processing code and press Sketch then press Run. it should pop up eventually and it will be a blue screen with a grey button, click the button to turn it on (WARNING: THE BUTTON IS SOMETIMES GLITCHES) after that you should have a working Oscope. If the error message pops up then you probably have a hardware problem, or possibly you didn't program the Arduino, or you might not have it connected.



                                                                                                                    ENJOY!                                                                                                                                                                                                    


                             CREATOR: simonfrfr BUILDER: simonfrfr Photographer: simonfrfr PROGRAMMER: simonfrfr                                                                               

Hack It! Challenge

Participated in the
Hack It! Challenge

ShopBot Challenge

Participated in the
ShopBot Challenge

The Mad Science Fair

Participated in the
The Mad Science Fair