Girino - Fast Arduino Oscilloscope

 by Caffeinomane
Featured
Girino.png
I am a Physicist and the nicest part of working in this field is that I get to build my own instruments. With this way of thinking, I decided to build a homebrew Arduino Oscilloscope. This instructable was written with the purpose of teaching a bit about microcontrollers and data acquisition. This is an extreme project because I wanted to squeeze out from Arduino as much velocity as I could, I have not seen any other Arduino Oscilloscope as fast as this one.

Some time ago I was working on an Arduino project and I needed to see if the output signal was into compliance with the specifics. Thus I spent some time on the internet looking for Arduino Oscilloscopes already implemented, but I did not like what I found. The projects that I found were mostly composed of a Graphical User Interface for the computer written in Processing and a very simple arduino sketch. The sketches were something like:
void setup() {
    Serial.begin(9600);
}

void loop() {
    int val = analogRead(ANALOG_IN);
    Serial.println(val);
}
This approach is not wrong and I do not want to insult anyone, but this is too slow for me. The serial port is slow and sending every result of an analogRead() through it is a bottleneck.

I have been studying Waveform Digitizers for some time and I know reasonably well how do they work, so I got inspiration from them. These were the starting points of the oscilloscope that I wanted to create:
  • the incoming signal should be decoupled from the arduino to preserve it;
  • with an offset of the signal it is possible to see negative signals;
  • the data should be buffered;
  • a hardware trigger is required to catch the signals;
  • a circular buffer can give the signal shape prior to the trigger (more to follow on this point);
  • using lower lever functions that the standard ones makes the program run faster.

The sketch for the Arduino is attached to this step, along with the schematic of the circuit that I made.

The name that I came up with, Girino, is a frivolous pun in Italian. Giro means rotation and adding the suffix -ino you get a small rotation, but Girino also means tadpole. This way I got a name and a mascot.
 
Remove these adsRemove these ads by Signing Up

Step 1: Disclaimer

Warning.png
THE AUTHOR OF THIS INSTRUCTABLE MAKES NO GUARANTEE OF VALIDITY AND NO WARRANTY WHATSOEVER.

Electronics can be dangerous if you do not know what you are doing and the author cannot guarantee the validity of the information found here. This is not a professional advice and anything written in this instructable can be inaccurate, misleading, dangerous or wrong. Do not rely upon any information found here without independent verification.

It is up to you to verify any information and to double check that you are not exposing yourself, or anyone, to any harm or exposing anything to any damage; I take no responsibility. You have to follow by yourself the proper safety precautions, if you want to reproduce this project.

Use this guide at your own risk!
ivansouza says: May 13, 2013. 9:13 PM
Nice Work!!! Maybe this could help you in this great project... http://www.linuxtoys.org/pscope/pscope.html
BashOnABike says: Apr 25, 2013. 3:36 PM
Also, I had to remove the HardwareSerial namespaces in Interface.cpp & Girino.h to get the sketch to compile. Did anyone else run into this issue?

I quickly skimmed HardwareSerial.h and saw no usage of said namespace.  Maybe versioning issue?

This thread seems kinda dead, so I may be speaking to an empty room...
BashOnABike says: Apr 13, 2013. 10:54 PM
Wow, excellently well explained Christiano--I feel I've already learned so much just reading through this in the library, and I haven't even started building! It really ties together the material I'm learning in EE, in a tangible & actionable manner. Keep up the good work!
dinoi says: Apr 11, 2013. 12:54 AM
Great work, but I have troubles to get it run. Could you please explain the Hardware mapping on your schematic:

ADC:1 is Analog 0 on Arduino,
PWM:1 is Analog3

but where to go with AnalogComparator:1 and Threshold:1?

