element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Blog Arduino as (slow) oscilloscope
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: strb
  • Date Created: 7 Feb 2016 9:30 PM Date Created
  • Views 3651 views
  • Likes 3 likes
  • Comments 15 comments
  • oscilloscope
  • labview
  • arduino
Related
Recommended

Arduino as (slow) oscilloscope

strb
strb
7 Feb 2016

A couple of days ago Ben in The Ben Heck show made a oscilloscope using raspberry pi and bitscope, now I want to show you how I made my personal oscilloscope using arduino and LabView.

 

Let's start!

First of all we have to know the speed limitation of analogRead, infact this instruction takes a bit more than 0.1 ms to execute, so the theoretical max speed that we can reach is lower than 10Khz. Umm..... it doesn't sound good! So the first step is to speed up analogRead, to do this we have to find the atmega328 datasheet and then study the chapter that explain how the adc works.Great, I just have to set a couple of registers to increase the conversion's speed (it seems easy but this was the first time that I changed the default settings so I spent few hours of "study" for it).Basically the adc take the system clock and divide its frequency with a certain factor specified into a register before using it for timing, so decreasing this number we can increase the speed.We also need to set the voltage reference, the input pin and the "format" of the adc output.

The next step is to create a fast data flow from arduino to pc, this is really easy because we have only to find the maximum speed using "standard" arduino communication, after a bit of try I found that the max speed is about 4000000 baud/s (500KByte/s, not bad!).

Beware! You can't use this speed to display data with the standard serial monitor, you have to made a specific program that can read data at those speed.

Below here you can see the program running on arduino:

byte mask=B01000000;//mask for start of conversion & state of conversion
char t=' ';

void setup()
{
  Serial.begin(4000000);//500kByte/s, super speed!
  ADMUX=B01100000;//I'm using input A0,result is left adjusted
  DIDR0=0x01;//shut off digital input for A0
  ADCSRA=B11000011;//I'm using 8 as division factor,with 4 I obtain quite noisy measurements
  ADCSRB=0x00;//free running, default setting
}

void loop()
{
  startofconversion();//start a new conversion
  Serial.print(t);//send old data
  t=waitandget();//obtain new data, it will be send next cicle
}

void startofconversion()
{
  ADCSRA=ADCSRA|mask;//let's start a conversion!
}

byte waitandget()
{
  while((ADCSRA&mask)==mask)//wait
  {
  }

  return ADCH;
}

