https://github.com/klew/arduino/blob/ma ... supla/io.h
Zaktualizuj bibliotekę
Kod: Zaznacz cały
/*
Copyright (C) AC SOFTWARE SP. Z O.O.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <SPI.h>
#include <SuplaDevice.h>
#include <supla/io.h>
#include <supla/control/relay.h>
#include <Adafruit_MCP23017.h>
// Choose proper network interface for your card:
// Arduino Mega with EthernetShield W5100:
// #include <supla/network/ethernet_shield.h>
// Ethernet MAC address
// uint8_t mac[6] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
// Supla::EthernetShield ethernet(mac);
//
// Arduino Mega with ENC28J60:
// #include <supla/network/ENC28J60.h>
// Supla::ENC28J60 ethernet(mac);
//
// ESP8266 based board:
#include <supla/network/esp_wifi.h>
Supla::ESPWifi wifi("your_wifi_ssid", "your_wifi_password");
//
// ESP32 based board:
// #include <supla/network/esp32_wifi.h>
// Supla::ESP32Wifi wifi("your_wifi_ssid", "your_wifi_password");
Adafruit_MCP23017 mcp;
class MyMcp23017 : public Supla::Io {
public:
void customDigitalWrite(int channelNumber, uint8_t pin, uint8_t val) {
if ((pin >= 100)&& (pin <= 115)){
mcp.digitalWrite(pin - 100, val);
return;
}
if (pin <= 99) {
return ::digitalWrite(pin,val);
}
}
int customDigitalRead(int channelNumber, uint8_t pin) {
if ((pin >= 100)&& (pin <= 115)){
return mcp.digitalRead(pin - 100);
}
if (pin <= 99){
return ::digitalRead(pin);
}
}
}MyMcp23017;
void setup() {
Serial.begin(115200);
mcp.begin();
mcp.pinMode(0, OUTPUT);
mcp.pinMode(1, OUTPUT);
mcp.pinMode(2, OUTPUT);
mcp.pinMode(3, OUTPUT);
mcp.pinMode(4, OUTPUT);
mcp.pinMode(5, OUTPUT);
mcp.pinMode(6, OUTPUT);
mcp.pinMode(7, OUTPUT);
mcp.pinMode(8, OUTPUT);
mcp.pinMode(9, OUTPUT);
mcp.pinMode(10, OUTPUT);
mcp.pinMode(11, OUTPUT);
mcp.pinMode(12, OUTPUT);
mcp.pinMode(13, OUTPUT);
mcp.pinMode(14, OUTPUT);
mcp.pinMode(15, OUTPUT);
// Replace the falowing GUID with value that you can retrieve from https://www.supla.org/arduino/get-guid
char GUID[SUPLA_GUID_SIZE] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
// Replace the following AUTHKEY with value that you can retrieve from: https://www.supla.org/arduino/get-authkey
char AUTHKEY[SUPLA_AUTHKEY_SIZE] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
/*
* Having your device already registered at cloud.supla.org,
* you want to change CHANNEL sequence or remove any of them,
* then you must also remove the device itself from cloud.supla.org.
* Otherwise you will get "Channel conflict!" error.
*/
new Supla::Control::Relay(100, true); // A0 //
new Supla::Control::Relay(101, true); // A1 //
new Supla::Control::Relay(102, true); // A2 //
new Supla::Control::Relay(103, true); // A3 //
new Supla::Control::Relay(104, true); // A4 //
new Supla::Control::Relay(105, true); // A5 //
new Supla::Control::Relay(106, true); // A6 //
new Supla::Control::Relay(107, true); // A7 //
new Supla::Control::Relay(108, true); // B0 //
new Supla::Control::Relay(109, true); // B1 //
new Supla::Control::Relay(110, true); // B2 //
new Supla::Control::Relay(111, true); // B3 //
new Supla::Control::Relay(112, true); // B4 //
new Supla::Control::Relay(113, true); // B5 //
new Supla::Control::Relay(114, true); // B6 //
new Supla::Control::Relay(115, true); // B7 //
/*
* SuplaDevice Initialization.
* Server address, LocationID and LocationPassword are available at https://cloud.supla.org
* If you do not have an account, you can create it at https://cloud.supla.org/account/create
* SUPLA and SUPLA CLOUD are free of charge
*
*/
SuplaDevice.begin(GUID, // Global Unique Identifier
"svr1.supla.org", // SUPLA server address
"email@address", // Email address used to login to Supla Cloud
AUTHKEY); // Authorization key
}
void loop() {
SuplaDevice.iterate();
delay(15);
}
Kod: Zaznacz cały
Adafruit_MCP23017 mcp;
Adafruit_MCP23017 mcp2;
#include <supla/io.h>
class MyMcp23017 : public Supla::Io {
public:
void customDigitalWrite(int channelNumber, uint8_t pin, uint8_t val) {
if ((pin >= 100) && (pin <= 115)) {
mcp.digitalWrite(pin - 100, val);
return;
}
if (pin <= 99) {
return ::digitalWrite(pin, val); // ------------------------------ so that the other channels work normally
}
}
int customDigitalRead(int channelNumber, uint8_t pin) {
if ((pin >= 100) && (pin <= 115)) {
return mcp.digitalRead(pin - 100);
}
if (pin <= 99) {
return ::digitalRead(pin); // ------------------------------ so that the other channels work normally
}
if ((pin >= 200) && (pin <= 215)) {
return mcp2.digitalRead(pin - 200);
}
}
} MyMcp23017;
Kod: Zaznacz cały
auto r1 = new Supla::Control::Relay(100);
auto b1 = new Supla::Control::Button(200);//, true, true); // przycisk na pin3, z input pullup i odwróconą logiką (zwieranie do gnd)
b1->addAction(Supla::TOGGLE , r1, Supla::ON_PRESS);
Kod: Zaznacz cały
mcp2.begin(1);
mcp2.pinMode(0, INPUT); mcp2.pullUp(0, HIGH); // turn on a 100K pullup internally
mcp2.pinMode(1, INPUT); mcp2.pullUp(1, HIGH); // turn on a 100K pullup internally
mcp2.pinMode(2, INPUT); mcp2.pullUp(2, HIGH); // turn on a 100K pullup internally
mcp2.pinMode(3, INPUT); mcp2.pullUp(3, HIGH); // turn on a 100K pullup internally
mcp2.pinMode(4, INPUT); mcp2.pullUp(4, HIGH); // turn on a 100K pullup internally
mcp2.pinMode(5, INPUT); mcp2.pullUp(5, HIGH); // turn on a 100K pullup internally
mcp2.pinMode(6, INPUT); mcp2.pullUp(6, HIGH); // turn on a 100K pullup internally
mcp2.pinMode(7, INPUT); mcp2.pullUp(7, HIGH); // turn on a 100K pullup internally
mcp2.pinMode(8, INPUT); mcp2.pullUp(8, HIGH); // turn on a 100K pullup internally
mcp2.pinMode(9, INPUT); mcp2.pullUp(9, HIGH); // turn on a 100K pullup internally
mcp2.pinMode(10, INPUT); mcp2.pullUp(10, HIGH); // turn on a 100K pullup internally
mcp2.pinMode(11, INPUT); mcp2.pullUp(11, HIGH); // turn on a 100K pullup internally
mcp2.pinMode(12, INPUT); mcp2.pullUp(12, HIGH); // turn on a 100K pullup internally
mcp2.pinMode(13, INPUT); mcp2.pullUp(13, HIGH); // turn on a 100K pullup internally
mcp2.pinMode(14, INPUT); mcp2.pullUp(14, HIGH); // turn on a 100K pullup internally
mcp2.pinMode(15, INPUT); mcp2.pullUp(15, HIGH); // turn on a 100K pullup internally
Kod: Zaznacz cały
for (int i = 0; i <= 15; i++) {
mcp2.pinMode(i, INPUT); mcp2.pullUp(i, HIGH); // turn on a 100K pullup internally
}
Dobry wieczórradzik_r pisze: ↑wt lis 03, 2020 6:36 pm Cool.
These are the changes that I was struggling with today, and eventually I came to it myself.
I also added a second MCP as buttons. I don't know if I made it right but it works.
of course with replacing button.h from elmaya
Kod: Zaznacz cały
Adafruit_MCP23017 mcp; Adafruit_MCP23017 mcp2; #include <supla/io.h> class MyMcp23017 : public Supla::Io { public: void customDigitalWrite(int channelNumber, uint8_t pin, uint8_t val) { if ((pin >= 100) && (pin <= 115)) { mcp.digitalWrite(pin - 100, val); return; } if (pin <= 99) { return ::digitalWrite(pin, val); // ------------------------------ so that the other channels work normally } } int customDigitalRead(int channelNumber, uint8_t pin) { if ((pin >= 100) && (pin <= 115)) { return mcp.digitalRead(pin - 100); } if (pin <= 99) { return ::digitalRead(pin); // ------------------------------ so that the other channels work normally } if ((pin >= 200) && (pin <= 215)) { return mcp2.digitalRead(pin - 200); } } } MyMcp23017;
Kod: Zaznacz cały
auto r1 = new Supla::Control::Relay(100); auto b1 = new Supla::Control::Button(200);//, true, true); // przycisk na pin3, z input pullup i odwróconą logiką (zwieranie do gnd) b1->addAction(Supla::TOGGLE , r1, Supla::ON_PRESS);
Cześć.Moezzz pisze: ↑czw sty 21, 2021 7:48 pmDobry wieczórradzik_r pisze: ↑wt lis 03, 2020 6:36 pm Cool.
These are the changes that I was struggling with today, and eventually I came to it myself.
I also added a second MCP as buttons. I don't know if I made it right but it works.
of course with replacing button.h from elmaya
Kod: Zaznacz cały
Adafruit_MCP23017 mcp; Adafruit_MCP23017 mcp2; #include <supla/io.h> class MyMcp23017 : public Supla::Io { public: void customDigitalWrite(int channelNumber, uint8_t pin, uint8_t val) { if ((pin >= 100) && (pin <= 115)) { mcp.digitalWrite(pin - 100, val); return; } if (pin <= 99) { return ::digitalWrite(pin, val); // ------------------------------ so that the other channels work normally } } int customDigitalRead(int channelNumber, uint8_t pin) { if ((pin >= 100) && (pin <= 115)) { return mcp.digitalRead(pin - 100); } if (pin <= 99) { return ::digitalRead(pin); // ------------------------------ so that the other channels work normally } if ((pin >= 200) && (pin <= 215)) { return mcp2.digitalRead(pin - 200); } } } MyMcp23017;
Kod: Zaznacz cały
auto r1 = new Supla::Control::Relay(100); auto b1 = new Supla::Control::Button(200);//, true, true); // przycisk na pin3, z input pullup i odwróconą logiką (zwieranie do gnd) b1->addAction(Supla::TOGGLE , r1, Supla::ON_PRESS);
Nie rozumiem, jak wskazałeś adresy I2C dwóch mcps. proszę wyjaśnić tę kwestię
Witam,
@radzik_r are you sure about that?
Kod: Zaznacz cały
mcp1.init(4, 5); // init(uint8_t sda, uint8_t scl, bool fast) = Wire.begin