Close
0%
0%

Lightpen to USB HID interface

Bring CRT displays and light pens into 21st century

Similar projects worth following
This project is about interfacing light pen from the 80s with modern operating system using USB HID.

This is the result of my other research project: Lightpen support for Retro Pie

What is a light pen? Read here.

About 25 years ago I was a happy user of a Commodore C128 with a 14" TV a my primary display. It was a CRT as there was no other kind.

Recently I have dug out some of the old computer stuff from the storage. Among other things I found there a Turbo Computer Lightpen for my C64/128. I have been using it as an input device for GEOS and it was like living in the techno future of the 21st century.

Lightpen was never precise enough to be used like a stylus for drawing, but it was good enough for pointing at menus, icons and marking text in text editing software geoWrite.

One of my RetroPie systems is connected to a tiny 5" portable TV. I got curious if I could find a way to use the light pen with at least some of these emulators.

I learned that with multitasking OS, like Linux there is simply no way of reliably measuring time offsets precise enough to position light pen reliably, even with support of a chip that decodes video signal.

Hence this project - everything this small Arduino Micro Pro does is to listen for signals from video decoder (LM1881) and record time offsets. Every VSYNC the results are reported through USB. Arduino describes itself as a mouse with absolute positioning reporting, like a drawing tablet.

lightpen-hid.ino

Firmware for Arduino Micro Pro. Autocalibration doesn't work well.

ino - 6.02 kB - 05/24/2021 at 18:08

Download

  • 1 × Arduino Micro Pro
  • 1 × 680K resistor
  • 2 × 0.1uF capacitor
  • 2 × female RCA connector
  • 1 × male RCA connector

View all 7 components

  • Success, a light pen as a pointing device for X Window system

    Maciej Witkowiak05/24/2021 at 18:57 0 comments

  • LM1881N application

    Maciej Witkowiak05/24/2021 at 18:54 0 comments

    This image from datasheet shows exactly how to wire LM1881N chip.

  • Design and theory of operation

    Maciej Witkowiak05/24/2021 at 18:51 0 comments

    Circuit

    Video input comes from composite video source and works as a passthrough. I have used one male and two female connectors to make it easy to connect as a passthrough no matter what cables are available.

    The LM1881N video decoder chip is an interface between video and Arduino. The signal changes on VSYNC (pin 3) and COMPOSITE SYNC (pin 1) are timed by Arduino and used to prepare HID report for host. The decoder is wired exactly like in the datasheet application example schematic, using two 0.1uF capacitors and one 680K resistor.

    The male DE9 connector is a socket for lightpen. Pin 3 is the push button (active low) and pin 6 is the light pen signal from phototransistor (also active low) whenever electron beam passes in front of light pen lens. You need to provide power to light pen, so pins 7 and 8 must be connected to common 5V bus and GND (respectively).

    Operation

    Timer1 is setup to count without prescaler (so 16MHz) and with interrupt on capture (change on pin 4, ICP1, connected to pin 6 on light pen cable).

    Another interrupt is triggered by high to low transition on pin 7, connected to VSYNC.

    After every low to high transition on COMPOSITE SYNC (pin 9 on Arduino) row counter is increased, Timer1 is reset to 0 and starts counting time for the current row.

    If there is ICP interrupt the current row numbe and current Timer1 value are saved for later use.

    After every VSYNC interrupt a HID report is prepared if there was ICP interrupt event:

    1. row number is our Y position
    2. Timer1 value saved in ICP is our X position
    3. button state is compared with last state
    4. x/y values are smoothed and rescaled
    5. HID report is sent to USB host

    Relevant events are cleared. The row counter is set to zero, a new image frame starts.

View all 3 project logs

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates