Shop OBEX P1 Docs P2 Docs Learn Events
Aide for mapping — Parallax Forums

Aide for mapping

Neurotic_NormanNeurotic_Norman Posts: 4
edited 2015-01-01 19:23 in BASIC Stamp
Hello everyone!

I'm working on a project converting an electric typewriter to function as a teletype for a Z80 computer. For this I've realized I'll need to map the keyboard, interpret the logic, and program the BSII to interface the "Teletype" with the serial terminal output. I felt it'd be best if I mapped the keyboard first, then the logic. Since I would like to expedite the process of mapping, I wanted to know how I could connect the sixteen leads from the typewriter to the BSII. My thought was depressing a key, and having one pin on the Stamp send out a pulse and having all the other pins look for a response. Each pin will pulse in sequence from 0 to 15. Then it would print which pin was the one connected to the output and which pin received the response. The problem is I don't know how to write the code for this, so I thought I'd ask for a little help.

Thanks bunches!

~James

Comments

  • PublisonPublison Posts: 12,366
    edited 2015-01-01 11:15
    Welcome to the forums!

    It's going to be asked, so I will ask it first.

    Is there an output from this device, (ie, Serial Parallel)?

    Are there sensors under each key? What typerwriter is it?
  • Neurotic_NormanNeurotic_Norman Posts: 4
    edited 2015-01-01 11:45
    Thank you!

    There is an input from the computer, which is a serial connection. The keyboard is set up in a matrix, so there are pads under each key but the only outputs are sixteen pins.

    The make/model is Brother GX-8250.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-01-01 12:35
    My thought was depressing a key, and having one pin on the Stamp send out a pulse and having all the other pins look for a response. Each pin will pulse in sequence from 0 to 15. Then it would print which pin was the one connected to the output and which pin received the response. The problem is I don't know how to write the code for this, so I thought I'd ask for a little help.

    If I get into a procrastinating mode (which happens much too often), I may give this a shot.

    Have you tested the lines (with a multimeter) to see which pins are connected electrically when the various keys are pressed?

    You'll probably need either pull-up or pull-down resistors on the lines being tested. If I may make a suggestion, have your matrix be normally pulled high and have the test line set low by the BS2. The other BS2 pins would then watch for a low pin. I make this suggestion because I think it would be a little easier to wire up a test matrix on the hardware I have handy (the PPDB has 8 active low buttons). It would be easy to switch to an active high rather than active low solution if that would work better for you.

    Hey other forum members, it won't hurt my feelings if someone else comes up with some test code first. My PBASIC is pretty rusty.
  • Mike GreenMike Green Posts: 23,101
    edited 2015-01-01 13:00
    Here's one example of a keyboard scanner for a 4x4 keypad (http://www.johnloomis.org/ece445/stamp/nv_mag/st_ap22.pdf). Have a look at the Nuts and Volts columns for other ideas. For example, you'll probably need more I/O pins. You may need to use an I/O expansion IC like the 74HC595 (output) or the 74HC165 (input). Some of the Nuts and Volts columns show how to do this.

    See: http://www.parallax.com/search?search_api_views_fulltext=nuts+and+volts
  • Neurotic_NormanNeurotic_Norman Posts: 4
    edited 2015-01-01 13:01
    I haven't done it with a multimeter. I was hoping to be able to expedite the mapping by using the BSII. If that cannot be done and the only option is manual testing, I'll brew a pot of coffee and do that. I'm afraid I don't know how the typewriter gathers the information from the matrix, so that'll be the next project.

    Thanks again!
  • Mike GreenMike Green Posts: 23,101
    edited 2015-01-01 13:07
    You need the multimeter to figure out how the keys are connected and what voltages are present. The manual for the typewriter says nothing about the internals of the typewriter. The keyboard could be connected any which way. Most likely the voltages present are 0V and 5V, but there's no guarantee of that and higher voltages could damage your Stamp if you don't allow for that.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-01-01 13:33
    I see Mike Green has pointed out some good sources of information.

    I'd think with 16 pins the BS2 should be able to handle scanning the keyboard without needing shift registers.

    I assumed the keyboard is laid out in an 8 x 8 matrix. This really isn't a safe assumption.

    I ran into trouble when I wanted to read the input pins in a FOR NEXT loop. I don't know how to make the input pin a variable.
    ' KeyMatrixTest150101a.BS2
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    OUTPUT_COUNT    CON     8
    INPUT_COUNT     CON     8
    FIRST_OUTPUT    CON     0
    FIRST_INPUT     CON     8
    NOT_VALID_INPUT CON     FIRST_INPUT + INPUT_COUNT
    
    outPin          VAR     Byte
    inPin           VAR     Byte
    activeOut       VAR     Byte
    activeIn        VAR     Byte
    testValue       VAR     Byte
    
    Main:
      DO
        DEBUG CR, "Please press a key on the matrix: "     ' prompt user
        activeIn = NOT_VALID_INPUT
        DO
          FOR outPin = FIRST_OUTPUT TO FIRST_OUTPUT + OUTPUT_COUNT - 1
            LOW outPin
            FOR inPin = FIRST_INPUT TO FIRST_INPUT + INPUT_COUNT - 1
              IF in[inPin] == 0 THEN
                activeIn = inPin
                activeOut = outPin
              ENDIF
            NEXT
            INPUT outPin
          NEXT
        LOOP UNTIL activeIn <> NOT_VALID_INPUT
    
        DEBUG CR, "The activeOut pin was # ", SDEC ? activeOut, " , the activeIn pin was # ", SDEC ? activeIn
        PAUSE 500                          ' wait half second
      LOOP                                  ' repeat forever
      END
    

    The line:
    IF in[inPin] == 0 THEN
    

    wouldn't compile.

    Is there a way to use the pin number as a variable?

    Do I need to use INS and then parse out the bits?

    I never spent a lot of time using the BS2 and it has been about five years since I've used it in my own projects.
  • Mike GreenMike Green Posts: 23,101
    edited 2015-01-01 13:57
    Try: IF INS & DCD inPin = 0 THEN
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-01-01 15:47
    Mike Green wrote: »
    Try: IF INS & DCD inPin = 0 THEN

    Thank you.

    I added your suggested code and I also decided to test all 15 pins instead of just 8. This way one doesn't need to know how the pins are used in the matrix to test them. I'd think this code should make figuring out the matrix a bit easier.

    The code requires each of the 16 pins to be pulled high.
    ' KeyMatrixTest150101c.BS2
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    OUTPUT_COUNT    CON     16
    INPUT_COUNT     CON     16
    FIRST_OUTPUT    CON     0
    FIRST_INPUT     CON     8
    NOT_VALID_INPUT CON     FIRST_INPUT + INPUT_COUNT
    
    outPin          VAR     Byte
    inPin           VAR     Byte
    activeOut       VAR     Byte
    activeIn        VAR     Byte
    testValue       VAR     Byte
    
    Main:
      DO
        DEBUG CR, "Please press a key on the matrix: "     ' prompt user
        activeIn = NOT_VALID_INPUT
        DO
          FOR outPin = FIRST_OUTPUT TO FIRST_OUTPUT + OUTPUT_COUNT - 1
            LOW outPin
            FOR inPin = FIRST_INPUT TO FIRST_INPUT + INPUT_COUNT - 1
              IF inPin <> outPin THEN
                 IF INS & DCD inPin = 0 THEN
                   activeIn = inPin
                   activeOut = outPin
                 ENDIF
               ENDIF
            NEXT
            INPUT outPin
          NEXT
        LOOP UNTIL activeIn <> NOT_VALID_INPUT
    
        DEBUG CR, "The activeOut pin was # ", SDEC ? activeOut, " , the activeIn pin was # ", SDEC ? activeIn
        PAUSE 500                          ' wait half second
      LOOP                                  ' repeat forever
      END
    

    Sorry, but I haven't tested it.

    I've attached the code to this post.
  • Neurotic_NormanNeurotic_Norman Posts: 4
    edited 2015-01-01 19:23
    Hello again everyone!

    So, to-day I went to test out the keyboard interface. I plugged it in, flipped the switch...

    and the motor burned out.

    So, I have saved the source code to use again when I find a new on which I may apply it.

    Sorry all this was rather for naught, but thanks again for all the help.
Sign In or Register to comment.