Arduino Etch-a-scope

Over the xmas break I bought myself an Arduino Mini, which was a wonderful distraction from all of the revision I was supposed to be doing.

One of the things I did with it was to hook it up to an oscilloscope, in order to draw stuff on the screen.

Someone’s just asked me how I did it, so I figure now’s as good a time as any to write it up.

I rendered my face as a raster image on the oscilloscope

Digital to Analogue Converter

Firstly, I wired up six of the arduino’s output pins through a ladder of resistors, making a R-2R ladder DAC. This arrangement means that each of the six pins can contribute some of their voltage to the final output value. The pin furthest from the final output has to pass through the most resistors and so has the smallest effect on the output voltage. The nearest pin only has to pass through a single resistor, and so causes a more dramatic effect on the output voltage.

For example, switching pin 1 on might cause the output voltage of the ladder to change from 2.22V to 2.29V. Switching pin 6 on, however, might cause it to jump from 2.22V up to 4.72V.

Pin 6’s voltage contribution is double that of pin 5’s, which is double pin 4’s, etc. So it’s binary, basically. Using this technique, you can create any voltage between 0V and 5V, in 64 increments. What this amounts to, is a very simple 6 bit digital to analogue converter (DAC).

Wiring laid out on breadboard

If you wire up the ports right, so that your most-voltage-contributing pin is wired to pin 8, and the rest in decreasing-voltage order up to pin 13, you’ll be able to send an integer to the arduino’s port C and have it correspond directly to the output voltage, which is neat. E.g.:

int var=25;
PORTB = var;

You can do the same with PORTD using pins 2 (lowest voltage) to 7 (highest):

PORTD = var << 2;

The << 2 bit-shift is necessary here because we’re not using pins 0 or 1, which also belong to port D, so there is a slight mis-alignment.

I also added a capacitor to the outputs, to act as a simple low-pass filter. This causes the voltage to change gradually, so that instead of jumping from 2V immediately to 3V, it will instead gradually go from 2 to 2.1 to 2.2 etc. up to 3V. This means the oscilloscope output had lines rather than just dots.

Finally, I hooked up the oscilloscope probes; the port B DAC to X and port D DAC to Y, set the scope to XY (Lissajous) mode, and wrote a little arduino program to move the dot around :-)

'David' written in phosphor


Oscillosketch source code
Oscillosketch uses a little array of “UDLR” (up, down, left, right) commands which draw out a letter using lines.

Etchascope source code
Etchascope uses an array of bits (which I created using either gimp script-fu or perl and imagemagick, can’t remember) hard-coded into the program (I’m sure there are better ways of getting the image data in there – using the arduino ethernet sheild, perhaps? :-). The program simply leaves the beam resting at an “on” pixel longer than it does the “off” pixels.

Feed me back if you demand answers!


three comments

Very cool, I am doing something very similar but outputting to a laser scanner. I’d like to implement something that automatically translates vector files, specifically ILDA.
Joe (Email) - 05 09 09 - 02:47

wow a stunning blog platform you got here
jane smith (URL) - 16 03 11 - 02:26

wow what a stunning blog you have here
jane smith - 16 03 11 - 02:27

Post a comment

Remember personal info?

Comment: Emoticons / Textile

This is not a trick question, but a mechanism for spam prevention.

  ( Register your username / Log in )

Hide email:

Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.
Powered by Pivot. RSS Feed & ATOM Feed