Sunday, October 4, 2015

Raspberry PI Teletype Project

Project Software

Software to control a Teletype with Raspberry Pi GPIO interface 

 
Skip forward to The Project section for details of how the software/hardware are integrated together. My project is using an old Raspberry Pi Model B. Newer Raspberry Pi models GPIO pins may be in a different order. Please research and verify the pin outs before connecting any external electronic to your Rasberry Pi.

Background

Since High School, I've surfed shortwave radio utility bands. These frequencies contain commercial and military traffic, which use "advanced modulation".

My two specific areas of interest are Radio Teletype (RTTY) and Radio Facsimile (FAX) transmissions. During the late 70's and through the early 90's, the HF radio spectrum (3MHz-30MHz) was quite rich with many interesting utility band broadcasts.

Between 1979-1990, I amassed quite a collection of surplus military radio, RTTY and FAX equipment. Over time, I realized I was acquiring the "best of breed" equipment, mostly used by the Navy.

I've retained a small portion of that collection to this day. Today the HF utility bands are not as exciting to monitor, yet there still remains some weather FAX (WEFAX) and weather-related RTTY traffic.

Today's go-to technology for receiving this traffic is a computer. Equipped with an audio card, both RTTY and WEFAX can be easily rendered by laptop/desktop computers. In the early 80s, this was not true. Personal computers were very expensive, and beyond the reach of a teenager communications technologist.

My first teleprinter was a Model 15 Teletype. This was mostly a automated typewriter. Using a clever combination of electromagnets and mechanics, these devices implemented a "serial port" supporting 5-bit Baudot code. This equipment was acquired at a Ham Fest in Wheaton IL, one very cold winter weekend. The trick then was to bring this equipment to life, and actually print something. This is where my youthful interest in electronics and shortwave radio were further developed. This heavy, noisy equipment became my pride and joy when I finally was able to print news feeds from shortwave radio.

I quickly learned the Model 15 was limited, by only supporting 60WPM, or 45 baud, traffic. Most press outlets on the HF bands used 66WPM, or 50 baud traffic. Listening to the "tweedle-tweedle" frequency shift key (FSK) audio signals, you could tell the speed of the broadcast, with a little experience. There was obviously still faster traffic, which turned out to be 100WPM, or 75 baud, traffic.

By today's standards, these speeds are painfully slow. However, for mechanical teleprinters, 100WPM, or 10 characters per second, is actually quite impressive to see in action.

Model 28 ID Tag
The king of the 5-bit Baudot teleprinter machines is the Model 28 Teletype. This was developed for the U.S. Military in the 50's by the Teletype Corporation. This is considered the most rugged teleprinter they ever developed. This is a marvel of mechanical engineering, and telecommunications. The Bell Labs exhibit at the Museum of Science and Industry in Chicago had a Model 28 TTY on display, printing UPI press feeds. This exhibit made a lasting impression on a pre-teen science enthusiast.

Images of my Model 28 printing a test pattern from my Raspberry Pi:
Model 28 Printing Test Pattern (close up)

Front view of printing teletype:
Model 28 Printing (front view)
Model 28 Selector Unit (front) 



Close up views of data selector unit, where binary 1's / 0's are converted mechanically to 5-bit codes. This is a mechanical serial port.


Model 28 Selector Unit (solenoid)

 

 

The Project 

The Raspberry Pi Teletype Project's goal is to bring back the press feed printed on the Model 28 Teletype I retain from my collection of surplus military radio gear. Using breaking news emails as a source of data, the Raspberry Pi is both an email filter and a teletype driver.

The Raspberry Pi GPIO (General Purpose I/O) pins are ideal for such a project. The interface to any teletype is primitive: a single solenoid used to key 1's and 0's data into the mechanical data selector of the Teletype. Using one GPIO pin to send a stream of binary Baudot code data to the Teletype, with some simple electronics to interface the Raspberry Pi with the Teletype, this 50's vintage teleprinter is back in operation again.

Step One: RPi LED "Blink"

Having no  Raspberry hardware programming experience, I searched for demo projects which expose this functionality. The WiringPi project an programming API to access to the GPIO / UART / PWM pins on the Raspberry Pi. Nice. Example one: "Blink".

RPi Blink wiring


Wiring Blink is simple enough. There is one small challenge: connecting the RPi pin header to a prototype board. My solution: cannibalize an old floppy disk IDE cable. This has more pins than needed, but this works.  The wiring for Blink is simple enough; one LED and a 330 ohm resistor.

This simple circuit uses GPIO 0 (pin 11) connected directly to one LED terminal, the 330 ohm resistor to the other LED terminal, and ground (pin 6) to blink the LED on/off using the WiringPi project. 

