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.

PCA9655E_1_write_read.ino 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* PCA9655E_1_write_read.ino
  2. set port 1 pins
  3. read and print value of port 0
  4. measure port 1 pin voltages with a multimeter
  5. DESTINATION PIN PIN_NUMBER PIN DESTINATION
  6. x INT 1 24 VDD Teensy LC 3.3V
  7. SCL AD1 2 23 SDA Teensy LC 18
  8. GND AD2 3 22 SCL Teensy LC 19
  9. GND IO0_0 4 21 AD0 SCL
  10. GND IO0_1 5 20 IO1_6 x
  11. VDD IO0_2 6 19 IO1_5 x
  12. VDD IO0_3 7 18 IO1_4 x
  13. GND IO0_4 8 17 IO1_4 x
  14. GND IO0_5 9 16 IO1_3 x
  15. x IO0_6 10 15 IO1_2 x
  16. x IO0_7 11 14 IO1_1 x
  17. GND VSS 12 13 IO1_0 x
  18. */
  19. #include "Wire.h"
  20. const uint8_t ADDR = 0x18; //I2C address with AD2=GND AD1=SCL AD0=SCL
  21. void setup()
  22. {
  23. delay(1000);
  24. Serial.print("PCA9655E_1_read.ino");
  25. Wire.begin();
  26. //Configure port 1 to output
  27. Wire.beginTransmission(ADDR);
  28. Wire.write(7); //configure direction
  29. Wire.write(0); //0=output
  30. Wire.endTransmission();
  31. Wire.beginTransmission(ADDR);
  32. Wire.write(3); //command byte 3 = Output Port 1
  33. Wire.write( 1<<2 | 1<<3); //1=high
  34. Wire.endTransmission();
  35. //Configure port 0 to input
  36. Wire.beginTransmission(ADDR);
  37. Wire.write(6); //command byte 6 = Configuration dir Port 0
  38. Wire.write(~0); //1=input
  39. Wire.endTransmission();
  40. Wire.beginTransmission(ADDR);
  41. Wire.write(0); //command byte 0 = Input Port 0
  42. Wire.endTransmission(false); //PCA9655E needs false to send a restart
  43. Wire.requestFrom(ADDR, 1u); //request one byte from input port
  44. Serial.print(" port0_val= ");
  45. uint8_t port0_val = Wire.read();
  46. Serial.print(port0_val, BIN); //expect xx001100
  47. }
  48. void loop() { }