You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Example-05: I2C Expander with SparkFun Qwiic Directional Pad
2
+
3
+
This example demonstrates how to use the KeyDetector library with the SparkFun Qwiic Directional Pad, which uses a PCA9554 8-bit I2C GPIO expander chip.
4
+
5
+
## Hardware Requirements
6
+
7
+
- Arduino board (or any other compatible board like ESP32, ESP8266, etc.)
The SparkFun Qwiic Directional Pad can be connected to your Arduino/board in one of two ways:
14
+
15
+
### Option 1: Using Qwiic Connector (Recommended)
16
+
If your board has a Qwiic connector or you have a Qwiic shield, simply connect the D-Pad to your board using a Qwiic cable.
17
+
18
+
### Option 2: Manual I2C Connection
19
+
If your board doesn't have a Qwiic connector, connect the D-Pad to your board using the following connections:
20
+
21
+
- D-Pad GND → Arduino GND
22
+
- D-Pad 3.3V → Arduino 3.3V
23
+
- D-Pad SDA → Arduino SDA (A4 on most Arduinos)
24
+
- D-Pad SCL → Arduino SCL (A5 on most Arduinos)
25
+
26
+
## Button Mapping
27
+
28
+
The SparkFun Qwiic Directional Pad has 5 buttons mapped to the following pins on the PCA9554 chip:
29
+
30
+
- Up: Pin 4
31
+
- Down: Pin 5
32
+
- Left: Pin 6
33
+
- Right: Pin 7
34
+
- Center/Select: Pin 3
35
+
36
+
## Active Low Logic
37
+
38
+
The buttons on the D-Pad are active LOW, meaning they are pulled up by default and pressing them connects the pin to ground. This example takes care of this by setting the `pullup` parameter to `true` in the KeyDetector constructor.
39
+
40
+
## Features Demonstrated
41
+
42
+
This example demonstrates:
43
+
44
+
1. Implementation of the `I2CExpander` interface for the PCA9554 chip
45
+
2. Reading button states from the I2C expander
46
+
3. Detecting button press, release, and held states
47
+
4. Handling simultaneous button presses
48
+
5. Sending button events to the Serial monitor
49
+
50
+
## Serial Output
51
+
52
+
Open the Serial Monitor at 115200 baud to see the button press, release, and held events. The example will print:
53
+
- When a button is pressed
54
+
- When a button is released
55
+
- When a button is held down
56
+
- When multiple buttons are pressed simultaneously
57
+
58
+
## Troubleshooting
59
+
60
+
If the example doesn't work:
61
+
62
+
1. Check your I2C connections
63
+
2. Verify that the I2C address is correct (0x27 by default)
64
+
3. Make sure the D-Pad is properly powered (3.3V)
65
+
4. Check if your Arduino can communicate with the D-Pad using an I2C scanner sketch
66
+
67
+
## Further Customization
68
+
69
+
You can modify the example to:
70
+
- Change the debounce delay (currently 10ms)
71
+
- Adjust the key press and repeat delays
72
+
- Add custom actions for different button combinations
73
+
- Integrate with other I2C devices using the same Wire interface
0 commit comments