So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By cueox
#70497 Hi guys,

I've been trying to set the GPIO 1 pin mode on my ESP 01S to an output so that I can use it to control a transistor. However, whenever I try to set the pin mode of pin 1 to an output (or even an input) the program won't run.

I can change the pin mode of the GPIO 2 pin and the program will run but as soon as I try to do so with the GPIO 1 pin the program won't run. Here's a snippet of the code (the rest is the code works fine as long as GPIO 1 pin mode isn't set):

Code: Select all#include <ESP8266WiFi.h>

const char* ssid = "XXX";
const char* pass = "XXX";

String ID_NUM = "000" ;
String sendStatus ;

IPAddress server(192, 168, 3, 3);
WiFiClient client;

void setup() {
  Serial.begin(9600);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, pass);         
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }
  Serial.println();
  Serial.println("Connected");
  Serial.print("LocalIP:"); Serial.println(WiFi.localIP());
  Serial.println("MAC:" + WiFi.macAddress());
  Serial.print("Gateway:"); Serial.println(WiFi.gatewayIP());
  Serial.print("AP MAC:"); Serial.println(WiFi.BSSIDstr());
  pinMode(2, INPUT);
  pinMode(1, OUTPUT) ;   //ADDING THIS CAUSES THE PROGRAM TO NOT RUN
  digitalWrite(1, LOW) ;     //ADDING THIS CAUSES THE PROGRAM TO NOT RUN
}


Thanks
User avatar
By QuickFix
#70555 GPIO1 is the TX-line of serial; in your sketch you're also opening a serial @9600 baud...
Code: Select allvoid setup() {
  Serial.begin(9600);
[...]
 Serial.print("AP MAC:"); Serial.println(WiFi.BSSIDstr());
  pinMode(2, INPUT);
  pinMode(1, OUTPUT) ;   //ADDING THIS CAUSES THE PROGRAM TO NOT RUN
  digitalWrite(1, LOW) ;     //ADDING THIS CAUSES THE PROGRAM TO NOT RUN


You can't have your cake and eat it too. :mrgreen:
User avatar
By martinayotte
#70560 Switching TXD pin back to GPIO1 could be done with the following, assuming you include eagle_soc.h :

Code: Select allextern "C" {
#include "eagle_soc.h"
}

setup() {
   // Some code here
   PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_GPIO1);
   pinMode(1, OUTPUT);
   // more code here
   
}
User avatar
By cueox
#70564 Hi guys,

Thanks for your replies. I had a look at the pin out of the ESP 01S and realised that I had been meaning to use GPIO 0 not GPIO 1 so I was setting the wrong pin. So setting pinMode(0, OUTPUT) should work because I'll be using GPIO 0 right?

Thanks, silly mistake.