ESP8266 To control digital pin

Hello,

This my first time using an ESP and one of my first using an Arduino.

I have a generic 8 pin ESP module that I have connected on my Arduino, I manged to make it work in terms of getting data from the web, currently it gets a 0 or 1 from my website, what I wanted to do is to turn on a LEDif it has a 1 and turn it off if it has a 0, but when I try to add an "pinMode(led, OUTPUT);" (the LED is on pin 8) I get the error "ets Jan 8 2013,rst cause:4, boot mode:(1,1) wdt reset" on my Serial monitor.

I think it's because I have the board set as "Generic ESP8266 Module" but my issue is, how can I read the data from the ESP when I am using the Arduino Uno itself? I don't understand that part, do I need to unplug the ESP from the RX and TX and plug it somewhere else?

Here is my full code for the ESP:

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

HTTPClient httpClient;

#define WIFI_SSID "----"
#define WIFI_PASS "----"

#define SERVER_NAME "http://192.168.1.85/arduino.php"

String savedBit;

void setup() {

  Serial.begin(115200);
  
  WiFi.hostname("Arduino");
  WiFi.begin(WIFI_SSID, WIFI_PASS);

  Serial.print("Connecting.."); 
  while(WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(1000);
  }

  Serial.println("");
  Serial.print("IP Address: ");
  Serial.print(WiFi.localIP());
  
}

void loop() {
  
  if (WiFi.status() == WL_CONNECTED) { 

    HTTPClient http;
    Serial.print("[HTTP] starting...\n");
    http.begin(SERVER_NAME);
    
    Serial.print("[HTTP] GET...\n");
    int httpCode = http.GET();


    if(httpCode > 0) {
      Serial.printf("[HTTP] GET... code: %d\n", httpCode);

      if(httpCode == HTTP_CODE_OK) {
          String pageBit = http.getString();
          if (!savedBit.equals(pageBit)) {
            savedBit = pageBit;

            if (pageBit.equals("1")) {
              // turn on led 
            } else if (pageBit.equals("0")) {
              // turn off led 
            }
          }

          Serial.flush();
      }
    } else {
      Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
    }

    http.end();
    delay(1000);
    
  }
  
}

Thank you!

WELCOME !

read HOW TO USE THIS FORUM

look at #7 about posting code.

please post your code.

dave-in-nj:
WELCOME !

read HOW TO USE THIS FORUM

look at #7 about posting code.

please post your code.

Hello, thank you!
I didn't post the code because I thought it would need something different for the Arduino part, but I edited with it now!

An 8 pin ESP8266-01 is usually delivered with what is called the “AT command set” firmware. That firmware is (very) losely based on the ascii text protocol developed back in 1981 for the original Hayes smartmodem. It is this command set the Uno uses to talk to the ESP8266-01 which does the web based stuff and passes the result back to the Uno.

When you use the ESP module with an Uno, you never reprogram the ESP, you just send it ascii commands and it returns ascii results. In this this arrangement, you would never change the board type to “Generic ESP8266 module” because if you compiled the program and had the ESP pins set correctly and downloaded the program, you would wipe the “AT command set” firmware that is in the modules flash memory.

The good news is that if the ESP module is connected to the Uno, you could never erase the flash in it using the Arduino IDE.

You can use the ESP8266-01 as a stand-alone module, no Uno required, and program it with the Arduino IDE. You’ve already loaded the ESP core files required to do that. But, in order to program the ESP as a stand-alone, you’ll need a 3.3 volt power supply and a fixture to hold the board, set pins to required voltages in order to get it into download mode and then using a usb to serial converter, download the program into the module just like you do with the Uno. The only downside to the -01 module is that you only have four, maybe five gpio pins.

Perhaps it can all be summed up with this:

Based on your original description of what you’re doing, you need to connect the led to the Uno, not the ESP module. You then use the web data, sent to the Uno from the ESP in an ascii string, to blink an led.

The code you’ve now posted is to use just the ESP module. IS the ESP module still connected to the Uno?

Oh okay, interesting, I only did write code for the ESP because all the guides I could find would tell me to.
I wanted the Uno to like "read" the data from the ESP and make the Uno do stuff based on it.
Should I re-flash the ESP with it's original AT command set?
Yeah I still have the ESP module connected to the Uno.

Did you use this online tutorial?

If not, please provide links to any tutorial(s) you have used so we know what has been modified.

  • You may not even NEED the Arduino if there are enough I/O pins on the ESP to satisfy your project needs.

That being said.. I did a similar project, where I had the ESP module host a local HTML file (my GUI/interface).. and had the ESP module configured as a captive portal (think hotel, when you want to use the internet, you only get 1 page delivered to you/your browser UNTIL you log in/pay... (whatever)..

So the '1 page' in my set up is the GUI interface...

I write my HTML/CSS code.. and when the page submits.. I parse the submitted (form) data out.. and pass that to my connected Arduino using a software serial connection.

On the Arduino side of things.. you parse that data.. and do whatever it is that 'action/command' is telling you to do..