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.
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).
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.:
PORTB = var;
You can do the same with PORTD using pins 2 (lowest voltage) to 7 (highest):
PORTD = var << 2;
<< 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
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!