Please note: The GPIO pin numbering is extremely confusing, and depends on the model RPI you are using. I am using a very old Raspberry Pi Model B 512MB, built 2011-2012 in this project. Below is complete GPIO header block used in this project.

Here is the full table of Raspberry Pi GPIO pin wiring.



Link to Raspberry Pi GPIO Heder Model A&B P1 Header (wiringPi Project)

 









RPI Model B Schematic: Page 2 explains the wiring of the GPIO connector in extreme detail. The DNC pins are extra 5v/3.3v and GND pins.

Copy/Paste the blink source code, compile, run and sure enough, the LED blinks at a 1/2s rate.

Next test: Can the GPIO  pins be cycled on/off quickly enough to control a Teletype. Just modify blink.c to delay 22ms, vs the 500ms value in this example. Running that code, you can't visually tell what is happening. So I tried 44ms, which is slow enough for my eye to see the LED is actually blinking. From this success, I assumed 22ms worked, I just couldn't see it. Yes, I could have hooked up an O-Scope, but this test seemed good enough.

Step Two: Controlling the Teletype Loop Current


GPIO Relay Control
(Note: Wiring above is for NC relay!!)

The Model 28 controlling "electronics" is a solenoid magnet, which keys bits into the selector unit. This is the input to the mechanical "UART" of the selector unit. This should be 120v-150v at 20-60ma. My main concern was to completely isolate this high voltage loop circuit from the RPi. This simple circuit allow easy control of a relay through any RPi GPIO pins. Modify the "Blink" demo hardware, replacing the LED with this circuit. You can then "hear" the relay click on/off at a 22ms rate.

This circuit substitutes the LED for an NPN transistor to power on/of the 5V normally open relay.

The final piece of this project is the Raspberry Pi software to convert input text to Baudot code. That ASCII to Baudot code conversion, and then finally to a bit stream to key the Teletype solenoid magnets is performed by this small software project. Github rtty-rpi Teletype driver project.


To build this project, you must have make and the GCC C compiler installed. Additionally, there is a dependency on the wiringPi project, which is simple to install:

    sudo apt-get install wiringpi

Once these prerequisites are met, just run "make" in the rtty-rpi project.

To test, run this command:

    sudo ./rtty-pi --test-data

This will print the following test pattern:

THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG'S BACK 1234567890
RYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRY



You can also type data from your computer in "real time" using this command:

    sudo ./rtty-pi --keyboard

To exit the --keyboard option, you MUST type this sequence of keys: <ENTER>NNNN.

Please note: The default data rate sent by this project is 60WPM. Should you have a Teletype with a gear shift for other speeds, such as 66WPM, 75WPM or 100WPM, you should use the --wpm option. 

Example: sudo ./rtty-pi --wpm 75 --test-data

Your other option: Set your Teletype gear speed selector to 60WPM.

You can investigate other options with the --help command.

Model 28 Teletype Operation Details

For over more than a decade, I used my model 28 Teletype. Yet, I didn't fully understand exactly how all of the mechanics worked between receiving a serial 5-bit Baudot code from the radio to printing text.

The Internet is a great resource for knowledge. The full Navy training manuals for all things Teletype is available. I am slowly going through the Model 28 Teletype training manual.

The incoming bits from the Baudot signal are decoded by the Teletype Selector Unit - essentially a serial modem mechanically implemented. The question that eluded me for years is just how does the Teletype decode the bits to a specific typing pallet on the type box?
 
Below are images that describe how the incoming Baudot code selects a letter from typing pallet, printing that letter on paper. 
 
Marking / Spacing means 1 / 0 or current on / off through the Teletype selector unit solenoid:
 

I find this diagram a little hard to read. Here is a hand sketch I created that makes sense to me:


 
What does the incoming signal look like? Here is a hand sketch that illustrates the signaling protocol:


Here is a picture of the type box as installed on the Teletype:


This view is the front of the type box. The Teletype moves the type box left/right and up/down based on the incoming code value, and then the typing hammer "pecks" the back of the pallet to print a letter on the paper.

This is the font side of the type box:



"Shadow image" of disassembled type box:


Type box dissassembled

Notice the rows are perfectly horizontal, but the vertical columns are not perfectly vertical, following a "curved arc" pattern. This curiosity hits at the complexity of the Model 28 operations, and now much engineering precision was involved in the development of this device.

For the seriously curious, here is a Navy training manual for a specific Model 28 Teletype. This link jumps to the section describing how a received code is converted mechanically to selecting a type box pallet.

Model 28 Navy training manual: Pallet selection

The full manual can be read. Warning: This document is very, very pedantic, and plodding reading. However,  to truly understand how this mechanical wonder works, this is a great reference source.

No comments:

Post a Comment