USB IN to Parallel ASCII OUT

SolidWorksMagi

Senior Member
Hi,

I have an old keyboard chip for a Sol-20 computer. I want to make a simple little circuit with a PICAXE chip to take the standard USB keyboard and translate the keys to drive the Sol-20 computer keyboard chip. Essentially, 2022 USB to 1975 7-bit ASCII out.

I don't know how to read the USB signals from the modern regular USA 102-Key keyboards.

Once I know how to input the USB keyboard key strings, I'm fairly sure I can create a translation table to drive the Sol-20 keyboard chip for the 96 to 128 characters I need.
 

Buzby

Senior Member
I've never seen PICAXE code to handle USB inputs, and I suspect that is because USB is too fast and complex. Last time I looked the USB specification was 300 pages long !.

However, if you have an older keyboard with a PS/2 plug, PICAXE has commands for handling these.

See the keyboard commands in the manual here - https://picaxe.com/basic-commands/a-z/
 

Flenser

Senior Member
As Buzby said, you won't be using a PICAXE chip to convert directly from USB in to the SOL 20 7-bit ASCII out.

What you coulc certainly do using a PICAXE is to connect a USB-to-Serial converter, to a PICAXE chip and write a program to convert serial in to the PICAXE to the SOL 20 7-bit ASCII out.

This conversion will take some time which will limit the serial speed. You will get the best serial speed if you use HSERIN as this will give you the most time to do the conversion. Depending on what control signals there are in the SOL 20 serial interface the "convesion" might be as simple as reading a character using HSERIN and the writing that character to a byte port.
 

SolidWorksMagi

Senior Member
As Buzby said, you won't be using a PICAXE chip to convert directly from USB in to the SOL 20 7-bit ASCII out.

What you coulc certainly do using a PICAXE is to connect a USB-to-Serial converter, to a PICAXE chip and write a program to convert serial in to the PICAXE to the SOL 20 7-bit ASCII out.

This conversion will take some time which will limit the serial speed. You will get the best serial speed if you use HSERIN as this will give you the most time to do the conversion. Depending on what control signals there are in the SOL 20 serial interface the "convesion" might be as simple as reading a character using HSERIN and the writing that character to a byte port.

Hi,

Great idea. I have a USB to TTL converter, I should have thought of that myself. I only need 9600 BAUD so the PICAXE should be able to handle the rest.

The next trick is to convert from serial IN on the HSERIAL PIN to Port-B parallel data so I can create a map of the USB keyboard bits before writing the final program.
 
Last edited:

AllyCat

Senior Member
Hi,

A potential problem is that your "USB to TTL converter" connects a "Host" Computer to a "Slave" Keyboard, but it appears that you want to use the Keyboard as a Host. The Host/Slave architecture of USB is the reason why all the original USB cables employed different types of plug at each end (Type A, Type B, etc.). That's now made more confusing with the modern "micro" and "Type C" connectors used on mobile phones, but then mobile phones now are effectively complex computers.

At one time, there were some "dual mode" keyboards with USB and PS2 interfaces and an adapter which was purely "physical" (i.e. pins linked through). So I assume that these keyboards included hardware/software to automatically select PS2 (effectively a Host) or USB (Slave) modes, but I don't know if such devices are still available. You might find that you must use a "computer" with a USB Host capability (which PICaxe certainly hasn't got) such as a Raspberry Pi.

Cheers, Alan.
 

Flenser

Senior Member
SolidWorksMagi,

I was too hasty. Alan is correct.

The USB-to-Serial converter is used to convert data that is sent over a USB serial device, like a serial terminal on your computer, to data over a serial connection. My idea will not work as I've described it because a USB keyboard appears to your computer as something called a USB HID (Human Interface Device) and just connecting the two together will not work.

My apologies for the confusion.
 

hippy

Technical Support
Staff member
Yes, what is need is a "USB Host" module, which can take a USB Keyboard, Mouse, Gamepad or Joystick and convert it to serial or something else a PICAXE can actually use.

There are some USB to PS/2 adapters which can probably be used but the the passive ones won't if the keyboard itself doesn't support their use.
 

Flenser

Senior Member
Having stuffed up once I was a bit leery about posting again, but I couldn't help doing some more research.

There are some USB to PS/2 adapters which can probably be used but the the passive ones won't if the keyboard itself doesn't support their use.
A web search came up with one example of the type of USB Host modules Hippy describes that outputs serial:
You buy their "USB Host" module: https://www.hobbytronics.co.uk/usb-host-board-v24
And their software that you install to use that module to convert a USB keyboard to serial is free: https://www.hobbytronics.co.uk/usb-host-keyboard

