Feature

Watching Waves

ATmega328P-based Mini Oscilloscope

Shashwat Patel

Issue 52, November 2021

A DIY mini oscilloscope using an ATmega328P microcontroller and 128x64 GLCD.

Test gear can be costly and out of reach for many hobbyists. Thankfully, makers can make some basic test gear out of commonly available parts and some coding prowess. This was the case for Shashwat who built his own ATmega328P-based mini oscilloscope after coding and simulating the project using simulation software. All built in a timber enclosure and rechargeable to boot. We caught up with Sashwat to find out more.

Thank you for your time, Shashwat. Before we discuss your project, please tell our readers about yourself.

I consider myself as one curious human who has always been awestruck by technology. I always find myself drawn to machines in general, but electronics have always had a special corner reserved for themselves in my head and heart.

Choosing engineering and that too in electronics, was only about time, and this decision was inevitable, especially after I rewatched the Iron Man movie for the 27th time. Apart from electronics, my life primarily includes watching movies (though it takes me around 5 attempts to watch one). My love for good food is another book in itself, and travelling.

Sci-Fi shows are a great place for inspiration for us makers. What got you interested in electronics in the first place?

What initially got me interested was my fascination with taking complex things apart, such as toys, old clocks, and sometimes mobile phones also. My first memorable electronics experience was when I took a remote control car apart and was completely fascinated by the green shiny circuit boards with all the complex parts. I found it fun to try and draw the circuit diagram by looking at the board. Of course, I had no idea what I was doing.

Those were the days when no JIO sim cards were available in India and smartphones did not fit into the budget of a High-school kid. At that time I had a Nokia Asha 200 multimedia mobile phone which hardly provided a download speed of a maximum 100 Kbps for a few hours after midnight. So every night I download 3-4 random electronics-based project videos (which took a whole night to finish) and the next day enjoy them in loop with full of interest.

Taking things apart is a common trait with makers, and a great way to learn. We were impressed by your mini oscilloscope project. What was the motivation behind it?

Before telling you about the motivation behind this project, let me tell you about e-Yantra first. e-Yantra is a project by IIT Bombay to spread education in embedded systems and robotics.

This project has been sponsored by the Ministry of Human Resource Development (MHRD) through the National Mission on Education through ICT (NMEICT). It helps faculties to provide training to students through hands-on projects and inculcate successful innovators and entrepreneurs among them.

A few months back I participated in a course on embedded systems & robotics conducted by e-Yantra. This is where I was personally set this challenge activity of building an oscilloscope using simulation software and writing the code in embedded C language.

After spending a lot of time on Atmel studio, I was able to successfully complete this task within the given time. Happily, I received a Grade A certificate for it. However, even though I had made this amazing project on simulation software, it was of no use to help me with my electronics hobby. So, I decided to build this project on hardware to make it more worthy.

Congrats on your grade A certificate. Planning a project in simulation software sounds like a good approach before investing in the hardware to build it. Tell us how your hardware works.

You've almost certainly drawn charts in school. Many of them show how a certain quantity of something (like a heart rate, the price of a corporation's shares, or a country's exchange rate) changes over time. They have the quantity plotted in the vertical direction (known as the y-axis) and the time period plotted in the horizontal direction (the x-axis). The trouble with charts like this is that they can take ages to plot unless, of course, you happen to be an oscilloscope!

Parts Required:
2 x Perfboard PCBs
1 x 18650 3.7V battery
1 x 18650 battery charging module
1 x Toggle Switch
1 x 10K Potentiometer
3 x Push Buttons
1 x ATmega328P microcontroller
2 x Capacitors
1 x 16 MHz crystal
1 x 128x64 GLCD
1 x 40 pin IC socket
Headers
1 x set of probes
Solder and Soldering wire

It's a handy little gadget that draws charts automatically using signals you feed into it from the probes hooked up to an electronic circuit/Function generator. When you attach a mini digital oscilloscope probe to an electronic circuit the analog-to-digital converter (ADC) of ATmega328P microcontroller samples the signal at discrete points with some delay(T) in time and converts the signal's voltage at these points to digital values called sample points.

The horizontal system's sample clock determines how often the ADC takes a sample. The rate at which the clock "ticks" is called the sample rate and is measured in samples per second. The sample points from the ADC are stored in the memory of the microcontroller as waveform points. More than one sample point may make up one waveform point.

Together, the waveform points make up one waveform record. The number of waveform points used to make a waveform record is called the record length. When we press Div +ve switch sampling delay(T) increases so the gap between sample points will increase as a result waveform appears zoomed out and vice versa.