Thanks a lot
Dinoi
hemalchevli says: Feb 6, 2013. 3:41 AM
I did something similar, I sent out sensor values to serial port in csv formate, I used GTK term, and logged the data in a file, that file was read at the same time by KST (an awesome plotting software) to plot the data. It has a good gui and many other options, I'm trying to make a plugin for kst that will make this process simple.
Nanico says: Jan 30, 2013. 5:58 AM
Can you explain how to use dual channel? What is the best way to switch from 1 ch to other
Caffeinomane (author) in reply to NanicoFeb 3, 2013. 11:40 PM
Well if you want to use two channels at the same time the acquisition rate will go down, probably more than a factor of 2.
Given that the Arduino has only one ADC you must alternatively feed to the ADC your signals. This means that you have to use the multiplexer (see step 8). At each iteration you have to:
- Read Ch 1 with the ADC
- Switch to Ch 2
- Read Ch 2
- Switch back to Ch 1
Plus doubling the number of channels you halve the amount of available memory, because you have to store two numbers at each iteration.
konsumer says: Jan 28, 2013. 8:52 AM
Very informative. I am the maker of arduinoscope, which is one of the Processing scopes you mentioned. Although, the original goal of that project was to make it extremely accessible to non-tech people (I used it for teaching electronics and hardware hacking.) I think we could add some of these features to that project (especially the Arduino firmware.) I don't really like Processing (or java, which arduinoscope is written in) and would be happy to switch to something else, if it could remain fairly easy for a non-programmer/electronics newb to get their hands on and modify. I started work on node.js to make a simple GUI, but Python also seems like a good candidate. I have moved the simple serial Arduino backend (sort of similar to the code pointed out, but you are exaggerating a bit, at least in my case) to use Firmata, to get myself out of the business of maintaining the firmware, and introduce new users to the awesome Firmata library. I'd be happy to move to a more performant Arduino firmware, especially if you want to maintain that part, and offer your Girino as a "fancy" version, in terms of hardware. Do you have speed stats? How much of this can be done without adding custom hardware, so people can do it all in soft/firmware?
Caffeinomane (author) in reply to konsumerJan 28, 2013. 9:22 AM
Thank you for your offer! Right now I am in the middle of the writing of a thesis, so I can not dedicate time on this project. When I am done with this thesis I will surely contact you to start this collaboration.
konsumer in reply to CaffeinomaneJan 28, 2013. 10:14 AM
sweet!
MGreatwolf says: Jan 22, 2013. 6:52 PM
I am somewhat new to this so forgive the question. I was reviewing your code and found the following line in it:
ADMUX |= ( ADCPIN & 0x07 );
unfortunately I am unable to locate ADCPIN in the datasheet or any of the source files provided by the Arduino developers. I like your solution and would like to dig into it a little deeper. Could you please provide some additional detail regarding ADCPIN? What it refers to and so on...Thanks for what appears to be a lot of work documenting this instructable.
Caffeinomane (author) in reply to MGreatwolfJan 23, 2013. 12:57 AM
Do not worry. If you look at the header file Girino.h you can see the definition:
#define ADCPIN 0
It refers to the ADC pin number that I used for the data acquisition.
aspify says: Dec 9, 2012. 10:06 PM
is the source code done in the arduino sketch editor or was it done in C++ code on another compiler? Just curious...thanks
Caffeinomane (author) in reply to aspifyDec 10, 2012. 9:24 AM
Well I usually code with VIM so I basically wrote the code with VIM and then opened and compiled it with the arduino IDE.
a.flux says: Nov 26, 2012. 3:48 AM
Thank you very much for this project! That's exactly what I was looking for. I think I will write the Qt/Qwt interface as soon as I'm done with the soldering.

Any recent update to the schemes?

a.f
Caffeinomane (author) in reply to a.fluxNov 26, 2012. 4:10 AM
Thank you!

No, there have not been any updates so far. I was planning to work more on this project, but some work problem denied that and are still denying.

I am still considering the idea of putting this project somewhere like Sourceforge.
Nanico says: Sep 3, 2012. 3:42 PM
Great work Caffeinomane!!! I love your project.
Can I use a LCD T6963c and use with girino? I have one and it run at 6 Mhz, and i want to make your project portable. Can you help me with the code for that? My ideia is to have 2 channel, but not every time.
Thank you
privatier says: Aug 12, 2012. 9:05 PM
For an alternative implementation of an oscilloscope, which uses an Arduino for data acquisition, please have a look at LXARDOSCOPE, available from Sourceforge. There is also a section on an investigation into the accuracy of the ADC; it includes schematics for a preamplifier which works from the same 5V supply as the Arduino.
Redsic says: Aug 1, 2012. 4:59 AM
Hello

This scope is great, my question though is…
This Oscilloscope is only able to read 0 -5v ? Is there anyway to Increase this ?
I know adding a resistor can make this go up to like 0-48+volts but reduces it's accuracy.