I've not used this so I don't know how well it works.
I haven't searched any further so I don't know if they are available any cheaper.

Then you still need to use a PICAXE to convert the serial to 7-bit ASCII.

BUT, if you can source a PS/2 keyboard cheaper than one of these "USB Host" modules then RevEd appear to already have you covered with this circuit for reading a PS/2 keyboard just using a PICAXE chip https://picaxe.com/circuit-creator/miscellaneous/ps2-keyboard/.
You'll need to expand the example code to output the correct protocol for the 7-bit ASCII you describe.
 

SolidWorksMagi

Senior Member
Hi,

Although I have an old PS/2 keyboard, I want to make something that I can use the cheaper USD $3 keyboards to make a USB connection since they're for sale all over the place.

I may have to go visit a thrift store and buy up a hand-full of older PS/2 keyboards.

OTOH, I don't know why something like this can't work for a USB keyboard just adding a female to female adapter; (I already have them both for testing stuff anyway)

It's something I'll try as soon as I'm done testing a VT-132 board that's not working 100%.
 

papaof2

Senior Member
That device plugs into a USB Master (PC) and provides serial output. The USB keyboard is a Slave so that device does NOT work with a keyboard.
 

oracacle

Senior Member
I would suggest you watch: How does a USB keyboard work? - YouTube
There is alot going on with USB. For starters that USB keyboard has to be initiated by the host machine, it also has to be pinged before it will send anything to the bus. I have no idea how a USB to TTL converter will handle that, or how easy it will be to get one that will be a host, ie you plug the USB into it.
you may also want to look into soemething like: Arduino USB Host Shield | Arduino Documentation | Arduino Documentation
I don't know if the PICAXE SPI is compatable as i have neve used anything like this. There are other USB host sheilds about which may fit the bill better. Each and every one of them will need have their data sheets read carefully.
 

SolidWorksMagi

Senior Member
Hi,

I'ts worth giving it a try ... The KBIN command examples a keyboard connection direct to the PICAXE chip ... it's a PS/2 keyboard and I have one so I'll try that first to see what I get, then I can try the USB keyboard with the USB-to-TTL adapter to see what I get. It either works or it doesn't ... no big deal.

I would like to buy one of those little boards from the UK, but I have to go with what I have ... it comes down to affordability for a very meager pension.

25465
 

Flenser

Senior Member
I would like to buy one of those little boards from the UK, but I have to go with what I have ..
For something as simple as this and for testing if it works I'd solder it out on a stripboard.first.
You don't need to worry about getting a PCB until you know which version you are going to go with and even then for a one-off I'd end up using the stripboard version.
 

SolidWorksMagi

Senior Member
For something as simple as this and for testing if it works I'd solder it out on a stripboard.first.
You don't need to worry about getting a PCB until you know which version you are going to go with and even then for a one-off I'd end up using the stripboard version.
Hi,

I'm using my RoboGuts™ circuit board for the experiments, then IF it works well, I may design a specific board for the project.
 

SolidWorksMagi

Senior Member
Having stuffed up once I was a bit leery about posting again, but I couldn't help doing some more research.


A web search came up with one example of the type of USB Host modules Hippy describes that outputs serial:
You buy their "USB Host" module: https://www.hobbytronics.co.uk/usb-host-board-v24
And their software that you install to use that module to convert a USB keyboard to serial is free: https://www.hobbytronics.co.uk/usb-host-keyboard

I've not used this so I don't know how well it works.
I haven't searched any further so I don't know if they are available any cheaper.

Then you still need to use a PICAXE to convert the serial to 7-bit ASCII.

BUT, if you can source a PS/2 keyboard cheaper than one of these "USB Host" modules then RevEd appear to already have you covered with this circuit for reading a PS/2 keyboard just using a PICAXE chip https://picaxe.com/circuit-creator/miscellaneous/ps2-keyboard/.
You'll need to expand the example code to output the correct protocol for the 7-bit ASCII you describe.

Hi,

I bought the usb-host-board-v24 ... https://www.hobbytronics.co.uk/usb-host-board-v24 and I'm trying to figure out how to see the data from the device in the debug screen using the KBIN command. I can see the key bytes on my oscilloscope, but not on the debug for the 20M2 chip.

What PINs should I be using from the usb-host-board-v24 to the 20M2 chip?




25472

+5V and GND I got, I tried TX (scope shows activity there) to C.1

; 20M2 C.1 C.2

