close-circle
Close
0%
0%

Arduino Teletype

Building on my RPi Telegraph project, the Arduino Teletype translates characters to baudot code and drives a teletype.

Similar projects worth following
close
In the 1800's, the telegraph was developed to send messages across long distances over wire using Morse Code. The code was translated by telegraphers to written characters. The next advancement in communications came the teletype in the early 1900's, which originally communicated across the same telegraph lines and exchanging baudot code, a 5 bit character code. The teletype would send and receive the baudot code and using precise timing drove a mechanical typewriter that printed the message on a roll of paper, and removed the human in the loop.

For kids today, the analogy would be where the telegraph was like text messaging, the teletype was like twitter feeds. News would be broadcast and received on teletype all across the country.

This initial build demos a couple of test patterns. I'm currently working on porting Eliza, and then adventure to the Arduino/Pi. One challenge I will have is to read the characters typed on the teletype to make it truly interac

  • Initial Build

    Ed Danis08/24/2014 at 16:54 0 comments

    This initial step is to drive a teletype with three test programs.  

    Program 1:

    The first a program that exercises the teletype with a series of 'R's and 'Y's..  The reason for this test is that the R and Y have opposite byte codes.  R is 01010 and Y is 10101.

    Program 2:

    The second program exercises the each letter and number by typing the following sentence:

    "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG'S BACK 1234567890 TIMES"

    Program 3:

    The third program accepts characters over the serial connection and types them out.  It tracks the number of characters and sends a <CR> and <LF> command before reaching the end of each line.

    Next build will decode the teletype signals.  The grander vision is to combine this project with my telegraph project and have the arduino translate between the two devices.

View project log

  • 1
    Step 1

  • 2
    Step 2

    #include<Serial.h>

    //Baudot lookup table

    unsigned char lookup[] = {

    ' ', 'E', ' ', 'A', ' ', 'S', 'I', 'U',

    '\n', 'D', 'R', 'J', 'N', 'F', 'C', 'K',

    'T', 'Z', 'L', 'W', 'H', 'Y', 'P', 'Q',

    'O', 'B', 'G', 0, 'M', 'X', 'V', 0,

    ' ', '3', '\n', '-', ' ', '`', '8', '7',

    '\r', ' ', '4', '\'', ',', '!', ':', '(',

    '5', '+', ')', '2', '$', '6', '0', '1',

    '9', '?', '&', 0, '.', '/', ';', 0 };

    const int RELAY_PIN = 4;

    const int CHAR_DELAY = 22; //milliseconds

    const int START_BIT_DELAY = 22; // milliseconds

    const int STOP_BIT_DELAY = 44; // milliseconds

    const int SPACE = 4;

    const int F_SHIFT = 27;

    const int L_SHIFT = 31;

    const int CR = 8;

    const int LF = 2;

    boolean letters_on = true;

    boolean print_debug = false;

    /* transmits 5 bit integers */

    void byte_send(int _byte){

    send_start_bit();

    // loop through all 5 bits and send a space for zero bits, and mark for one bits.

    for(int _bit = 0; _bit < 5; _bit++){

    switch (bitRead(_byte,_bit)) {

    case 0:

    Serial.print(0);

    space();

    break;

    case 1:

    Serial.print(1);

    mark();

    break;

    } // end switch

    } // end for loop

    send_stop_bit();

    } // end byte_send()

    /* Lookup and decode characters before transmitting. */

    void char_send(char letter){

    char l = toupper(letter);

    Serial.print("sending ");

    Serial.print(l);

    int idx = lookupChar(l);

    Serial.print(" idx: ");

    Serial.print(idx);

    Serial.print(" Binary: ");

    // check for offset

    if (31 < idx){ // shift for figures

    if (letters_on){

    figure_shift();

    }

    idx = idx - 32;

    } else { // shift for letters

    if (false == letters_on){

    letter_shift();

    }

    }

    byte_send(idx);

    Serial.println();

    } // end char_send()

    void letter_shift(){

    Serial.print(" [L_SHIFT] ");

    letters_on = true;

    byte_send(L_SHIFT);

    }

    void figure_shift(){

    Serial.print(" [F_SHIFT] ");

    letters_on = false;

    byte_send(F_SHIFT);

    }

    void cr(){ Serial.print(" <CR> "); byte_send(CR); }

    void lf(){ Serial.print(" <LF>"); byte_send(LF); }

    void send_start_bit(){

    digitalWrite(RELAY_PIN, HIGH);

    delay(START_BIT_DELAY);

    }

    void send_stop_bit(){

    digitalWrite(RELAY_PIN, LOW);

    delay(STOP_BIT_DELAY);

    }

    void mark(){

    digitalWrite(RELAY_PIN, LOW);

    delay(CHAR_DELAY);

    }

    void space(){

    digitalWrite(RELAY_PIN, HIGH);

    delay(CHAR_DELAY);

    }

    int lookupChar(char letter){

    if (' ' == letter){ return 4; }

    for (int lookupIdx = 0; lookupIdx < sizeof(lookup); lookupIdx++){

    if (letter == lookup[lookupIdx]){

    return lookupIdx;

    }

    }

    return 0;

    }

    void setup(){

    Serial.begin(115200);

    pinMode(RELAY_PIN, OUTPUT);

    pinMode(5, OUTPUT);

    digitalWrite(RELAY_PIN, LOW);

    }

    void demo(){

    cr();

    lf();

    letter_shift();

    for (int i = 0; i < 34; i++){

    char_send('R');

    char_send('Y');

    }

    }

    void demo2(){

    int idx = 0;

    char demo_string[] = "THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG'S BACK 1234567890 TIMES";

    cr();

    lf();

    letter_shift();

    for (int i = 0; i < sizeof(demo_string); i++){

    char_send(demo_string[i]);

    }

    }

    void demo3(){

    int cur = 0;

    while (cur < 68) {

    if (Serial.available() > 0) {

    Serial.print(cur);

    Serial.print(": ");

    char_send(Serial.read());

    cur++;

    }

    }

    cr();

    lf();

    }

    void loop() {

    demo();

    demo2();

    //demo3();

    }

View all instructions

Enjoy this project?

Share

Discussions

studio8h wrote 08/28/2015 at 22:02 point

Thanks for this wonderful program. It got me started with Arduino, and best of all it has my Teletype Model 28 and Western Union 2-B humming nicely. Great job!

  Are you sure? yes | no

Ed Danis wrote 09/04/2015 at 02:07 point

Awesome! glad to help.  I'm working on another program for this project.  Do you remember Eliza?

https://en.wikipedia.org/wiki/ELIZA

  Are you sure? yes | no

Dale wrote 09/04/2014 at 13:15 point
Do you have a drawing on how you hooked up the relay board and power supply to the printer?

  Are you sure? yes | no

Ed Danis wrote 09/06/2014 at 23:39 point
Hi Dale, see the block diagram I added to the instructions. It's real simple. just put the relay in the loop using the Normally Closed (NC) terminals on the relay. Let me know if this is still confusing.

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

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