ESP12 problems with pins D3 and D4

Ive been experiencing problems using pins D3 and D4 as pull down pins.
when D3 is connected it doesnt upload and when D4 is connected it uploads but theres no serial output and in both cases the program never starts. the program only runs when D3 and D4 are disconnected during the boot/upload. im not use how to fix this or if it even can be fixed, If theres no way to fix D3 and D4 then i could either use TX and Rx or another io expansion board but im quite space constrained so id rather not. any suggestions or ideas would be welcome

here is a schematic of the board, its wired exactly as shown except the modifications to the esp12f board

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <ArduinoOTA.h>
#include <PubSubClient.h>
#include <pcf8574.h>

//Mqtt
#define USER_MQTT_SERVER          "192.168.199.15"
#define USER_MQTT_PORT            1883
#define USER_MQTT_USERNAME        ""
#define USER_MQTT_PASSWORD        ""
#define USER_MQTT_CLIENT_NAME     "ControlMCU"

//Wifi
#define USER_SSID                 ""
#define USER_PASSWORD             ""


WiFiClient espClient;
PubSubClient client(espClient);
PCF8574 ex1(0x20);

const char* ssid = USER_SSID ; 
const char* password = USER_PASSWORD ;
const char* mqtt_server = USER_MQTT_SERVER ;
const int mqtt_port = USER_MQTT_PORT ;
const char *mqtt_user = USER_MQTT_USERNAME ;
const char *mqtt_pass = USER_MQTT_PASSWORD ;
const char *mqtt_client_name = USER_MQTT_CLIENT_NAME ; 

//Notes
//The pc power commands will likely be under cmnd/tasmota_012CA5/POWER1
//Currently "works", the program will only start if D4 and D3 are disconnected, once started it can be connected
//need to add the bin counting and preset led manager

//Code
char positionPublish[50];
char charPayload[50];
bool boot = true;
int preset = 0;
int lastpressed [] = {0,0,0,0,0};
int activedevices [] = {0,0,0,0,0,0}; // 0=Reading, 1=Bed, 2=Desk, 3=Fan 4=PC 5=TV
int buttonpins[] = {D8,D7,D6,D5,D4,D3}; //D3 is the preset swicher 


void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  setup_wifi();
  client.setServer(mqtt_server, mqtt_port);
  client.setCallback(callback);
  ArduinoOTA.setHostname(USER_MQTT_CLIENT_NAME);
  ArduinoOTA.begin(); 
  delay(10);

  //Pin shenanigans
  for(int i = 0 ; i < 6; i++){
    pinMode(buttonpins[i],INPUT_PULLUP);
  }
  for(int i = 0 ; i < 8; i++){
    delay(200);
  	pinMode(ex1, i, OUTPUT);
    pinMode(ex1, i, LOW);
  }
  pinMode(LED_BUILTIN, OUTPUT); // Define LED as output
  digitalWrite(LED_BUILTIN, LOW); // ESP12 Builtin LED
}


void loop() 
{
  if (!client.connected()) 
  {
    reconnect();
  }
  client.loop();
  ArduinoOTA.handle();
  MqttOut();
}