The voltage value of the sample point which is having the maximum analog value out of all the sample points stored in the memory is the Peak voltage of the captured waveform. And the inverse of the sampling rate will be the Frequency of the waveform.

The display receives these record points after being stored in the memory and displays them as a captured waveform on the DISPLAY WAVEFORM area ((0, 0), (95, 63)) and simultaneously on the DISPLAY WAVEFORM INFO area ((96, 63), (127, 63)) parameters (like frequency of the waveform, peak voltage of the waveform, etc) are displayed.

Thanks for the detailed explanation. Do you know what the min and max values you can measure?

Yes, AVR controllers use 10-bit inbuilt ADC, which means we will get digital output 0 to 1023. i.e. When the input is 0V, the digital output will be 0V & when input is 5V (and Vref=5V), we will get the highest digital output corresponding to 1023 steps, which is 5V. So for the voltage range, the oscilloscope can plot the signals of 0V to 5V DC. And AVR having step size (with Vref=5V) 5/1023 = 4.88 mV, so it can detect the change of a minimum of 4.88 mV in the input signal.

What frequency range does the circuit measure, and how were you able to check its accurate?

It can measure from 10Hz to 50kHz. I have tested the oscilloscope using my Arduino-based function generator and the readings were pretty much accurate.

What prototyping did you need to do?

Before building my mini oscilloscope on hardware I tried & tested my circuit and code on simulIDE simulation software. After a lot of debugging when I was satisfied with my code and output of the oscilloscope, I started building it on hardware.

Can you tell us a little about the function generator circuit you made to test the oscilloscope?

When I successfully completed my mini oscilloscope project, I can't wait to test it out. So I made a simple square wave generator from Arduino from which I can change the frequency and peak voltage of the square wave. With the help of "tone" function, I was able to generate a square wave of the specified frequency (and 50% duty cycle) on the PWM pin of the Arduino. But sadly Arduino doesn’t have any function to change the peak voltage of the square wave. So, I attached a 10 KOhm potentiometer to its PWM pin in order to change its peak voltage.

It’s great that you have built the project into an enclosure to make it a complete build. How did you go about making that?

I don't have a 3D printer so I decided to build a wooden enclosure. I went to the carpenter shop and bought a few balsa sticks, sandpaper, hexsaw and fevicol glue. Then I measured the height and width of the LCD and built a rectangular frame for that. This will be the front of our oscilloscope and for the back part, with the help of hexsaw, I cut down the balsa sticks into pieces and joined them with glue to make a rectangular wooden box. After completing the front and back parts, I rubbed them with sandpaper to provide a very neat wooden texture to the enclosure.

Were there any particular challenges you needed to overcome?

Most of the challenges I faced were when I was writing the code for the display. The 128x64 LCD screen was something I was working on for the first time and had to go through the ug8 library several times to write even one function.

When I was trying to plot the waves on the screen, the curves were not getting plotted symmetrical about the vertical axis and this was something that bothered me for a while. Also, enclosing all the hardware in a small wooden box with perfection was an interesting challenge for me. Overall the activity was more of enjoyment rather than a challenge for me.

Great! Where do you plan to go from here?

Every Engineer who loves to tinker with electronics at some point in time would want to have their own lab set up. A Multimeter, Oscilloscope, Function Generator, and Dual mode power supply are the bare minimum equipment for a decent lab set-up. While all of these can be purchased with a huge amount of money, we can also easily build a few on our own. Obviously, makers like me will prefer the second choice. When you take a closer look at all the devices, apart from the basic circuitry, you will find the two most important components are common in all of them i.e LCD and a microcontroller.

If I will be building this again in the future, I'll try to build most of the equipment in one. No doubt I have to write a bunch of lines of code and deal with very large circuitry but as a result, I'll get a compact, budget-friendly, and most importantly a multi-functional device that will save a lot of extra workbench space also.

That sounds like quite the challenge. If our readers wanted to make your oscilloscope project for themselves, do you have the wiring diagram and code to share?

Yes. I am happy to share these with your readers. The code can be found on my GitHub https://git.io/JEsvf

It’s wonderful that the maker community shares their knowledge, thank you. Is there anything else we haven't discussed about the project that our readers should know about?

I don’t think there is anything left to discuss. Anyone having basic understanding of programming & electronics can easily build by reading this article.

Thank you Shashwat. We wish you all the best and look forward to seeing what you build next.