This beats the other Arduino scopes I tried hand's down.
I think this is the best DIY scope out there,
On IDE maybe you could steal the IDE from lxardoscope on Sourceforge.
I get what your saying on the power it can be powered from 12v, but you RECOMMEND 5 Volts as that's what the Ardino uses...

I really like this, not because it is a really great and simple scope with a really small footprint space wise...
but simply because of it's growth potential...

Just an Idea... for most people growing an Interest in the field.. space and initial hardware outlay cost's are an issue...

I was recently lucky enough to win a great old oscilloscope, function generator multimeter and regulated power supply for pretty cheap... second hand
and when I say cheap... I mean a few hundred pounds...
and they pretty much take up almost Half my workbench space wise.. even stacking the power supply and function generator on-top of the Oscilloscope.

This Scope is set to be the cheapest and smallest space wise...
You could combine more into this, with an Arduino mega maybe for more inputs you could build in a simple Function generator... a Multi-meter, and design to put in your own regulated power supply....
all with one credit card sized board, with a bread board and some components, you could make a PCB CNC design layout and sell them for great profit, and great value saving the average enthusiast beginner hundreds of pounds, and ton's of desk space, so they can take their projects from the garage workbench to the study desk...
then to add on a Raspberry PI 25£ credit card PC with a customized distribution with Arduino IDE etc. or a cheap 7” android capacitive touch pad with apps.
You now have an entire workbench with a design IDE, with all the tools capable of operating off a 12 volt battery... powered by wall/solar panels, and all fit in one little box smaller than your average Oscilloscope able to fit on any desk, small enough that the wife does not throw it out !
The applications could be endless...
But this project has a lot of room for Growth... and If you highlight it's growth potential... there will be a lot more interest... and a lot more people building these, and making cut's with components able to be sourced cheaply in many countries...
Man...
You will have a following and be set for life.
Schools/Universities will want this, what better way to learn than to build your own test equipment…
Not to mention cost saving’s, Saving each school from forking out thousands per each lab desk, to a mere hundred or so pounds, making education affordable !
but keep it open source please, and make the commission of donations and official branded boards, Which people will want to have...
anyway.
If your keen to go down that Path, I am keen to help.
From a Automation/Integration/Programmer/IT specialist dabbling in electronics
Redsic in reply to RedsicAug 2, 2012. 2:27 PM
Merge,

Grinoscope

Simple Logic Analyzer
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1223530321

Multimeter
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1266030815/7

Waveform Generator
http://www.instructables.com/id/Arduino-Waveform-Generator/

Voltage Regulator
http://www.arduino.cc/playground/Main/RegulatedPositiveVoltageBooster

All in the same box, with say a Raspberry PI, Touchscreen/LCD, and a Lead acid Battery, = Super low cost full lab in one little box, Ideal for starters and beginners.
womai says: Mar 28, 2012. 4:06 PM
Two ideas to make the code more efficient (run faster):

The calculation

ADCCounter = ( ADCCounter + 1 ) % ADCBUFFERSIZE;

involves an integer division which tends to be time consuming (at least on a Microchip PIC - I do not know Atmel as well). Instead, try

if (++ADCCounter >= ADCBUFFERSIZE) ADCCounter = 0;

Second, you can completely avoid the time required to evaluate

if(wait)

and live without the wait variable if you simply set stopIndex to a value that the counter never reaches, as long as you aren't yet in the post-trigger phase. I.e. during initialization (when starting a new sweep) set

stopIndex = ADCBUFFERSIZE + 1;

and when the trigger event happens then just do as you did so far, but without the boolean wait variable:

ISR(ANALOG_COMP_vect)
{
// Disable Analog Comparator interrupt
cbi( ACSR,ACIE );

// Turn on errorPin
//digitalWrite( errorPin, HIGH );
sbi( PORTB, PORTB5 );

stopIndex = ( ADCCounter + waitDuration ) % ADCBUFFERSIZE;
}

and the ADC ISR routine becomes

ISR(ADC_vect)
{
if (++ADCCounter >= ADCBUFFERSIZE) ADCCounter = 0;

if ( stopIndex == ADCCounter )
{
cbi( ADCSRA, ADEN );
freeze = true;
}
}
Caffeinomane (author) in reply to womaiJul 10, 2012. 2:23 PM
Thank you very much womai for your precious advices!
This period is very though for me but I am planning to modify the project according to your suggestions.
hoppy777 says: Mar 29, 2012. 3:42 PM
Build an adruino signal generator. It ought to be easy to generate different wave forms.

