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.

openDrain_activeLow.ino 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* simulate one scan of a key martix, on open-drain active-low I/O expander
  2. BREADBOARD SETUP *******************************
  3. Teensy LC connected to MCP23018 I/O expander via I2C
  4. 4.7k Ohm pullup resistors on SDA and SCL
  5. use volt meter to measure pin voltages
  6. MCP23018 has open-drain outputs (open-drain can only sink current)
  7. MCP23018 PIN DIAGRAM ***************************
  8. write port B read port A
  9. GND VSS 1 28 NC
  10. NC 2 27 GPA7
  11. jumper0 GPB0 3 26 GPA6
  12. GPB1 4 25 GPA5
  13. GPB2 5 24 GPA4 jumper4
  14. GPB3 6 23 GPA3
  15. jumper4 GPB4 7 22 GPA2
  16. GPB5 8 21 GPA1
  17. GPB6 9 20 GPA0 jumper0
  18. GPB7 10 19 INTA
  19. power VDD 11 18 INTB
  20. SCL SCL 12 17 NC
  21. SDA SDA 13 16 RESET power
  22. NC 14 15 ADDR GND
  23. */
  24. #include "Wire.h"
  25. const uint8_t ADDR = 0x20; //MCP23018 I2C address with ADDR pin 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 enabled
  43. Wire.endTransmission();
  44. // =================== scan ===================
  45. Serial.println("scan");
  46. Wire.beginTransmission(ADDR);
  47. Wire.write(0x13); //GPIOB output
  48. Wire.write(B00001111); //pins 0-3 off, pins 4-7 sink on (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=11101111
  56. }
  57. void loop() { }