Arduino‎ > ‎Brewing Arduino‎ > ‎

Using Arduino as Oscilloscope - ArduinoScope!

posted Nov 27, 2010, 1:31 AM by Haris Hashim   [ updated Nov 27, 2010, 4:19 AM ]



Introduction


A good friend one time debug circuit and at the same time demo a scope done using Arduino. Interesting stuff! You can visit his blog Arduino For Beginners and get lots of information about Arduino!

Only until today I did give Arduino scope a try. Found that it is PITA to get started due to lack of clear cut documentation. But don't take me wrong. It is fantastic once it get running.

Highly recommended for every home brewers. A multimeter is good to certain extent. It has it advantages. But showing a value in graph form. Current value as well as past value, is not one of them. Having a real oscilloscope easily set us grand amount of dollars. And by that I mean US dollars and not Malaysia dollars (no such thing as Malaysia dollars anyway!).

Anyway, a little bit of background. For those who are already familiar with Arduino. Do you guys know that Arduino is actually based on a platform called Processing? Read wikipedia entry for more info about Processing. In fact running Processing IDE will cause this response of ... "Whoa processing looks like Arduino!". In fact it is the other way around. Arduino looks like processing. Make sense because Arduino is based on processing.

Arduino scope make use of both Arduino and Processing. We will upload a sketch to Arduino board. This cause the board to read voltage value from analog I/0 pin and send it back to PC using serial communication.

On the PC side. We will open up Processing and run a sketch (note that Processing also call it sketch, same as Arduino. Or rather Arduino is using terminology carried over from Processing). The sketch run on PC, listen to the first serial port to accept voltage reading and display it graphically.

That's it in a nutshell. So let see how to set it up.

Tutorial


Step 1


I am assuming that you guys already have Arduino installed :D but no Processing. So head over and download processing.

Extract the downloaded zip file to somewhere convenient. In my case,it is "d:\app\processing".

Run the program. For instance "d:\App\processing-1.2.1\processing.exe".

Upon first run, it will create a folder in user document folder named "Processing". User document folder is "My Documents" folder. You get the drift.

Need to know this "Processing" folder for next step.

Step 2


Just like Arduino (or the other way around, Arduino is like Processing). Processing make use of libraries to make our live easier. Arduinoscope itself is a library. It make use of another library called ControlP5. Which provide graphical UI element for user interface. Need to download it so head to ControlP5 web page and download it

Extract the downloaded zip file into "libraries" folder in "[My Documents]\Processing". Location of [My Documents]\Processing folder is as mentioned in previous step. Make sure that you have "[My Documents]\Processing\libraries\controlP5" folder after executing this step.

Step 3

As mentioned above, Arduinoscope itself is a library. We need to download it too! This is the mind boggling part. But first just head to Arduinoscope usage page.

The page give 2 links for the processing lib and the arduino patchThe first link download the library it self. We will look at the other link in next step.

Anyway, please download the library from Arduinoscope page to get the latest version. After download is complete extract contents to  "[My Documents]\Processing\libraries\arduinoscope". Folder name must be "arduinoscope". This is important, otherwise won't work!

Common pitfall here (and I did this!) is to name the folder following zip file name. Which is "processing-arduinoscope". Won't work!.

Another common pitfall (and I did this too!) is to copy the library to Arduino library folder. Remember that this is processing library and not Arduino library. It will obviously not work. Plus upon starting Arduino IDE. It will complain about library having name with not allowed character until the offending library is deleted or moved somewhere else.

Step 4

Now we need to download the Arduino sketch or called Arduino patch in previous step. Remember that Arduinoscope use both processing Arduino. In this step download the Arduino patch. Basically it is a pde file with exact file name of "arduino-arduinoscope.pde". At the time of writing, the second link for the arduino patch does not work (hint: spelling error involving dash and underscore).

Here is the link that works "arduino-arduinoscope.pde". In the future, might be agood idea to download from Arduinoscope page. In case it is updated or the above error is corrected.

Here is another mind boggling part. What the hell should we do with this file?

First, I would advice to rename the file to "arduinoscope.pde" for no rational reason. Just for kicks ;D

Create a folder named "arduinoscope" in Arduino sketch folder and copy the sketch there. Arduino sketch folder is located in "[My Documents]\Arduino\sketch".

Now it is time to run our beloved Arduino IDE. Then open up the sketch from menu File>Sketchbook>sketch>arduinoscope. Upload this sketch to Arduino compatible board.

Which bring us to another pitfall! The pitfall of not having same name for folder and sketch file. If the file name is "arduinoscope.pde". The folder name must be "arduinoscope". Otherwise won't see the sketch in File>Sketchbook>sketch menu. Apparently can still browse and open using File>Open menu.

At the end of this very long step. Make sure that you have an Arduino board (Duemilanove or Uno or any compatible board) uploaded with the Arduino patch. This board will run and continuously send analog voltage reading to the PC using USB. This reading is going to be read in next step.

Step 5

Back to processing IDE. In the IDE we are going to open up the sketch that is responsible for reading the serial value from first found com port. This value came from Arduino board as described in last step. The sketch will show a graph as what we expect from an oscilloscope.

So where can we find that sketch? One concept learned from last step is that. Sketch file located in sketch folder and is conveniently accessible from  File>Sketchbook>sketch. In the case of processing, this will be "[My Documents]\Processing\sketch".

Another concept that is not immediately clear is that libraries can provide example sketch! Check it out by browsing to "arduinoscope" library folder. Inside that folder there is an "examples" folder with sketches inside. This example sketch is accessible from menu File>Sketchbook>libraries>arduinoscope>examples.

Phew! that is a long one.

So go ahead and open up a sample sketch by doing File>Sketchbook>libraries>arduinoscope>examples>SimpleSerialArduinoscope.

Before running the sketch. Note that in Processing, there is only run button but no upload button. Processing runs sketch in the PC. As opposed to Arduino, which run sketch on a remote Arduino board. Hence the upload button for Arduino and no such button in processing.

Run the sketch! This will open up another window with graphical oscilloscope interface.

Step 6

We have a sketch on the PC showing oscilloscope. On the other end we have Arduino board running. So how do we test?

What happening is that the Arduino board is sampling voltage value on analog I/O pin 1 to 6 in a loop. Since at the moment, nothing is connected to  the pins. The values are sort of zero with a little bit of background noise.

To test, connect 5V pin to analog I/O pin 1. Immediately our Arduinoscope running in PC will show readings in the area of 5v. Disconnect 5V pin and connect it to 3v3 pin. This will cause reading to drop down to 3V3 level.

Weird Stuff

Display on PC show 6 readings possibly for the 6 channel of analog I/O pin. Let say 5V is connected to analog I/O pin 1. All 6 readings show a decreasing value of 5V. Perhaps there is a bug somewhere.

Will try to connect 5V to analog I/O pin 1, 3V3 to analog I/O pin 2 and see what is going on.












Comments