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_activeHigh.ino 2.6KB

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