Aktualny schemat poniżej: Aktualna pinologia:
GPIO0 - wolne
GPIO1 - wolne
GPIO2 - przycisk włączający wyświetlacz, docelowo także będzie uruchamiał tryb konfiguracji
GPIO3 - wolne
GPIO4 - SDA dla BME i OLED
GPIO5 - SCL dla BME i OLED
GPIO12 - przekaźnik 1
GPIO13 - przycisk 1
GPIO14 - przekaźnik 2
GPIO15 - przycisk 2
Pewnie znawcy tematu od razu się domyślili, że przycisk 2 nie działa
Jak można by wykorzystać lepiej dostępne piny, żeby to działało zgodnie z oczekiwaniem?
Dopuszczalne zmiany zarówno w połączeniach jak i w samym sofcie, który w roboczej wersji jest poniżej:
Code: Select all
/*
Copyright (C) Mariusz Górski (Goral64)
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.
*/
#define SID "*****" // SSID
#define WPW "*****" // Hasło do WiFi
#define SVR "supla.*****" // serwer Supla
#define EML "*****@*****" // email konta w Supla
#define DEVICE_NAME "BME280+2RELAYS" // nazwa urządzenia
#define DISPLAY_SIZE 96 // przekątna wyświetlacza 96 -> 0,96"
#define DISPLAY_DELAY_SEC 10 // czas wyświetlania max 25 (s)
#define PIN_DISPLAY 2 // pin z włącznikiem wyświetlacza 2 -> D4
#define PIN_OLED_SDA 4 // pin SDA wyświetlacza 4 -> D2
#define PIN_OLED_SCL 5 // pin SCL wyświetlacza 5 -> D1
#define PIN_RELAY1 12
#define PIN_BUTTON1 13
#define PIN_RELAY2 14
#define PIN_BUTTON2 15
#include <SuplaDevice.h>
#include <supla/network/esp_wifi.h> // interfejs sieciowy
Supla::ESPWifi suplaWifi(SID, WPW);
#include <ESP8266WiFi.h>
#include <supla/sensor/bme280.h> // sensor BME280
#include <supla/control/relay.h> // przekaźniki
#include <supla/control/button.h> // przyciski
#include "SSD1306Wire.h"
SSD1306Wire display(0x3c, PIN_OLED_SDA, PIN_OLED_SCL); // D2-SDA D1-SCL ----- OLED 0,96 ---
Supla::Sensor::BME280* bme;
Supla::Control::Relay *relay1 = nullptr;
Supla::Control::Relay *relay2 = nullptr;
Supla::Control::Button *button1 = nullptr;
Supla::Control::Button *button2 = nullptr;
void makeSuplaAuthKey(char *authKey) {
uint8_t mac[WL_MAC_ADDR_LENGTH];
WiFi.macAddress(mac);
char buf[SUPLA_AUTHKEY_SIZE] = { mac[0], mac[1], mac[2], mac[3], mac[4],
mac[5], mac[0], mac[1], mac[2], mac[3], mac[4], mac[5] };
memcpy(authKey, &buf, SUPLA_AUTHKEY_SIZE);
}
void makeSuplaGuid(char *guid) {
uint8_t mac[WL_MAC_ADDR_LENGTH];
WiFi.macAddress(mac);
char buf[SUPLA_GUID_SIZE] = { mac[0], mac[1], mac[2], mac[3],
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5] };
memcpy(guid, &buf, SUPLA_GUID_SIZE);
}
void displayOLED_96() {
display.drawHorizontalLine(0, 23, 127);
display.drawHorizontalLine(0, 44, 128);
display.drawVerticalLine(64, 1, 21);
display.setFont(ArialMT_Plain_24);
display.drawString(0, 0, String(bme->getTemp(), 1));
display.setFont(ArialMT_Plain_10);
display.drawString(48, 4, "ºC");
display.setFont(ArialMT_Plain_24);
display.drawString(70, 0, String(bme->getHumi(), 1));
display.setFont(ArialMT_Plain_10);
display.drawString(118, 4, "%");
display.setFont(ArialMT_Plain_10);
display.drawString(1, 30, "BME-280:");
display.setFont(ArialMT_Plain_24);
display.drawString(52, 20, String(bme->getPressure(), 0));
display.setFont(ArialMT_Plain_10);
display.drawString(108, 24, "hPa");
}
void displayOLED() {
if (digitalRead(PIN_DISPLAY) == LOW) {
display.clear();
if(DISPLAY_SIZE == 96) {
displayOLED_96();
}
display.display();
delay(DISPLAY_DELAY_SEC * 1000);
display.clear();
display.display();
}
}
void setup() {
Serial.begin(9600);
pinMode(PIN_DISPLAY, INPUT_PULLUP);
delay(100);
display.init();
display.flipScreenVertically();
display.setContrast(50);
display.clear();
display.setContrast(50, 121, 32);
WiFi.softAPdisconnect(true);
suplaWifi.enableSSL(false);
SuplaDevice.setName(DEVICE_NAME);
char guid[SUPLA_GUID_SIZE];
makeSuplaGuid(guid);
char authKey[SUPLA_AUTHKEY_SIZE];
makeSuplaAuthKey(authKey);
bme = new Supla::Sensor::BME280(0x76, 118);
relay1 = new Supla::Control::Relay(PIN_RELAY1);
relay2 = new Supla::Control::Relay(PIN_RELAY2);
button1 = new Supla::Control::Button(PIN_BUTTON1, true);
button2 = new Supla::Control::Button(PIN_BUTTON2, true);
button1->willTrigger(*relay1, Supla::ON_PRESS, Supla::TOGGLE);
button2->willTrigger(*relay2, Supla::ON_PRESS, Supla::TOGGLE);
SuplaDevice.begin(guid, SVR, EML, authKey);
}
void loop() {
SuplaDevice.iterate();
displayOLED();
}
