Difference between revisions of "TinyPS2"

From Land Boards Wiki
Jump to navigation Jump to search
 
(65 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[File:TinyPS2_P899_cropped-720px.jpg]]
+
See [[TinyPS2 Revs 1-3]] for ATTiny85 based build
 +
 
 +
[[File:TinyPS2_Front_Rev4_3D.png]]
 +
 
 +
== Introduction ==
 +
 
 +
It is getting difficult to find ASCII serial keyboards for use in Retro-Computer projects. This card fills that need. The card is a PS/2 keyboard to TTL Level Serial adapter. PS/2 keyboards are still widely available.
 +
 
 +
[[file:Keyboard_PS2_MicrosoftNatural.jpg]]
  
 
== Features ==
 
== Features ==
  
* PS/2 keyboard or mouse to TTL Level Serial converter based on [https://www.smbaker.com/ps2-ttlserial-adapter-for-rc2014-and-midi Scott Baker BLOG]
+
* [[QT_Py_(RP2040_based)|QT Py (RP2040 based)]]
* [https://www.microchip.com/en-us/product/ATtiny85 ATTiny85 8-bit CPU]
+
** Run at 125 MHz
** Run at 8 MHz in this use-case
+
** 2MB of In System Programmable (ISP) flash
** 8 KB of In System Programmable (ISP) flash
+
** 264KB of SRAM
** 8-MHz internal RC oscillator that can be used as the default clock
+
* 115,200 baud serial
** 512 bytes of EEPROM
+
** 57,600-250,000 are build time options
** 512 bytes of SRAM
 
* 115,200 baud
 
 
* 49x49mm ODAS form factor
 
* 49x49mm ODAS form factor
* 4-40 mounting holes
+
* (4) 4-40 mounting holes
 
* 3.3V or 5V operation
 
* 3.3V or 5V operation
 
* Current measurement
 
* Current measurement
** 1 mA @ 5V (without keyboard)
+
** TBD @ 5V (without keyboard)
** 13 mA @ 5V (including keyboard)
+
** TBD @ 5V (including keyboard)
** 8mA @ 3.3V (including keyboard)
+
** TBD @ 3.3V (including keyboard)
*** Requires a keyboard that works at 3.3V
+
*** Does not require a keyboard that works at 3.3V
 +
 
 +
=== CPU Connections ===
  
=== TinyPS2 Connections ===
+
[[file:TinyPS2_CPU_Rev4_Conns.PNG]]
  
[[file:TinyPS2_CPU_Pins.PNG]]
+
<pre>
 +
#define DATAPIN 27
 +
#define IRQPIN  26
 +
</pre>
  
 
== Connectors ==
 
== Connectors ==
Line 28: Line 39:
 
=== J1 - TTL Serial Connector ===
 
=== J1 - TTL Serial Connector ===
  
[[file:TinyPS2_J1.PNG]]
+
[[file:TinyPS2_J1_Rev4_Conns.PNG]]
  
# VCC (nearest to J1 silkscreem)
+
# VCC (pin nearest to J1 silkscreem)
 
# SERTX
 
# SERTX
 
# N/C
 
# N/C
Line 39: Line 50:
 
* Standard PS/2 Mini-DIN-6 connector
 
* Standard PS/2 Mini-DIN-6 connector
  
[[file:TinyPS2_J2_kbd.PNG]]
+
[[file:TinyPS2_J2_Rev4_Conns.PNG]]
 
 
=== H2 - In-System Programming Header ===
 
 
 
[[file:ICSP.PNG]]
 
 
 
* SPI connector to download ATTiny85
 
* 2x3 header
 
* Program ATTiny85 without PS/2 keyboard attached
 
* Pinout
 
 
 
# KBCLK
 
# VCC
 
# SERTX
 
# KBDAT
 
# RST*
 
# GND
 
 
 
== Firmware ==
 
 
 
* [https://github.com/land-boards/lb-Arduino-Code/tree/master/LBCards/TinyPS2 GitHib Repo for TinyPS2 Firmware]
 
 
 
[[file:ATtiny45-85.png]]
 
 
 
=== Scott Baker's build ===
 
 
 
* [https://www.smbaker.com/ps2-ttlserial-adapter-for-rc2014-and-midi Scott Baker's Build BLOG page]
 
 
 
<video type="youtube">cSaBCtcUoq4</video>
 
 
 
* [https://github.com/sbelectronics/ps2-ttlserial Scott's GitHub page]
 
** Scott appears to have used [https://obdev.at/products/crosspack/index.html Crosspack] for AVR software development
 
* Scott uses two libraries from other projects
 
** [https://github.com/thegaragelab/tinytemplate ATTiny85 UART Library] - The Garage Lab
 
*** [https://github.com/thegaragelab/tinytemplate/blob/master/firmware/shared/uart_send.c uart_send.c]
 
** [http://www.nerdkits.com/videos/interrupts_and_ps2_keyboard/ Interrupts: Interfacing a Microcontroller with a PS/2 Keyboard] - PS/2 Keyboard Library
 
* Scott has hex file
 
** FUSES = -U lfuse:w:0x62:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m
 
** Downloaded using [[TL866ii_Plus_Programmer|TL866i]]
 
** Used Fuse bits from  Programmer
 
*** Matched lfuse values already
 
  
==== Tested Scott's Build ====
+
== Firmware Build Card Rev 4 ==
  
* Works really well
+
[[file:asciifull.png]]
* 115,200 baud
 
* Works at 3.3V or 5V
 
** Drops out around 3.15V - may need BOD bit changed?
 
  
=== TinyPS2V01 (Arduino UNO) ===
+
=== Arduino ===
  
* Tried replacing Scott's code with "standard" Arduino code with a lot of issues
+
* Card rev 4 uses a QTPy or XAIO RP2040 CPU
* First cut used libraries
+
* Arduino Library
** [https://www.pjrc.com/teensy/td_libs_PS2Keyboard.html PJRC PS/2 library]
+
** [https://github.com/techpaul/PS2KeyAdvanced PS2KeyAdvanced]
** [https://github.com/land-boards/lb-Arduino-Code/tree/master/LBCards/TinyPS2/TinyPS2V01 Read PS/2 print to screen]
+
* [https://github.com/land-boards/lb-Arduino-Code/blob/master/LBCards/TinyPS2/TinyPS2_PCB_Rev4_AdvKbd/TinyPS2_PCB_Rev4_AdvKbd.ino TinyPS2_PCB_Rev4_AdvKbd] - code
* Resources (Arduino UNO)
 
 
<pre>
 
<pre>
Sketch uses 3334 bytes (10%) of program storage space. Maximum is 32256 bytes.
+
#define DATAPIN 27
Global variables use 377 bytes (18%) of dynamic memory, leaving 1671 bytes for local variables. Maximum is 2048 bytes.
+
#define IRQPIN  26
 
</pre>
 
</pre>
* Issues "likely" due to single interrupt in ATTiny85
 
** Can't use Arduino libraries without conflict
 
** Both [https://docs.arduino.cc/learn/built-in-libraries/software-serial Arduino SoftSerial] and [https://www.arduino.cc/reference/en/libraries/ps2keyboard/ PS/2 routines] use this same interrupt
 
 
=== TinyPS2V02 ===
 
 
* Read PS/2 keyboard, write Serial (9600 baud)
 
* [https://www.pjrc.com/teensy/td_libs_PS2Keyboard.html PJRC PS/2 library]
 
* [https://docs.arduino.cc/learn/built-in-libraries/software-serial Software Serial library]
 
* [https://github.com/land-boards/lb-Arduino-Code/tree/master/LBCards/TinyPS2/TinyPS2V02 Main sketch]
 
** Didn't run when first tried
 
** Maybe PS2Keyboard library does not work on ATTiny85?
 
*** Proper interrupt support for ATTiny85?
 
* [https://thewanderingengineer.com/2014/08/11/pin-change-interrupts-on-attiny85/ Pin Change Interrupts on ATtiny85]
 
* Verified KBD data, clocks are reaching ATTiny85
 
* Code
 
<pre>
 
#include <SoftwareSerial.h>
 
#include <PS2Keyboard.h>
 
 
const int DataPin = 0;
 
const int IRQpin =  1;
 
 
#define rxPin 3
 
#define txPin 2
 
 
// Set up SoftwareSerial and PS/2 objects
 
SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
 
PS2Keyboard keyboard;
 
  
void setup() {
+
* Example code produces warning
  
  pinMode(rxPin, INPUT);
 
  pinMode(txPin, OUTPUT);
 
  mySerial.begin(9600);
 
 
 
  keyboard.begin(DataPin, IRQpin);
 
}
 
 
void loop() {
 
  if (keyboard.available())
 
  {
 
   
 
    // read the next key
 
    char c = keyboard.read();
 
    mySerial.write(c);
 
  }
 
}
 
</pre>
 
* Resources (ATTiny85)
 
 
<pre>
 
<pre>
Sketch uses 3126 bytes (38%) of program storage space. Maximum is 8192 bytes.
+
WARNING: library PS2KeyAdvanced claims to run on avr, sam, samd1, stm32, esp32 architecture(s) and may be incompatible with your current board which runs on rp2040 architecture(s).
Global variables use 241 bytes (47%) of dynamic memory, leaving 271 bytes for local variables. Maximum is 512 bytes.
+
Sketch uses 82336 bytes (0%) of program storage space. Maximum is 16777216 bytes.
 +
Global variables use 43096 bytes (15%) of dynamic memory, leaving 227240 bytes for local variables. Maximum is 270336 bytes.
 
</pre>
 
</pre>
  
=== TinyPS2V03 ===
+
* Code works well!
 
 
* Test routine
 
** Sends out A-Z in serial line at 9600 baud (~100uS bit time)
 
* [https://docs.arduino.cc/learn/built-in-libraries/software-serial Software Serial library]
 
** Verifies SoftwareSerial works
 
 
 
* Test with [https://github.com/land-boards/lb-Arduino-Code/tree/master/LBCards/TinyPS2/TinyPS2V04 TinyPS04 sketch]
 
** 2 mS off/on on serial output pin verifies delay(2)
 
*** Caught missing bootloader (sets speed fuses)
 
 
 
=== TinyPS04 ===
 
  
* Test with [https://github.com/land-boards/lb-Arduino-Code/blob/master/LBCards/TinyPS2/TinyPS2V03/TinyPS2V03.ino TinyPS04 sketch]
+
=== C++ ===
* Toggle serial output line every 2 mS
 
* Verifies delay(2)
 
  
=== TinyPS05 ===
+
* [https://github.com/tvlad1234/pico-ps2Driv pico-ps2Driv] - SDK C code
  
* Intent: Verify interrupt from keyboard does not conflict with Software Serial
+
=== CircuitPython ===
* Toggles serial out line if char comes in
 
* Never toggles
 
  
== Programming Card ==
+
* CircuitPython support issues
 +
** [https://docs.circuitpython.org/en/latest/shared-bindings/ps2io/index.html PS/2 Library] - Not in Pico core modules
  
* [http://highlowtech.org/?p=1695 Programming procedure is taken from here]
 
* Add ATTiny Board support to Preferences, Path:
 
 
<pre>
 
<pre>
https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json
+
>>> import ps2io
 
+
Traceback (most recent call last):
 +
  File "<stdin>", line 1, in <module>
 +
ImportError: no module named 'ps2io'
 
</pre>
 
</pre>
* Select ATTiny85, 8 Mhz
 
* '''Burn bootloader''' - Otherwise clock is way off
 
 
[[File:Arduino_IDE_ATTiny85.png]]
 
 
* [[ATProgHead]]
 
** Running Arduino as ISP
 
 
== Other People's Videos ==
 
 
* [https://www.smbaker.com/ps2-ttlserial-adapter-for-rc2014-and-midi Scott Baker's Build]
 
 
<video type="youtube">cSaBCtcUoq4</video>
 
 
<video type="youtube">PmJlDlI-Pb4</video>
 
  
 
== Schematic ==
 
== Schematic ==
Line 207: Line 99:
 
== Issues ==
 
== Issues ==
  
* Missing pull-up resistors on PS/2
+
* [[TinyPS2_Revs_1-3|Revs 1-3 are documented here]]
** Rev 2 - add pull-up resistors
+
 
** (There's pullups in the part so this may not be needed)
+
=== Rev 4 ===
* Missing C3 cap in sequence
+
 
** Rev 2 - change C4 => C3
+
* Changed CPU
 +
** Was 8 MHz ATTiny85
 +
** Changed to QT PY or XAIO
 +
* Changed pin usage
 +
* Uses Hardware Transmitter in CPU
 +
* Keyboard runs at 5V
 +
* CPU runs at 3.3VV
 +
* 3.3V to 5V level shifter
  
 
== Assembly Sheet ==
 
== Assembly Sheet ==
  
* [[TinyPS2 Assembly Sheet]]
+
* [[TinyPS2 Rev 4 Assembly Sheet]]

Latest revision as of 16:51, 15 August 2022

See TinyPS2 Revs 1-3 for ATTiny85 based build

TinyPS2 Front Rev4 3D.png

Introduction

It is getting difficult to find ASCII serial keyboards for use in Retro-Computer projects. This card fills that need. The card is a PS/2 keyboard to TTL Level Serial adapter. PS/2 keyboards are still widely available.

Keyboard PS2 MicrosoftNatural.jpg

Features

  • QT Py (RP2040 based)
    • Run at 125 MHz
    • 2MB of In System Programmable (ISP) flash
    • 264KB of SRAM
  • 115,200 baud serial
    • 57,600-250,000 are build time options
  • 49x49mm ODAS form factor
  • (4) 4-40 mounting holes
  • 3.3V or 5V operation
  • Current measurement
    • TBD @ 5V (without keyboard)
    • TBD @ 5V (including keyboard)
    • TBD @ 3.3V (including keyboard)
      • Does not require a keyboard that works at 3.3V

CPU Connections

TinyPS2 CPU Rev4 Conns.PNG

#define DATAPIN 27
#define IRQPIN  26

Connectors

J1 - TTL Serial Connector

TinyPS2 J1 Rev4 Conns.PNG

  1. VCC (pin nearest to J1 silkscreem)
  2. SERTX
  3. N/C
  4. GND

J2 - PS/2

  • Standard PS/2 Mini-DIN-6 connector

TinyPS2 J2 Rev4 Conns.PNG

Firmware Build Card Rev 4

Asciifull.png

Arduino

#define DATAPIN 27
#define IRQPIN  26
  • Example code produces warning
WARNING: library PS2KeyAdvanced claims to run on avr, sam, samd1, stm32, esp32 architecture(s) and may be incompatible with your current board which runs on rp2040 architecture(s).
Sketch uses 82336 bytes (0%) of program storage space. Maximum is 16777216 bytes.
Global variables use 43096 bytes (15%) of dynamic memory, leaving 227240 bytes for local variables. Maximum is 270336 bytes.
  • Code works well!

C++

CircuitPython

  • CircuitPython support issues
>>> import ps2io
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: no module named 'ps2io'

Schematic

Issues

Rev 4

  • Changed CPU
    • Was 8 MHz ATTiny85
    • Changed to QT PY or XAIO
  • Changed pin usage
  • Uses Hardware Transmitter in CPU
  • Keyboard runs at 5V
  • CPU runs at 3.3VV
  • 3.3V to 5V level shifter

Assembly Sheet