With this I reach a sample rate of about 85/90 Khz(It's an estimate, i can't measure it because I haven't an oscilloscope),of course it isn't comparable with a real oscilloscope but it's enough if you have to display for example an audio waveform or if you have to check the pwm for a motor.

The precision is 8 bit.

 

Pc program

To make the pc interface I used LabView, the program still have some little problems but it works, with it I can see in real time the signal and the current value:

image

Of course I can zoom in to see it better image

image

You can also freeze current measurements to see it in the "Static graph" and then take data using windows on the upper right.

image

In this image I'm visualizing the voltage on a capacitor and below the old measurements of the square wave, as you can see the measured frequency is 1129 Hz, the calculated one is 1300 Hz so it isn't perfect but it can give you a quite accurate idea of what your circuit is doing (I was checking an oscillator made with a 555).

 

I will work to make it better, more precise and stable and probably I will create a small circuit to increase the range (0-5V is a quite poor range).

Attachments:
programs.zip
  • Sign in to reply

Top Comments

  • DAB
    DAB over 10 years ago in reply to strb +2
    I agree. I did a lot of debugging work with an old Dumont oscilloscope that could only see about 100 KHz signals, which was plenty for the old TVs at the time. DAB
  • clem57
    clem57 over 10 years ago in reply to strb +1
    Not quite. You can use interrupt timer to perform time sensitive gathering data while looping sending data. This will be bursty sending on USB while being interrupted. Clem
  • strb
    strb over 10 years ago +1
    I've update the two programs, I've partially followed your suggest. Basically now I acquire a data packet of 1500 sample and simultaneously I measure the total time of sample acquisition and after I send…
  • strb
    strb over 10 years ago in reply to e14 Contributor

    Hi, at the moment the frequency calculation is "manual",I decide 2 points in the graph and then the pc calculate elapsed time between the two points and the corresponding frequency.To see how much time take the adc conversion I'm using the function micros(), this function return the microseconds that are elapsed from the start of your program (when you turn on the board or reset), it has a precision of 4 microseconds.

    I'm not using the function delay because it stop the program, th function micros() (or millis() if you have to measure milliseconds) instead run in parallel with your program (it use a timer counter) so you can run your program and acquire the time data only when you need.

    Do you have only to measure the frequency of a signal or even other things?

     

    You can see below the arduino program that I'm using now:

     

     

    byte mask=B01000000;//mask for start of conversion & state of conversion

    char data[1500];//I am using a packet of 1500 byte

    byte start=0;//data from the pc

    long timer=0;//estimated time for the global conversion

    char msb;//these 3 char are used to send the time measurements

    char midsb;

    char lsb;

     

    void setup()

    {

      Serial.begin(250000);

      ADMUX=B01100000;//I'm using input A0,result is left adjusted

      DIDR0=0x01;//shut off digital input for A0

      ADCSRA=B11000011;//I'm using 8 as division factor

      ADCSRB=0x00;//free running, default setting

    }

     

    void loop()

    {

      if(Serial.available()!=0)//there are incoming data?

      {

        start=Serial.read();

        if((start&B11111000)=='p')//I'm checking the ack...

        {

          ADCSRA=(ADCSRA&B11111000)|(start&B00000111);//set the speed

          timer=micros();//get time

          for(int i=0;i<1500;i++)//acquire data

          {

            startofconversion();

            data[i]=waitandget();

          }

          timer=micros()-timer;//calculate the effective time of conversion

          for(int i=0;i<1500;i++)//send data

          {

            Serial.print(data[i]);

          }

          /*Serial.println();//debug

          Serial.print(timer);//debug

          Serial.println();//debug*/

          lsb=timer&0x000000FF;

          midsb=(timer>>8)&0x000000FF;

          msb=(timer>>16)&0x000000FF;

          Serial.print(msb);//send timer's data

          Serial.print(midsb);

          Serial.print(lsb);

        }

      }

    }

     

    void startofconversion()

    {

      ADCSRA=ADCSRA|mask;//let's start a conversion!

    }

     

    byte waitandget()

    {

      while((ADCSRA&mask)==mask)//wait

      {

      }

     

      return ADCH;

    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • e14 Contributor
    e14 Contributor over 10 years ago

    I am working on a similar kind of project,but i don't know how to measure the frequency of a signal that is being applied,is frequency calculations involves any delay considerations that is introduced by internal hardware?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • strb
    strb over 10 years ago

    I've update the two programs, I've partially followed your suggest.

    Basically now I acquire a data packet of 1500 sample and simultaneously I measure the total time of sample acquisition and after I send the packet and the time to pc that plot the signal and display the sample frequency, I use this data also to obtain a more accurate signal's frequency estimation.

    With "high" sample rate and only 1500 sample it isn't possible to display slow signals, so I can also change the sample frequency "on run", with this trick I can even capture slow wave, the sample frequency now can be selected from about 9 khz to 178khz,it is an huge improvement!

    The next step is to use interrupts to automatically store samples and maybe create a "RAM shield" to increase the memory image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 10 years ago in reply to strb

    I agree.

     

    I did a lot of debugging work with an old Dumont oscilloscope that could only see about 100 KHz signals, which was plenty for the old TVs at the time.

     

    DAB

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • strb
    strb over 10 years ago in reply to DAB

    Yes, the arduino's ADC is quite limiting but it's enough for my actual scope, at the moment I'm not using a display directly connected to arduino mainly for two reasons:

    -I haven't a display for now

    -I'm using the pc as interface to make estimations of sample rate (and also to see a big amount of data at the same time, arduino doesn't have enough memory to do this)

    Thanks to your encouragement.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
<>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube