Skip to content

Commit a060f0a

Browse files
committed
add test and doc for SX1509 io expander
1 parent 8254c85 commit a060f0a

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

Test-SX1509-Sparkfun/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# SX1509 I/O Expander
2+
3+
See [MODULES](../MODULES.md) for other modules and for info about the SX1509
4+
5+
Things to know:
6+
* 3.3V max!
7+
* I2C address is `0x3E` by default (but might change depending on your breakout board!)
8+
9+
## Schema
10+
11+
![Schema](schema.png)
12+
13+
## Code
14+
15+
The code requires 2 libraries
16+
* Wire (for I2C communication)
17+
* SparkFunSX1509 for using the SX1509 itself
18+

Test-SX1509-Sparkfun/Sketch.fzz

4.6 KB
Binary file not shown.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <Arduino.h>
2+
#include <Wire.h> // Include the I2C library (required)
3+
#include <SparkFunSX1509.h> // Include SX1509 library
4+
5+
SX1509 io; // Create an SX1509 object
6+
7+
const int SX1509_BTN_PIN = 0;
8+
9+
void setup(){
10+
Serial.begin(9600);
11+
12+
// Try to connect to the i/o expander
13+
if (!io.begin(0x3E)) {
14+
Serial.println("SX1509 not connected");
15+
} else {
16+
Serial.println("SX1509 connected");
17+
}
18+
19+
// Configure pin 0 as input
20+
io.pinMode(SX1509_BTN_PIN, INPUT_PULLUP);
21+
}
22+
23+
24+
void loop(){
25+
26+
// Use io.digitalRead() to check if an SX1509 input I/O is either LOW or HIGH.
27+
if (io.digitalRead(SX1509_BTN_PIN) == LOW) {
28+
Serial.println("I/O Expander button pushed");
29+
while (io.digitalRead(SX1509_BTN_PIN) == LOW)
30+
; // Wait for button to release (this is blocking the program)
31+
}
32+
33+
}

Test-SX1509-Sparkfun/schema.png

264 KB
Loading

0 commit comments

Comments
 (0)