Oscilloscope! THE EASY WAY! DIY

60,884

76

27

Published

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 t...

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                                                                               

Share

Recommendations

  • Water Contest

    Water Contest
  • Oil Contest

    Oil Contest
  • Creative Misuse Contest

    Creative Misuse Contest

27 Discussions

You put a Processing Sketch (A different program than Arduino) in the Arduino IDE. to download the software for that program, visit: processing.org

What is the voltage range this project can read? Can it read negative as well?

hey it gives an error message saying "Could not load font Zigguart-HTF-Black-32.vlw" even if i have placed it in the data folder of my sketch.......please tell me how to fix it

1 reply

Hi, I hope that with 1 year time problem of error "Could not load font Zigguart-HTF-Black-32.vlw" is solved?

I'm using Mac with OSX 10.10. and have the same problem.

Very nice project.

Please kindly help,

toksaj@gmail.com

load_font error.tiff

excellent job! but I have some questions to ask you.What's are circle1,circle2 and circle3 used for ? I can see you only displays circle3 so is it the button?,however,when i tried to display circle1 and circle2.I found no any other thing appeared and when i pressed the button,the oscolloscope didn't show the wave

this is a very interesting project and you did a great job, the only thing that could make it better was a technical explanation of how o'scopes work for the people that do not understand how they do their little magic, and some more comments within the code. i think you did a great job though, and its quite ingenious for a 14yo, though your 16 now, so I'm sure you've moved on to new exciting things and don't care about this any longer, which is understandable.

1 reply

The way an Oscilloscope works is actually an internal ADC's (Analog to Digital Converter) output is used to determine the voltage. The reading works like this: Voltage over Time. Which is how the program on Processing works.

This looks fantastic and I'm really excited for the next version of this you've mentioned you're working on - can't wait! I'm a hobbyist working on mostly analogue synth electronics, so I don't need a $300 (second hand) o'scope. It's a good excuse for me to clutter my house more and get into Arduino too!

Sorry the connection was lost....... But I did everything right. Don't Know what I'm doing wrong :(

1 reply

This oscilloscope is far from being perfect, but the beauty - not to say the ingenuity - is in its simplicity.
(I had some small electronical problems and was thinking about buying an oscilloscope just to find the bug. With the help of this instructable it was very easy to find the bug.)
The casing for my 'ArduScope' is an empty matchbox and it will be a permanent help in my toolbox.
Thank you!

1 reply

this code isnt compatible with arduino 1.0, it would be great if you can update it.
"As of Arduino 1.0, the 'BYTE' keyword is no longer supported.
Please use Serial.write() instead."
this is the error

2 replies