keybrd library is an open source library for creating custom-keyboard firmware.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

source_activeLow.ino 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* simulate one scan of a key martix, on source active-low I/O expander
  2. BREADBOARD SETUP *******************************
  3. Teensy LC connected to MCP23017 I/O expander via I2C
  4. 4.7k Ohm pullup resistors on SDA and SCL
  5. use volt meter to measure pin voltages
  6. MCP23017 PIN DIAGRAM ***************************
  7. write port B read port A
  8. jumper0 GPB0 1 26 GPA7
  9. GPB1 2 25 GPA6
  10. GPB2 3 24 GPA5
  11. GPB3 4 23 GPA4 jumper4
  12. jumper4 GPB4 5 22 GPA3
  13. GPB5 6 21 GPA2
  14. GPB6 7 20 GPA1
  15. GPB7 8 19 GPA0 jumper0
  16. power VDD 9 18 INTA
  17. GND VSS 10 28 INTB
  18. NC 11 27 RESET power
  19. SCL SCL 12 17 A2 gnd
  20. SDA SDA 13 16 A1 gnd
  21. NC 14 15 A0 gnd
  22. */
  23. #include "Wire.h"
  24. const uint8_t ADDR = 0x20; //MCP23017 I2C address with all ADDR pins grounded
  25. void setup()
  26. {
  27. delay(1000); //time for Serial print to work
  28. // ================= configure ================
  29. Serial.print("config ");
  30. Wire.begin();
  31. Wire.beginTransmission(ADDR);
  32. Wire.write(0x01); //IODIRB Configure
  33. Wire.write(0); //as output
  34. Wire.endTransmission();
  35. Wire.beginTransmission(ADDR);
  36. Wire.write(0x00); //IODIRA Configuration
  37. Wire.write(~0); //as input
  38. Wire.endTransmission();
  39. Wire.beginTransmission(ADDR);
  40. Wire.write(0x0C); //GPPUA pull-up
  41. Wire.write(~0); //pull-up enabled
  42. Wire.endTransmission();
  43. // =================== scan ===================
  44. Serial.println("scan");
  45. Wire.beginTransmission(ADDR);
  46. Wire.write(0x13); //GPIOB output
  47. Wire.write(B00001111); //pins 0-3 power (strobe, LED on), pins 4-7 ground
  48. Wire.endTransmission();
  49. Wire.beginTransmission(ADDR);
  50. Wire.write(0x12); //GPIOA (immediately before requestFrom)
  51. Wire.endTransmission();
  52. Wire.requestFrom(ADDR, static_cast<uint8_t>(1)); //request one byte from GPIOA read
  53. Serial.print("portA=");
  54. Serial.println(Wire.read(), BIN); //prints portA=11101111
  55. }
  56. void loop() { }