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.

keybrd_MCP23018_begin_hangs.no 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* this works on Teensy LC 1*bb, active low and active high
  2. MCP23018::begin() hangs, details in setup()
  3. | Layout | **0** | **1** |
  4. |:------:|-------|-------|
  5. | **0** | a | b |
  6. | **1** | c | d |
  7. */
  8. // ################## GLOBAL ###################
  9. // ================= INCLUDES ==================
  10. #include <Debug.h>
  11. //IOE Ports
  12. #include "IOExpanderPort.h"
  13. #include <RowPort_MCP23018.h>
  14. #include <ColPort_MCP23018.h>
  15. //Codes
  16. #include <Code_Sc.h>
  17. //Matrix
  18. #include <Row_uC.h>
  19. #include <Row_IOE.h>
  20. // =============== CONFIGURATION ===============
  21. const unsigned int RowBase::DELAY_MICROSECONDS = 500;
  22. //activeLow has diode cathode (band) on row
  23. //activeHigh has diode cathode (band) on col, and pull down resistors on cols
  24. //0=active low, 1= active high
  25. const bool RowScanner_PinsArray::activeHigh = 0;
  26. const bool RowScanner_PinsBitwise::activeHigh = 0;
  27. Debug debug;
  28. // ================= uC PINS =================
  29. uint8_t readPins[] = {14, 15};
  30. uint8_t READ_PIN_COUNT = sizeof(readPins)/sizeof(*readPins);
  31. // ================ IOE PORTS ================
  32. const uint8_t IOExpanderPort::ADDR = 0x20;
  33. IOExpanderPort portA(0, 0);
  34. RowPort_MCP23018 rowPort(portA);
  35. IOExpanderPort portB(1, 0);
  36. ColPort_MCP23018 colPort(portB, 1<<0 | 1<<1 );
  37. // =================== CODES ===================
  38. Code_Sc s_a(KEY_A);
  39. Code_Sc s_b(KEY_B);
  40. Code_Sc s_c(KEY_C);
  41. Code_Sc s_d(KEY_D);
  42. Code_Sc s_0(KEY_0);
  43. Code_Sc s_1(KEY_1);
  44. Code_Sc s_2(KEY_2);
  45. Code_Sc s_3(KEY_3);
  46. // ================= LEFT ROWS =================
  47. Key* ptrsKeys_L0[] = { &s_a, &s_b };
  48. Row_uC row_L0(0, readPins, READ_PIN_COUNT, ptrsKeys_L0);
  49. Key* ptrsKeys_L1[] = { &s_c, &s_d };
  50. Row_uC row_L1(1, readPins, READ_PIN_COUNT, ptrsKeys_L1);
  51. // ================= RIGHT ROWS ================
  52. Key* ptrsKeys_R0[] = { &s_0, &s_1 };
  53. Row_IOE row_R0(rowPort, 1<<0, colPort, ptrsKeys_R0);
  54. Key* ptrsKeys_R1[] = { &s_2, &s_3 };
  55. Row_IOE row_R1(rowPort, 1<<1, colPort, ptrsKeys_R1);
  56. // ################### MAIN ####################
  57. void setup()
  58. {
  59. Keyboard.begin();
  60. Wire.begin(); //Wire.begin() must be called before rowPort.begin() colPort.begin()
  61. //delay(1000); //time for OS to detect USB before printing
  62. Keyboard.print(F("activeState.ino "));
  63. debug.print_free_RAM();
  64. /* Teensy LC on 1*bb
  65. RowPort_MCP23018::begin() hangs
  66. ColPort_MCP23018::begin() sometimes hangs, sometimes prints after 6 seconds
  67. PCA9655E::begin()s works on 4*bb
  68. maybe hangs if IOE is not attached because endTransmission() waiting for confirmation??
  69. trouble shooting MCP23018::begin()s
  70. checked wiring against datasheets
  71. measured power and ground, 3.3 volts checks out
  72. !! next things to check could take days:
  73. test MCP23018 with Teensy 2.0, because it worked last year
  74. set Teensy 2.0 to 3.3 volts and test again
  75. try with PCA9655E instead of MCP23018 (works on 4*bb)
  76. might be solder joints on LC (I soldered it), try using other Teensy LC
  77. test MCP23018 on simple demo sketch /home/wolfv/Documents/Arduino/demo_keep/mcp23018_../
  78. test MCP23018 with signal analyzer
  79. //rowPort.begin(); //this breaks sketch, does not print "activeState.ino ", kb unresponsive
  80. //colPort.begin(RowScanner_PinsBitwise::activeHigh); //hanges for 6 seconds
  81. Keyboard.println(F(" after Port.begin()"));
  82. */
  83. }
  84. uint16_t next = 0;
  85. elapsedMillis elapsed;
  86. void loop()
  87. {
  88. row_L0.process();
  89. row_L1.process();
  90. //row_R0.process();
  91. //row_R1.process();
  92. /* used this when debugging MCP23018::begin() hangs
  93. if ( (next < 10) && (elapsed > 1000 * next) )
  94. {
  95. Keyboard.print(next);
  96. Keyboard.print(F(" "));
  97. next++;
  98. }
  99. */
  100. //delay(500);
  101. //Keyboard.println("");
  102. }