Build Your Own Light Pen (Penlight Pen)
- Year
- 1983
- Type
- DIY project
- Category
- Light pen
- Manufacturer
- Homebrew design by John Anderson (Creative Computing / The Creative Atari)
- Tags
- light-pen, phototransistor, joystick-port, paddle, antic, gtia, penh, penv, creative-computing, diy, beginner
- Related
- Joystick-Port Interfacing: the PIA as a Parallel I/O Port, Driving an RC Servo from the Joystick Port (Antic, 1984), Real-World Interface (Antic Relay Controller), Build-Your-Own Speech Synthesizer (SP0256-AL2), Ultra Sound: Monitor-Port Audio Cable (Antic, 1983), AtariCom and Other Atari-to-Atari Link Cables
Overview
The Atari 400/800 has light-pen support built into its hardware. A pen plugged into controller port 1 (port "0" in BASIC) needs no extra board, and its position can be read with two PEEKs. Atari announced a pen of its own, shown in a 1981 product brochure for under $100, but pulled it before it reached the shops. John Anderson heard more than one explanation: a flaky tip switch, or marketing's fear of children poking a pointy stick at a TV tube. Symtec's professional aluminium-barrelled pen cost $150. So Anderson, an associate editor at Creative Computing, showed readers how to build one for about $10 and a couple of hours' work. The article was collected in The Creative Atari.
How a light pen works
The TV draws the picture one scan line at a time from the top left. A phototransistor aimed at the screen sees a flash when the beam passes its spot. ANTIC latches the beam's position at that moment into its light-pen registers, which the OS copies to the shadows LPENH (564) and LPENV (565). Your program turns those values into screen coordinates. The hardware has already done the hard work.
Parts (1983 Radio Shack numbers)
| Part | Number |
|---|---|
| Phototransistor | 276-130 (89¢) |
| 100 kΩ ½ W resistor | 271-045 |
| Penlight (the pen body) | 61-2626 ($1.99) |
| DE-9 plug and five-conductor shielded cable | an old joystick cable won't do, because it lacks the needed pins |
| Bell wire, the cap of a Bic pen, electrical tape, optional grommet |
Wiring (controller port 1)
| DE-9 pin | Connects to |
|---|---|
| 6 (trigger / light-pen input) | phototransistor collector |
| 7 (+5 V) | 100 kΩ resistor to the collector |
| 8 (ground) | phototransistor emitter, and one side of the touch ring (via the metal barrel) |
| 9 (paddle 0 input) | the other side of the touch ring |
The base lead of the phototransistor is clipped off and not used.
The touch-ring switch: instead of a mechanical tip switch, a bare wire loop sits in a groove cut around the pen's plastic tip. Touching it bridges pins 8 and 9 through your finger, and PADDLE(0) drops well below its idle value of 228. If it doesn't respond, try a slightly damp fingertip.
Building it
- Gut the penlight: remove the bulb holder and push the switch and springs out of the barrel.
- Enlarge the switch hole for the cable. Thread the barrel onto the cable before soldering anything.
- Solder the resistor and leads to the phototransistor with a low-wattage iron.
- Cut a groove about 1/8" up the plastic tip with a craft knife. Melt a small hole in the groove with a heated pin, and thread the touch-ring wire through it.
- Test before closing up:
10 SETCOLOR 2,0,14:SETCOLOR 1,0,0:? PEEK(564),PEEK(565),PADDLE(0):GOTO 10
The first two numbers should change as you move the pen over the bright screen, and the third should drop when you touch pins 8 and 9 together. 6. Insulate everything, slide it into the barrel, use a trimmed Bic cap as a collar to centre the phototransistor, and screw the tip back on. A stripped lead wrapped through the tip makes the ground contact to the barrel.
Using and calibrating
Anderson supplied a GRAPHICS 7 drawing program and a menu-selection demo with the article. Calibration is done by adjusting the offsets subtracted from LPENH and LPENV until the plotted point lands under the tip. They were consistent across the three pens he built, but depend on your monitor. Expect:
- better vertical than horizontal accuracy;
- a need for a very bright screen, which is why his drawing program can invert the colours;
- on an Atari 400, Anderson advises plugging the pen into port 4 and using
PADDLE(6)instead ofPADDLE(0).
The same principle works on XL/XE machines. Modern flat-panel displays don't have a scanning beam, so you need a CRT for any light pen to work.
Credits
- John Anderson — Build Your Own Light Pen (The Creative Atari, Creative Computing) — AtariArchives.org
- De Re Atari programmer's card (LPENH/LPENV OS shadows) — AtariArchives.org
