From 3d8298da4766c7beeb924f495836ef22affd61ca Mon Sep 17 00:00:00 2001 From: Renzo Date: Sat, 18 Aug 2018 21:44:23 +0200 Subject: [PATCH] Some wemos examples from http://nopnop2002.webcrow.jp --- README.md | 5 +- examples/interruptWemos/interruptWemos.ino | 68 ++++++++++++++++++++++ examples/ledWemos/ledWemos.ino | 51 ++++++++++++++++ 3 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 examples/interruptWemos/interruptWemos.ino create mode 100644 examples/ledWemos/ledWemos.ino diff --git a/README.md b/README.md index b4cc7f5..b9d7761 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,12 @@ Tutorial: 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 `/libraries/` folder. You may need to create the libraries subfolder if its your first library. Restart the IDE. -# Reef complete PCF8574 digital input and output expander with i2c bus. +# Reef complete PCF8574 PCF8574AP digital input and output expander with i2c bus. I try to simplify the use of this IC, with a minimal set of operation. +PCF8574P address map 0x20-0x27 +PCF8574AP address map 0x38-0x3f + Constructor: you must pas the address of i2c (to check the adress use this guide [I2cScanner](https://playground.arduino.cc/Main/I2cScanner)) ```cpp diff --git a/examples/interruptWemos/interruptWemos.ino b/examples/interruptWemos/interruptWemos.ino new file mode 100644 index 0000000..a9def81 --- /dev/null +++ b/examples/interruptWemos/interruptWemos.ino @@ -0,0 +1,68 @@ +/* + * PCF8574 GPIO Port Expand + * http://nopnop2002.webcrow.jp/WeMos/WeMos-25.html + * + * PCF8574 ----- WeMos + * A0 ----- GRD + * A1 ----- GRD + * A2 ----- GRD + * VSS ----- GRD + * VDD ----- 5V/3.3V + * SDA ----- GPIO_4 + * SCL ----- GPIO_5 + * INT ----- GPIO_13 + * + * P0 ----------------- BUTTON0 + * P1 ----------------- BUTTON1 + * P2 ----------------- BUTTON2 + * P3 ----------------- BUTTON3 + * P4 ----------------- BUTTON4 + * P5 ----------------- BUTTON5 + * P6 ----------------- BUTTON6 + * P7 ----------------- BUTTON7 + * + */ + +#include "Arduino.h" +#include "PCF8574.h" // https://github.com/xreef/PCF8574_library + +#define ESP8266_INTERRUPTED_PIN 13 + +// Set i2c address +PCF8574 pcf8574(0x20); + +// Function interrupt +bool keyPressed = false; + +void keyPressedOnPCF8574(){ +// Serial.println("keyPressedOnPCF8574"); + keyPressed = true; +} + +void setup() +{ + Serial.begin(9600); + pinMode(ESP8266_INTERRUPTED_PIN, INPUT_PULLUP); + attachInterrupt(digitalPinToInterrupt(ESP8266_INTERRUPTED_PIN), keyPressedOnPCF8574, FALLING); + + for(int i=0;i<8;i++) { + pcf8574.pinMode(i, INPUT); + } + pcf8574.begin(); +} + +void loop() +{ + if (keyPressed){ + PCF8574::DigitalInput val = pcf8574.digitalReadAll(); + if (val.p0==HIGH) Serial.println("KEY0 PRESSED"); + if (val.p1==HIGH) Serial.println("KEY1 PRESSED"); + if (val.p2==HIGH) Serial.println("KEY2 PRESSED"); + if (val.p3==HIGH) Serial.println("KEY3 PRESSED"); + if (val.p4==HIGH) Serial.println("KEY4 PRESSED"); + if (val.p5==HIGH) Serial.println("KEY5 PRESSED"); + if (val.p6==HIGH) Serial.println("KEY6 PRESSED"); + if (val.p7==HIGH) Serial.println("KEY7 PRESSED"); + keyPressed= false; + } +} diff --git a/examples/ledWemos/ledWemos.ino b/examples/ledWemos/ledWemos.ino new file mode 100644 index 0000000..ea5e8cb --- /dev/null +++ b/examples/ledWemos/ledWemos.ino @@ -0,0 +1,51 @@ +/* + * PCF8574 GPIO Port Expand + * http://nopnop2002.webcrow.jp/WeMos/WeMos-25.html + * + * PCF8574 ----- WeMos + * A0 ----- GRD + * A1 ----- GRD + * A2 ----- GRD + * VSS ----- GRD + * VDD ----- 5V/3.3V + * SDA ----- GPIO_4(PullUp) + * SCL ----- GPIO_5(PullUp) + * + * P0 ----------------- LED0 + * P1 ----------------- LED1 + * P2 ----------------- LED2 + * P3 ----------------- LED3 + * P4 ----------------- LED4 + * P5 ----------------- LED5 + * P6 ----------------- LED6 + * P7 ----------------- LED7 + * + */ + +#include "Arduino.h" +#include "PCF8574.h" // https://github.com/xreef/PCF8574_library + +// Set i2c address +PCF8574 pcf8574(0x20); + +void setup() +{ + Serial.begin(9600); + + // Set pinMode to OUTPUT + for(int i=0;i<8;i++) { + pcf8574.pinMode(i, OUTPUT); + } + pcf8574.begin(); +} + +void loop() +{ + static int pin = 0; + pcf8574.digitalWrite(pin, HIGH); + delay(1000); + pcf8574.digitalWrite(pin, LOW); + delay(1000); + pin++; + if (pin > 7) pin = 0; +}