Próbuje uruchomić moduł ESP32S3 z expanderem i2c MCP23017. Robię według powyższych przykładów, ale wygląda to jak by w ogóle nie były wykorzystywane funkcje "CustomDigitalRead/Write".
Gdy wysterowuję expander we funkcji "Setup" poleceniami "mcp.digitalWrite/read" to wszystko działa, wyjścia są wysterowywane, a wejścia sczytywane. Z poziomu kodu supli przekaźnik jest zarejestrowany, ze strony internetowej można zmienić stan przekaźnika, ale fizycznie na płycie nic się nie dzieje. Poprosił bym o sugestię bardziej doświadczonych kolegów co zrobiłem nie tak?
Code: Select all
/*
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 <SuplaDevice.h>
#include <supla/control/rgbw_leds.h>
#include <supla/control/button.h>
#include <supla/control/relay.h>
#include <Adafruit_MCP23017/Adafruit_MCP23017.h>
#include <Wire.h>
#include <supla/io.h>
#define I2C_SDA 41
#define I2C_SCL 42
Adafruit_MCP23017 mcp;
// Choose proper network interface for your card:
#ifdef ARDUINO_ARCH_AVR
// 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);
#elif defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
// ESP8266 and ESP32 based board:
#include <supla/network/esp_wifi.h>
Supla::ESPWifi wifi("wifi", "haslo"); //dane ukryte
#endif
/*
* Youtube: https://youtu.be/FE9tqzTjmA4
* Youtube example was done on older version of SuplaDevice library
*/
#define RED_PIN1 21
#define GREEN_PIN1 14
#define BLUE_PIN1 13
#define BRIGHTNESS_PIN1 255
#define BUTTON_PIN1 0
#define RED_PIN2 255
#define GREEN_PIN2 255
#define BLUE_PIN2 255
#define BRIGHTNESS_PIN2 12
#define BUTTON_PIN2 18
#define MAIN_RELAY 40
#define WL_DRZWI1 111 //mcp.digitalRead(11)
#define WL_DRZWI2 103 //mcp.digitalRead(3)
///#define wl_swiatlo 11
#define LED_ZIEL_WL1 109
#define LED_ZIEL_WL2 101
#define LED_CZER_WL1 110
#define LED_CZER_WL2 102
#define LED_WARNING 108
class MyMcp23017 : public Supla::Io {
public:
void customDigitalWrite(int channelNumber, uint8_t pin, uint8_t val) {
if ((pin >= 100)&& (pin <= 115)) {
//mcp.pinMode(pin - 100, OUTPUT);
mcp.digitalWrite(pin - 100, val);
//pinMode(12, OUTPUT);
//digitalWrite(12,1);
return;
}
if (pin <= 99) {
pinMode(12, OUTPUT);
digitalWrite(12,1);
return ::digitalWrite(pin,val); // ------------------------------ so that the other channels work normally
}
}
void customPinMode(int channelNumber, uint8_t pin, uint8_t mode) {
if ((pin >= 100)&& (pin <= 115)) {
mcp.pinMode(pin - 100, mode);
//mcp.digitalWrite(pin - 100, val);
//pinMode(12, OUTPUT);
//digitalWrite(12,1);
return;
}
if (pin <= 99) {
//pinMode(12, OUTPUT);
// digitalWrite(12,1);
return ::pinMode(pin,mode); // ------------------------------ so that the other channels work normally
}
}
int customDigitalRead(int channelNumber, uint8_t pin) {
//pinMode(40, OUTPUT);
//digitalWrite(40,1);
if ((pin >= 100)&& (pin <= 115)) {
//mcp.pinMode(pin - 100, INPUT);
return ::mcp.digitalRead(pin - 100);
}
if (pin <= 99){
return ::digitalRead(pin); // ------------------------------ so that the other channels work normally
}
}
};
MyMcp23017 instanceMyMcp23017;
void setup() {
Wire.begin(I2C_SDA, I2C_SCL, 100000);
mcp.begin();
Serial.begin(115200);
// Replace the falowing GUID with value that you can retrieve from https://www.supla.org/arduino/get-guid
char GUID[SUPLA_GUID_SIZE] = {dane ukryte};
// Replace the following AUTHKEY with value that you can retrieve from: https://www.supla.org/arduino/get-authkey
char AUTHKEY[SUPLA_AUTHKEY_SIZE] = {dane ukryte};
/*
* 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.
*/
// CHANNEL0 - RGB controller and dimmer (RGBW)
auto rgbw1 = new Supla::Control::RGBWLeds(
RED_PIN1, GREEN_PIN1, BLUE_PIN1, BRIGHTNESS_PIN1);
auto rgbw2 = new Supla::Control::RGBWLeds(
RED_PIN2, GREEN_PIN2, BLUE_PIN2, BRIGHTNESS_PIN2);
auto button1 = new Supla::Control::Button(BUTTON_PIN1, false, true);
auto button2 = new Supla::Control::Button(BUTTON_PIN2, false, true); //pin, podciaganie, inwersja stanu
auto button3 = new Supla::Control::Button(WL_DRZWI1, false, true);
auto relay1 = new Supla::Control::Relay(LED_WARNING, 0);
auto relay2 = new Supla::Control::Relay(MAIN_RELAY, 1);
button1->setMulticlickTime(200);
button1->setHoldTime(400);
button1->repeatOnHoldEvery(35);
button2->setMulticlickTime(200);
button2->setHoldTime(400);
button2->repeatOnHoldEvery(35);
button3->setMulticlickTime(200);
button3->setHoldTime(400);
button3->repeatOnHoldEvery(35);
rgbw1->setStep(1);
rgbw2->setStep(1);
// rgbw->setMinMaxIterationDelay(750); // delay between dimming direction
// change, 750 ms (default)
// rgbw->setMinIterationBrightness(1); // 1 is default value
button1->addAction(Supla::ITERATE_DIM_ALL, rgbw1, Supla::ON_HOLD);
button1->addAction(Supla::TOGGLE, rgbw1, Supla::ON_CLICK_1);
button2->addAction(Supla::TOGGLE, rgbw2, Supla::ON_CLICK_1);
button3->addAction(Supla::TOGGLE, relay2, Supla::ON_CLICK_1);
//button2->addAction(Supla::ITERATE_DIM_ALL, rgbw2, Supla::ON_HOLD);
//-----------------------------------------------------------------------------------------------
mcp.pinMode(2, OUTPUT); // pin LED_CZERWONA2 wyjscie
mcp.digitalWrite(2, LOW);
//-----------------------------------------------------------------------------------------------
/*
* SuplaDevice Initialization.
* Server address is 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
"svrxx.supla.org", // SUPLA server address (dane ukryte)
"adres@email", // Email address used to login to Supla Cloud (Dane ukryte)
AUTHKEY); // Authorization key
}
void loop() {
SuplaDevice.iterate();
}