Rankle
24.Март.2023 12:02:39
1
Добрый день
Помогите разобраться почему на WeMos D1 uno R3 WiFi (ESP12-E) происходит конфликт расширителя портов (pcf8574) и TFT (на ST7789).
pcf8574 подключён на D14 (SDA) и D15 (SCL)
#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <PCF8574.h>
#include <Wire.h>
const char* ssid = "WEMOS";
const char* password = "123456789";
IPAddress local_ip(192,168,5,1);
IPAddress gateway(192,168,5,1);
IPAddress subnet(255,255,255,0);
ESP8266WebServer server(80);
PCF8574 pcf8574(0x25);
#define TFT_CS 10
#define TFT_DC D3
#define TFT_RST D6
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
void setup(void)
{
Serial.begin(115200);
pcf8574.begin();
pcf8574.pinMode(P0, OUTPUT);
pcf8574.digitalWrite(P0, LOW);
tft.init(240, 320, SPI_MODE2); // Init ST7789 240x240
tft.setRotation(1); tft.invertDisplay(false);
tft.fillScreen(ST77XX_BLACK);
tft.setCursor(140, 28); tft.setTextColor(0x07FF); tft.setTextSize(2); tft.print("HELLO");
WiFi.softAP(ssid, password);
WiFi.softAPConfig(local_ip, gateway, subnet);
delay(100);
server.begin();
Serial.println("HTTP server started");
}
void loop()
{
pcf8574.digitalWrite(P0, HIGH);
delay (500);
pcf8574.digitalWrite(P0, LOW);
delay (500);
}
Вот так выводится на TFT только “HELLO” и НЕ работает реле подключенное к порту 0 расширителя портов.
А если закомментирую строки 24, 32, 33, 34, 35 то НЕ выводится на TFT “HELLO” зато реле исправно включается и выключается.
ua6em
24.Март.2023 12:16:34
2
видимо надо открыть как прописано в ядре и привести распиновку в соответствие
Rankle
24.Март.2023 12:56:41
3
Извините, не понял. В соответствии с чем? Я подключил к тем выводам, которые выделены под i2c. У класса pcf8574 есть ещё синтаксис (адрес, sda, scl). Я и так тоже пробовал, после адреса прописывать пины на которые подключен расширитель. Не сработало. Когда пины не указываешь, то работает. Когда указываешь - не работает.
ua6em
24.Март.2023 13:15:35
4
фото именно вашей платы выкладывайте, глянем, как сконфигурирована
Для начала определимся, что за плата, если соответствует картинке, то это D1 R1
https://arduinomaster.ru/wp-content/uploads/2017/12/2017-12-30_13-45-11.png
Как прописана:
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#define PIN_WIRE_SDA (4)
#define PIN_WIRE_SCL (5)
static const uint8_t SDA = PIN_WIRE_SDA;
static const uint8_t SCL = PIN_WIRE_SCL;
//new ESP-12E GPIO2
#define LED_BUILTIN 2
static const uint8_t D0 = 3;
static const uint8_t D1 = 1;
static const uint8_t D2 = 16;
static const uint8_t D3 = 5;
static const uint8_t D4 = 4;
static const uint8_t D5 = 14;
static const uint8_t D6 = 12;
static const uint8_t D7 = 13;
static const uint8_t D8 = 0;
static const uint8_t D9 = 2;
static const uint8_t D10 = 15;
static const uint8_t D11 = 13;
static const uint8_t D12 = 12;
static const uint8_t D13 = 14;
static const uint8_t D14 = 4;
static const uint8_t D15 = 5;
#include "../generic/common.h"
#endif /* Pins_Arduino_h */
тут есть SPI - тут нет SPI
а тут: (generic/common.h)
#ifndef GENERIC_COMMON_H
#define GENERIC_COMMON_H
#define EXTERNAL_NUM_INTERRUPTS 16
#define NUM_DIGITAL_PINS 17
#define NUM_ANALOG_INPUTS 1
#define isFlashInterfacePin(p)\
(esp_is_8285()\
? ((p) == 6 || (p) == 7 || (p) == 8 || (p) == 11)\
: ((p) >= 6 && (p) <= 11))
#define analogInputToDigitalPin(p) ((p > 0) ? NOT_A_PIN : 0)
#define digitalPinToInterrupt(p) (((p) < EXTERNAL_NUM_INTERRUPTS)? (p) : NOT_AN_INTERRUPT)
#define digitalPinHasPWM(p) (((p) < NUM_DIGITAL_PINS && !isFlashInterfacePin(p))? 1 : 0)
#define PIN_SPI_SS (15)
#define PIN_SPI_MOSI (13)
#define PIN_SPI_MISO (12)
#define PIN_SPI_SCK (14)
static const uint8_t SS = PIN_SPI_SS;
static const uint8_t MOSI = PIN_SPI_MOSI;
static const uint8_t MISO = PIN_SPI_MISO;
static const uint8_t SCK = PIN_SPI_SCK;
#ifndef PIN_A0
#define PIN_A0 (17)
#endif /* PIN_A0 */
static const uint8_t A0 = PIN_A0;
У нас есть где-то в определениях пины с именем P0, ан нету таких…
Выходит вся лабуда в библиотеке PCF8574 и её конкретном применении!?
ua6em
24.Март.2023 17:07:33
6
ясно, wemos D1 R1, теперь показывайте библиотеку PCF8574
Rankle
24.Март.2023 17:32:05
7
библиотека скачана с GitHub
.....
......
#if !defined(DEFAULT_SDA)
# if defined(ARDUINO_ARCH_STM32)
# define DEFAULT_SDA PB7
# elif defined(ESP8266)
# define DEFAULT_SDA 4
# elif defined(SDA)
# define DEFAULT_SDA SDA
# else
# error "Error define DEFAULT_SDA, SDA not declared, if you have this error contact the mantainer"
# endif
#endif
#if !defined(DEFAULT_SCL)
# if defined(ARDUINO_ARCH_STM32)
# define DEFAULT_SCL PB6
# elif defined(ESP8266)
# define DEFAULT_SCL 5
# elif defined(SDA)
# define DEFAULT_SCL SCL
# else
# error "Error define DEFAULT_SCL, SCL not declared, if you have this error contact the mantainer"
# endif
#endif
....
....
....
Т.е. вся проблема в 7-ой и в 18-ой строке?