konfiguracja dla MCP23017, PCF8575 oraz PCF8574

WinstonW
Posts: 22
Joined: Fri Jul 10, 2020 3:50 pm

Post

Witam.Posiadam Arduino Mega +ethernet W5100 , jako że dla sterowania domem wykorzystałem wszystkie piny , a chce uniknąć montażu następnego arduino, chciałbym zastosować któryś z modułów MCP23017, PCF8575 lub PCF8574.

Pytanie:czy ktoś jest w stanie pomóc opisać w jaki sposób dopisać linijki aby działały któreś z powyższych ekspanderów?


mój kod w skróconej wersji

#include <SuplaDevice.h>
#include <supla/control/relay.h>
#include <supla/control/button.h>
#include <supla/sensor/binary.h>

// Choose where Supla should store counter data in persistant memory
// We recommend to use external FRAM memory
#define STORAGE_OFFSET 100
#include <supla/storage/eeprom.h>
Supla::Eeprom eeprom(STORAGE_OFFSET);
// #include <supla/storage/fram_spi.h>
// Supla::FramSpi fram(STORAGE_OFFSET);

// 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);
#endif
void setup() {

Serial.begin(9600);

// Replace the falowing GUID with value that you can retrieve from https://www.supla.org/arduino/get-guid
char GUID[SUPLA_GUID_SIZE] = {xxxxxxxxxxx};

// Replace the following AUTHKEY with value that you can retrieve from: https://www.supla.org/arduino/get-authkey
char AUTHKEY[SUPLA_AUTHKEY_SIZE] = {xxxxxxxxx};

/*
* 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.
*/

//SEKCJA PRZEKAŹNIKÓW
///////////////////////////////////////////////////////////////
//SEKCJA PRZEKAZNIKÓW 230V
auto r0 = new Supla::Control::Relay(26); //oswietlenie garaz
auto r1 = new Supla::Control::Relay(27); //oswietlenie korytarz salon
auto r2 = new Supla::Control::Relay(28); //oswietlenie schody parter boki
auto r3 = new Supla::Control::Relay(29); //oswietlenie schody pietro boki
auto r4 = new Supla::Control::Relay(30); //oswietlenie sufit salon LED
auto r5 = new Supla::Control::Relay(31); //włączenie choinki
auto r6 = new Supla::Control::Relay(32); //oswietlenie światła bramy garażowej


//SEKCJA BUTTONÓW
///////////////////////////////////////////////////////////////
auto b0 = new Supla::Control::Button(24, false ); //S01 oswietlenie garaz
b0->setHoldTime(1000);// po 2 s od przytrzymania przycisku zostanie wywołane zdarzenie ON_HOLD
b0->addAction(Supla::TOGGLE, r0, Supla::ON_PRESS); //przerzuca oś.garaz właczy-wyłacz
b0->addAction(Supla::TOGGLE, r6, Supla::ON_HOLD); //po przytrzymaniu przerzuca oś.światła garaz brama

auto b1 = new Supla::Control::Button(23, false ); //S09 oswietlenie korytarz salon
b1->addAction(Supla::TOGGLE, r1, Supla::ON_PRESS);

auto b2 = new Supla::Control::Button(20, false ); //S03 oswietlenie schody parter boki
b2->addAction(Supla::TOGGLE, r2, Supla::ON_PRESS);

auto b3 = new Supla::Control::Button(17, true ); //S10 oswietlenie schody pietro boki
b3->setHoldTime(1000);// po 2 s od przytrzymania przycisku zostanie wywołane zdarzenie ON_HOLD
b3->addAction(Supla::TOGGLE, r3, Supla::ON_PRESS);//przerzuca oś. schody pietro właczy-wyłacz
b3->addAction(Supla::TOGGLE, r10, Supla::ON_HOLD);//po przytrzymaniu przerzuca oś.lampa piętro

auto b4 = new Supla::Control::Button(21, false ); //S02 oswietlenie sufit salon LED
b4->addAction(Supla::TOGGLE, r4, Supla::ON_PRESS);

auto b5 = new Supla::Control::Button(25, false ); //S17 włączenie choinki
b5->addAction(Supla::TOGGLE, r5, Supla::ON_PRESS);

/*
* 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.setName("x");
SuplaDevice.begin(GUID, // Global Unique Identifier
"xxxxx", // SUPLA server address
"x", // Email address used to login to Supla Cloud
AUTHKEY); // Authorization key

}

void loop() {
SuplaDevice.iterate();
}
jaku2k
Posts: 920
Joined: Sun May 24, 2020 8:40 pm
Has thanked: 1 time

Post

Witam,
u mnie dwa MCP23017 działają z ESP32 na bazie przykładów @elmaya i @radzik_r
viewtopic.php?p=79429#p79429
Pozdrawiam
Jakub

Return to “Arduino IDE”