Hoppy
womai says: Mar 28, 2012. 4:28 PM
One thing to be careful about: If you supply the op-amp with +/-12V it can drive almost as much into your Arduino - which will most likely kill the latter! Would be a good idea to add a series resistor after the last op-amp stage, and behind that two clamping diodes (Schottky type) going to 0V and 5V, respectively.
womai says: Mar 28, 2012. 4:25 PM
You can build a simple analog signal generator with an Arduino driving a R-2R resistor network (google the term and you'll get plenty of hits) from an 8-bit port. Use 1% resistors and you'll get almost 8 bits of resolution. You can the scale an buffer the signal with an op-amp stage. Just a few cents worth of parts apart from the arduino.

Here is such a project that uses an AVR, ready to be copied:
http://www.myplace.nu/avr/minidds/index.htm
womai says: Mar 28, 2012. 4:16 PM
To the circuit itself:

The third op-amp stage isn't really needed. Did you try to run without it? (make sure the unused op-amps inputs are tied to VCC and VSS, respectively, to avoid oscillations).

Second, to protect the input stage against overvoltage I'd add clamping diodes to VCC and VSS, respectively, right at the place where the 1 MOhm resistor is. Good, cheap, fast, low-capacitance diodes would be e.g. 1N914.
womai says: Mar 28, 2012. 4:11 PM
Just a general comment - and it doesn't affect the content of what you say, you did a very nice Instructable! - what you have in your circuit is called an op-amp "follower" or a "buffer", not an "emitter follower". An emitter follower would be a single transistor (with suitable resistors), not a full-blown op-amp. In fact, your op-amp could have FETs in the output stage (not BJT = bipolar junction transistors), and FETs have source, drain, and gate, but no emitter whatsoever.
intructable says: Mar 19, 2012. 12:21 PM
Amazing, great job!
For a GUI you could use Qt which is free and coded in C++.
Check my instructables to get an overview of what Qt could do.

Good luck
Caffeinomane (author) in reply to intructableMar 20, 2012. 1:15 AM
Thank you!
I was actually thinking about using the Qt with Qwt.
intructable in reply to CaffeinomaneMar 20, 2012. 3:40 AM
You will also need a serial library, try the qextserialport library.
Here some information about that :
http://www.instructables.com/id/Control-your-arduino-from-your-PC-with-the-Qt-Gui/

For Qwt, take a look at this :
http://www.instructables.com/id/Make-graphs-on-Qt-and-plot-your-arduino-measuremen/

As you are a physicist (like me) you could find Qwt very useful to develop your applications.

cheers
Caffeinomane (author) in reply to intructableMar 21, 2012. 9:48 AM
I will surely take a look at those instructables. Thank you!
JakeTobak says: Mar 18, 2012. 7:20 AM
For the GUI, you might be able to do something with MATLAB and its ArduinoIO package.
Caffeinomane (author) in reply to JakeTobakMar 18, 2012. 2:36 PM
I guess that that could be an option. Unfortunately, even though Matlab is a wonderful instrument, it is too expensive and the GUI would not be available to everybody. I would like to use an open source tool to give the result to the community.
rblee in reply to CaffeinomaneMar 19, 2012. 5:01 PM
You could also try Octave (http://www.gnu.org/software/octave/) which is a kind of open source Matlab. Although the language structure and syntax are similar, it isn't as simple as just dropping Matlab code in and running it.

That said, you seem to be in the position of writing new code, so this probably wouldn't matter.

Oh, did I mention the learning curve? :)

BTW - Really nice project. Well done.
Caffeinomane (author) in reply to rbleeMar 20, 2012. 1:18 AM
Yes I considered that option because I actually use Octave in my daily analyses. But I do not think that its target is to develop GUIs. I think that Python could be more proper.
DGerman says: Mar 19, 2012. 2:49 PM
Nice use of preprocessor
Caffeinomane (author) in reply to DGermanMar 20, 2012. 1:16 AM
Thank you!
I would like to use the preprocessor more, it is intriguing :)
l1q1d says: Mar 19, 2012. 1:38 AM
Great work man!
Caffeinomane (author) in reply to l1q1dMar 19, 2012. 2:39 AM
Thank you!
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!