void setup_wifi() {
  Serial.println();
  Serial.print("Connecting to ");
  Serial.print(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}


void reconnect() 
{
  int retries = 0;
  while (!client.connected()) {
    if(retries < 150)
    {
      Serial.println("Attempting MQTT connection...");
      if (client.connect(mqtt_client_name, mqtt_user, mqtt_pass)) 
      {
        Serial.println("MQTT connected");
        if(boot == false)
        {
          client.publish(USER_MQTT_CLIENT_NAME"/checkIn","Reconnected"); 
        }
        if(boot == true)
        {
          client.publish(USER_MQTT_CLIENT_NAME"/checkIn","Rebooted");
        }
        client.subscribe("lightsstat/tasmotaRelay0B6F1F/POWER1"); //Fan
        client.subscribe("lightsstat/tasmotaRelay0B6F1F/POWER2"); //Bed
        client.subscribe("lightsstat/tasmotaRelay0B6F1F/POWER3"); //Reading
        client.subscribe("stat/tasmotaRelay1F87DEC/POWER"); //Desk
        client.subscribe("stat/PCstat"); //PC
        client.subscribe("stat/TVstat"); //TV
      } 
      else 
      {
        Serial.print("failed, rc=");
        Serial.print(client.state());
        Serial.println(" try again in 5 seconds");
        retries++;
        // Wait 5 seconds before retrying
        delay(5000);
      }
    }
    if(retries > 149)
    {
    ESP.restart();
    }
  }
} 


void callback(char* topic, byte* payload, unsigned int length) 
{
  Serial.println("Message arrived:");
  String newTopic = topic;
  payload[length] = '\0';
  String newPayload = String((char *)payload);
  int intPayload = newPayload.toInt();
  newPayload.toCharArray(charPayload, newPayload.length() + 1);

  if (newTopic == "stat/tasmotaRelay1F87DEC/POWER") {
    if (newPayload == "ON"){
      activedevices[2] = 1;
    }
    else if (newPayload == "OFF"){   
      activedevices[2] = 0;
    }
  }
  
  if (newTopic == "lightsstat/tasmotaRelay0B6F1F/POWER1"){
    if (newPayload == "ON"){
      activedevices[3] = 1;
    }
    else if (newPayload == "OFF"){   
      activedevices[3] = 0;
    }
  }

  if (newTopic == "lightsstat/tasmotaRelay0B6F1F/POWER2"){
    if (newPayload == "ON"){
      activedevices[1] = 1;
    }
    else if (newPayload == "OFF"){   
      activedevices[1] = 0;
     }
  }
  
  if (newTopic == "lightsstat/tasmotaRelay0B6F1F/POWER3"){
    if (newPayload == "ON"){
      activedevices[0] = 1;
    }
    else if (newPayload == "OFF"){   
      activedevices[0] = 0;
    }
  }

  if (newTopic == "stat/PCstat"){
    if (newPayload == "ON"){
      activedevices[4] = 1;
    }
    else if (newPayload == "OFF"){   
      activedevices[4] = 0;
    }
  }

  if (newTopic == "stat/TVstat"){
    if (newPayload == "ON"){
      activedevices[5] = 1;
    }
    else if (newPayload == "OFF"){   
      activedevices[5] = 0;
    }
  }

  for(int i = 0; i < 6; i++){
    Serial.print(activedevices[i]);
    if (activedevices[i] == 1){
      digitalWrite(ex1, i, HIGH);
    } else {
      digitalWrite(ex1, i, LOW);
    }
  }

  Serial.println ("");
  Serial.println ("");
}

void MqttOut()
{
  delay(100);
  int active = 0;

  if (digitalRead(buttonpins[5]) == HIGH){ //detects the preset button and ajusts accordingly
    preset++;
    if (preset > 8){
      preset = 0;
    }
    delay(100);
    Serial.println (preset);
  }
  
  for (int i = 0; i < 5; i++){
    if (digitalRead(buttonpins[i]) == HIGH){
      active = 1;
    }
    
    if (lastpressed[i] == 1 && active == 1){
      active = 0;
    } else {
      lastpressed[i] = 0;
    }

    if (active == 1){
      int location = (preset * 5) + i + 1;
      switch (location){
        case 1:
          client.publish("cmnd/tasmotaRelay1F87DEC/Power1","TOGGLE"); //DeskLight

        break;
        case 2:
          client.publish("lightscmnd/tasmotaRelay0B6F1F/Power2","TOGGLE"); //BedLight

        break;
        case 3:
          client.publish("lightscmnd/tasmotaRelay0B6F1F/Power3","TOGGLE"); //ReadingLight

        break;   
        case 4:
          client.publish("lightscmnd/tasmotaRelay0B6F1F/Power1","TOGGLE"); //Fan

        break; 
        case 5:
          client.publish(USER_MQTT_CLIENT_NAME"/Commands/PowerPC","TOGGLE"); //PC

        break;   

        default:
        break;
      } 
      lastpressed[i] = 1;
      active = 0;
    }
  }
}


void checkIn()
{
  client.publish(USER_MQTT_CLIENT_NAME"/checkIn","OK");
}

Is it possible you are running into this problem?

I just found out that the onboard LED on my ESP-12E module is connected to GPIO2 pin (thru 470 Ohm internal resistor).

From your schematic, GPIO2 is D4.

I dont belive that is the issue but its definitely interesting


Ive modified my schematic so its less of a problem, i used 2 NPN transistors to separate the troublesome pins from the circute while uploading with the new PROGRAMING SWITCH

In your schematic, pins D3 to D8 are in pulldown. Right?
But in your code you put them in pullup. Right?
What am I missing?
What is the reason for this procedure?

yes in the schematic they are pulldown, I lifted some of the code from a previous project where the "INPUT_PULLUP" was, it used for when you dont use a resistor to gnd or vcc here. ill experiment around with removing the resistors for pull up and down for pins D3 and D4 later im going out now so i cant give you a proper responce

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.