Typewriter Matrix

Dear all,
For the last days I have been trying to hack an old typewriter keyboard matrix and simulate the key presses through arduino.
On the board of typewriter there are two rows of pins. One with 8 pins and one with 11. Whenever one of the 8 is connected to one of the 11 pins, one character is typed with this electromechanical part of the machine. I managed to connect each of these pins to map down each combination. I soldered jumper cables on the board and I connected them to the arduino.
First tested with just one character ( one pin from the one row and one from the other) and worked fine as a key press simulator. Then added more from the one row combining it with just one of the other row and after having some issues it worked.
Now whenever I add more wires from the second row(doesnt matter wich one is wich) it stops working and types nothing.
My project until now is pretty simular to this one, though im trying to controll the typewriter only with an arduino (not plus a rasberry). Any ideas what might be the problem and it stops working when im adding more pins to the arduino? I also tryied using diodes but didn't change anything.
Any ideas what might be the problem and it stops working when im adding more pins to the arduino or what I should change?

Im quite new this world of electronics so apologies for obvious mistakes.
Here is an AI code that partly worked on my project.

Thanks :slight_smile:


#define NUM_ROWS 3
#define NUM_COLS 7

int rowPins[NUM_ROWS] = {A0, A1, A2};  // Row pins
int colPins[NUM_COLS] = {0, 1, 2, 3, 4, 5, 6};  // Column pins

char keyMap[NUM_ROWS][NUM_COLS] = {  
  {'Q', 'W', 'E', 'R', 'T', 'Y', 'U'},  // Row 1
  {'A', 'S', 'D', 'F', 'G', 'H', 'J'},  // Row 2
  {'Z', 'X', 'C', 'V', 'B', 'N', 'M'}   // Row 3
};

void setup() {
  Serial.begin(9600);  // Start serial communication

  // Initialize row pins as outputs
  for (int i = 0; i < NUM_ROWS; i++) {
    pinMode(rowPins[i], OUTPUT);
    digitalWrite(rowPins[i], LOW);  // Start with rows LOW
  }

  // Initialize column pins as inputs with pull-up resistors
  for (int i = 0; i < NUM_COLS; i++) {
    pinMode(colPins[i], INPUT_PULLUP);  // Use internal pull-up resistors
  }
}

void loop() {
  for (int row = 0; row < NUM_ROWS; row++) {
    digitalWrite(rowPins[row], HIGH);  // Activate one row at a time
    delay(10);  // Small delay for stability

    for (int col = 0; col < NUM_COLS; col++) {
      if (digitalRead(colPins[col]) == HIGH) {  // Key is pressed
        Serial.print("Key Pressed: ");
        Serial.println(keyMap[row][col]);  // Print the key

        delay(300);  // Debounce delay to avoid multiple detections
      }
      delay(100);  // Small delay after checking each column
    }

    digitalWrite(rowPins[row], LOW);  // Deactivate row
    delay(100);  // Small delay after scanning each row
  }
}

`

Have a look at the Adafruit_TCA8418, that is a dedicated chip to read out key matrices.
Might work.

This is your last question, but needs to be addressed first: You really must learn from the beginning.

Not "old"... "electric, daisywheel" ... "Old" are mechanical.

No doubt, garbage code. It can barely blink an LED without errors.

I'm sure the video used a RPi for a reason. Have you asked the author?

How do you add pins the an Arduino?

There is so much glossed-over information. Did you even understand this sentence at 3m26s?

3:26 Once I’ve done that, I just have to write some code to read the channels of the multiplexers

Its pretty much only for having a shell on a serial port.

Its like connecting a VT100 terminal to a serial port but instead of outputing on a crt its using paper.

The Arduino is "emulating" the VT100 side in this scenario.

The project in the video consists of two parts:

  • reading a keyboard matrix
  • writing to the typewriter

On which part are you focusing right now?

Or larger data buffer for slowly feeding the "picture" text?

There is no real need for a large buffer. The communication is using flow control. Just stop producing data for the serial port while the Arduino is not ready for receiving any more data.

I see.

Try this. It is my sketch for gamepad. Based on examples you can find here:
"Keypad/examples/MultiKey/MultiKey.ino at master · Chris--A/Keypad · GitHub"
It is very simple and works like charm...

/* @file MultiKey.ino
|| @version 1.0
|| @author Mark Stanley
|| @contact mstanley@technologist.com
||
|| @description
|| | The latest version, 3.0, of the keypad library supports up to 10
|| | active keys all being pressed at the same time. This sketch is an
|| | example of how you can get multiple key presses from a keypad or
|| | keyboard.
|| #
*/

#include <Keypad.h>
#include <Keyboard.h>

const byte ROWS = 5; //four rows
const byte COLS = 5; //three columns
char keys[ROWS][COLS] = {
    {'1','2','3','4','5'}, //2    0x81-left SHIFT (0x81 without quotations marks {0x81,'c','d','e','f'}, etc...)
    {'6','7','8','9','0'}, //3    0x80-left CTRL
    {0x81,'c','d','e','f'}, //4
    {'g','h','i','j','m'}, //5
    {'q','r','s','t','w'}, //6
  // 14  10   9   8   7
};

byte rowPins[ROWS] = {2, 3, 4, 5, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {14, 10, 9, 8, 7}; //connect to the column pinouts of the keypad

Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup() 
{
    // Serial.begin(9600);
}


void loop() 
{
    // Fills kpd.key[ ] array with up-to 10 active keys.
    // Returns true if there are ANY active keys.
    if (kpd.getKeys())
    {
        for (int i=0; i<LIST_MAX; i++)   // Scan the whole key list.
        {
            if ( kpd.key[i].stateChanged )   // Only find keys that have changed state.
            {
                switch (kpd.key[i].kstate) // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
                {  
                  case PRESSED:
                  Keyboard.press(kpd.key[i].kchar);
                  break;

                  //case HOLD:
                  //break;

                  case RELEASED:
                  Keyboard.release(kpd.key[i].kchar);
                  break;

                  //case IDLE:
                  // break;

                }

                Serial.print(kpd.key[i].kchar);

            }
        }
    }
}  // End loop

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.