Skip to content

Commit 3d8298d

Browse files
committed
Some wemos examples from
http://nopnop2002.webcrow.jp
1 parent 0dc02aa commit 3d8298d

File tree

3 files changed

+123
-1
lines changed

3 files changed

+123
-1
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ Tutorial:
44

55
To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder PCF8574. Check that the PCF8574 folder contains `PCF8574\\.cpp` and `PCF8574.h`. Place the DHT library folder your `<arduinosketchfolder>/libraries/` folder. You may need to create the libraries subfolder if its your first library. Restart the IDE.
66

7-
# Reef complete PCF8574 digital input and output expander with i2c bus.
7+
# Reef complete PCF8574 PCF8574AP digital input and output expander with i2c bus.
88
I try to simplify the use of this IC, with a minimal set of operation.
99

10+
PCF8574P address map 0x20-0x27
11+
PCF8574AP address map 0x38-0x3f
12+
1013
Constructor:
1114
you must pas the address of i2c (to check the adress use this guide [I2cScanner](https://playground.arduino.cc/Main/I2cScanner))
1215
```cpp
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* PCF8574 GPIO Port Expand
3+
* http://nopnop2002.webcrow.jp/WeMos/WeMos-25.html
4+
*
5+
* PCF8574 ----- WeMos
6+
* A0 ----- GRD
7+
* A1 ----- GRD
8+
* A2 ----- GRD
9+
* VSS ----- GRD
10+
* VDD ----- 5V/3.3V
11+
* SDA ----- GPIO_4
12+
* SCL ----- GPIO_5
13+
* INT ----- GPIO_13
14+
*
15+
* P0 ----------------- BUTTON0
16+
* P1 ----------------- BUTTON1
17+
* P2 ----------------- BUTTON2
18+
* P3 ----------------- BUTTON3
19+
* P4 ----------------- BUTTON4
20+
* P5 ----------------- BUTTON5
21+
* P6 ----------------- BUTTON6
22+
* P7 ----------------- BUTTON7
23+
*
24+
*/
25+
26+
#include "Arduino.h"
27+
#include "PCF8574.h" // https://github.com/xreef/PCF8574_library
28+
29+
#define ESP8266_INTERRUPTED_PIN 13
30+
31+
// Set i2c address
32+
PCF8574 pcf8574(0x20);
33+
34+
// Function interrupt
35+
bool keyPressed = false;
36+
37+
void keyPressedOnPCF8574(){
38+
// Serial.println("keyPressedOnPCF8574");
39+
keyPressed = true;
40+
}
41+
42+
void setup()
43+
{
44+
Serial.begin(9600);
45+
pinMode(ESP8266_INTERRUPTED_PIN, INPUT_PULLUP);
46+
attachInterrupt(digitalPinToInterrupt(ESP8266_INTERRUPTED_PIN), keyPressedOnPCF8574, FALLING);
47+
48+
for(int i=0;i<8;i++) {
49+
pcf8574.pinMode(i, INPUT);
50+
}
51+
pcf8574.begin();
52+
}
53+
54+
void loop()
55+
{
56+
if (keyPressed){
57+
PCF8574::DigitalInput val = pcf8574.digitalReadAll();
58+
if (val.p0==HIGH) Serial.println("KEY0 PRESSED");
59+
if (val.p1==HIGH) Serial.println("KEY1 PRESSED");
60+
if (val.p2==HIGH) Serial.println("KEY2 PRESSED");
61+
if (val.p3==HIGH) Serial.println("KEY3 PRESSED");
62+
if (val.p4==HIGH) Serial.println("KEY4 PRESSED");
63+
if (val.p5==HIGH) Serial.println("KEY5 PRESSED");
64+
if (val.p6==HIGH) Serial.println("KEY6 PRESSED");
65+
if (val.p7==HIGH) Serial.println("KEY7 PRESSED");
66+
keyPressed= false;
67+
}
68+
}

examples/ledWemos/ledWemos.ino

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* PCF8574 GPIO Port Expand
3+
* http://nopnop2002.webcrow.jp/WeMos/WeMos-25.html
4+
*
5+
* PCF8574 ----- WeMos
6+
* A0 ----- GRD
7+
* A1 ----- GRD
8+
* A2 ----- GRD
9+
* VSS ----- GRD
10+
* VDD ----- 5V/3.3V
11+
* SDA ----- GPIO_4(PullUp)
12+
* SCL ----- GPIO_5(PullUp)
13+
*
14+
* P0 ----------------- LED0
15+
* P1 ----------------- LED1
16+
* P2 ----------------- LED2
17+
* P3 ----------------- LED3
18+
* P4 ----------------- LED4
19+
* P5 ----------------- LED5
20+
* P6 ----------------- LED6
21+
* P7 ----------------- LED7
22+
*
23+
*/
24+
25+
#include "Arduino.h"
26+
#include "PCF8574.h" // https://github.com/xreef/PCF8574_library
27+
28+
// Set i2c address
29+
PCF8574 pcf8574(0x20);
30+
31+
void setup()
32+
{
33+
Serial.begin(9600);
34+
35+
// Set pinMode to OUTPUT
36+
for(int i=0;i<8;i++) {
37+
pcf8574.pinMode(i, OUTPUT);
38+
}
39+
pcf8574.begin();
40+
}
41+
42+
void loop()
43+
{
44+
static int pin = 0;
45+
pcf8574.digitalWrite(pin, HIGH);
46+
delay(1000);
47+
pcf8574.digitalWrite(pin, LOW);
48+
delay(1000);
49+
pin++;
50+
if (pin > 7) pin = 0;
51+
}

0 commit comments

Comments
 (0)