; |---------U---------|
; V+ | 1 20|
; SerIN | 2 19| SerOUT
; ADC I/O | 3 C.7 B.0 18| I/O
; IN | 4 C.6 B.1 17| I/O
; I/O | 5 C.5 B.2 16| I/O
; I/O | 6 C.4 B.3 15| I/O
; I/O | 7 C.3 B.4 14| I/O
; KB clk I/O | 8 C.2 B.5 13| I/O hi2c SDA
;KB data I/O | 9 C.1 B.6 12| I/O hserin
;hserout I/O |10 C.0 B.7 11| I/O hi2c SCL
; |-------------------|
 

Buzby

Senior Member
The module you have converts the USB signals from the keyboard into serial or I2C that the PICAXE can then read.

To test the module, use a scope to monitor the RX and TX pins on the module. Do this without the PICAXE connected.

When you determine that data is comming out of one of the RX/TX pins on the module, you can connect that pin to a serial input pin on the PICAXE.

You can then use SERIN or HSERIN to read the data. You do not use KBDIN, as the module is not providing PS/2.

All the above assumes you have bought the keyboard version of the module, and not the MIDI version, or mouse, or empty !.
 

oracacle

Senior Member
Since it says usb host and nothing directly for keyboards I would follow buzbys advice. It appears that it can be configured to be a USB host of any description.
 

hippy

Technical Support
Staff member
All the above assumes you have bought the keyboard version of the module, and not the MIDI version, or mouse, or empty !.
Assuming the data being seen on TX occurs when a keyboard is plugged in, a key pressed or released, I would assume it is pre-programmed as a keyboard host. Firmware for something else shouldn't enumerate a keyboard as being for it.

What PINs should I be using from the usb-host-board-v24 to the 20M2 chip?
You should only need to connect +5V, GND/0V and TX from the board to an input pin on the PICAXE.

I would suggest using an X2 and that input being HSERIN so you can use background serial receive. It might work with SERIN but depends on baud rate and what the module actually puts out.

As you can see something on the scope when a key is pressed you should be able to measure the bit time and determine the baud rate from that. And also be able to see how many bytes are sent per key press or release. That's probably also in the documentation but I didn't spot a link for that.
 

Flenser

Senior Member
All the above assumes you have bought the keyboard version of the module, and not the MIDI version, or mouse, or empty !.
Buzby,

This looks to be a really nice product becuase while you specify which version of software you want preinstalled when you purchase the host module all the other versions of the software for this module are available for you to download for free and update the module yourself using a downloader program also available for free on the site.

SolidWorksMagi,

The instructions for the USB Keyboard of the software are available on this page. The default baud rate is 9600 and it uses true logic by default.

If I've understood correctly and you specified the USB Keyboard software when you ordered it then to test it out you should be able to connect the TX and ground pins from the USB Host module to your PICAXE and write a simple program that waits for a serial byte at T9600_<your freq> and transmits it to the PE terminal using sertxd.

Start out with just the alphanumeric characters for this test (which are all ASCII characters) and then read the doco for recognizing the function keys and the CRTL-key combinations (which are sent as two character combinations because these are not ASCII characters) and the ALT-key combinations (which are sent as non-printing ASCII characters).

You use the RX connection to send commands to the USB Host Module to alter it's configuration.
 

hippy

Technical Support
Staff member
The instructions for the USB Keyboard of the software are available on this page. The default baud rate is 9600 and it uses true logic by default.
Thanks for finding that page and I would also start how you suggested ...
Code:
#Picaxe 20M2
#Terminal 38400
#No_Data

Symbol RX   = C.1
Symbol FREQ = M32
Symbol BAUD = T9600_32

Init:
  SetFreq FREQ

MainLoop:
  Do
    SerIn RX, BAUD, b0
    b2 = b0 / $10 : b2 = b2 / 10 * 7 + b2 + "0"
    b1 = b0 & $0F : b1 = b1 / 10 * 7 + b1 + "0"
    If b0 >= $20 And b0 <= $7E Then
      SerTxd( "Got $", b2, b1, " '", b0, "'", CR, LF )
    Else
      SerTxd( "Got $", b2, b1, CR, LF )
    End If 
  Loop
 

SolidWorksMagi

Senior Member
Hi,

Finally got back to this project. Connected the Tx PIN OUT to the 20M2 PIN 12 = B.6
Then hserin w1 and a CASE statement for the capital letters, numbers and special characters.

Next time I get into the project I'll have a gosub to send parallel data out the B.0 to B.5 and B.7 for 7-bit characters to drive a vintage Processor Technology Sol-20 keyboard chip connected to start identifying what characters goto what characters.

Hopefully, this will be Apple I compatible as well as other vintage computers, but if not, then it's just changing the CASE gosubs.
 
Top