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
  • 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 3157 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 9 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 9 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 9 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…
  • Former Member
    Former Member over 9 years ago

    This is sure really great. I've seen some similar sine wave generation project using Arduino compatible board (https://www.facebook.com/groups/AmebaIoTWW/ ).

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 9 years ago

    Ok,Thank you very much

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • strb
    strb over 9 years ago in reply to Former Member

    I've attached programs at the end of the blog post, they are a bit different compared to what I've described, now the frequency calculation is more accurate.

    It's a good idea to see even the spectrum of the wave, probably I will try it too.

    If you want to do the fourier transform with arduino you can use this library: ArduinoFFT - Open Music Labs Wiki I have already tested it and works fine, it is also well explained.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 9 years ago in reply to strb

    Thank you for the quick reply.

    Idea of my project is to acquire analog signals of lower frequencies(frequency range is limited by the sampling rate of Arduino) and displaying the time domain signals on Oscilloscope.Later I want to perform FFT analysis on collected samples to get its frequency spectrum. I wanted to get the frequency of a signal from the time domain waveform displayed on the graph by noting the time period of a signal just like a conventional oscilloscope.In your code it seems  you are  transferring time data serially along with the samples and using Labview to do mathematical parts of calculation.I am beginner to Labview programming,  will you please share the Labview file?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 9 years ago in reply to strb

    Thank you for the quick reply.

    Idea of my project is to acquire analog signals of lower frequencies(frequency range is limited by the sampling rate of Arduino) and displaying the time domain signals on Oscilloscope.Later I want to perform FFT analysis on collected samples to get its frequency spectrum. I wanted to get the frequency of a signal from the time domain waveform displayed on the graph by noting the time period of a signal just like a conventional oscilloscope.In your code it seems  you are  transferring time data serially along with the samples and using Labview to do mathematical parts of calculation.I am beginner to Labview programming,  will you please share the Labview file?

    • 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 © 2025 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.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube