1

Good day everyone! I have a project, in which the data from a button (number of clicks) will be sent to a real-time Firebase database. Every time the button is clicked the counter increases and will be updated in the firebase database.

Wifi Module: Esp8266 Esp-01 + Esp-01 Adapter

Esp8266 Esp-01 + Esp-01 Adapter

In my understanding, there are 2 ways to use this wifi module.

  1. Upload the code to the Arduino Uno and use AT commands in the module to send data to the web.

  2. Upload the code inside the WiFi Module itself and after that it can be a standalone SOC and does not need the Arduino anymore after the code has been uploaded.

I have tried the second way, but I got confused and stuck. So far I have successfully plugged the adapter in a breadboard and tested some AT commands.

Since I will be using the second way I won't be using these. So I tried this code:

 #include <ESP8266WiFi.h>
 #include <FirebaseArduino.h>

 #define FIREBASE_HOST "https://duck-917ba.firebaseio.com/"
 #define FIREBASE_AUTH "r3jNQCsxN2Y2dcfawimRlzjLjdBSXLjstwGeyB0oMK"

 #define WIFI_SSID "mywifi"
 #define WIFI_PASSWORD "621533515"

const int  buttonPin = 8;    
int buttonPushCounter = 0;  
int buttonState = 0;        
int lastButtonState = 0;     

void setup() {
  pinMode(buttonPin, INPUT);
  Serial.begin(9600);
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("connecting");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println();
  Serial.print("connected: ");
  Serial.println(WiFi.localIP());
  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
  Firebase.setInt("clicks",0);
}

void loop() {
  buttonState = digitalRead(buttonPin);
  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button went from off to on:
      buttonPushCounter++;
      Serial.println("on");
      Serial.print("number of button pushes: ");
      Serial.println(buttonPushCounter);
      Firebase.setInt("clicks", buttonPushCounter);
    } else {
      // if the current state is LOW then the button went from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(100);
  }
  // save the current state as the last state, for next time through the loop
  lastButtonState = buttonState;
}

So I have plugged my 4-pin adapter to the following:

  • ARD(TX)-ADAPTER(TX)

  • ARD(RX)-ADAPTER(RX)

  • ARD(5V)-ADAPTER(VCC)

  • ARD(GND)-ADAPTER(GND)

I have set the Generic ESP8266 Module Board.

Problems Encountered:

I am supposed to select the port of the ESP8266 but I only see the Arduino UNO port in the port list. When I compile the code I get this error:

enter image description here

I am now confused on what the error is all about. I thought since I am using an adapter I can use the PROGRAMMING MODE of the module easily. But it seems like my adapter is not doing its job. According to some of my research I have to use TTL or FTDI USB-to-serial dedicated module / Ground some wires while compiling which is very confusing for a beginner like me.

So here are my final thoughts:

  1. Can I input/flash code in my module using my Arduino and adapter?

  2. Since the button is plugged in the Arduino's pin 8, does that mean that the code in the module will be successfully inserted? I will still need the Arduino to be plugged in the buttons?

  3. What could be the reason why the module won't appear in the Port List and generates the errors?

I know this is quite a long and boring topic but I know a lot of aspiring IOT developers out there are having the same issues about this wifi module. I hope we can solve it together. Thanks!

1

1.) Can I input/flash code in my module using my arduino and adapter?

Yes

2.) Since the button is plugged in the pin 8 of arduino. Does that mean If the code in the module will be successfully inserted. I will still need the arduino to be plugged in the buttons?

The ESP8266 cannot magically know about the Arduino and the Arduino cannot magically know about the buttons. If you have buttons connected to the Arduino then the Arduino needs telling about them. If the Arduino and ESP8266 need to work together then they both need programming to work together. If, and only if, you connect the buttons to the ESP8266 and not the Arduino do you not need the Arduino.

3.) What could be the reason why the module won't appear in the Port List and generates the errors?

The Arduino is getting in the way. Connect Arduino RESET to Arduino GND to disable the ATMega328p chip which is also trying to use TX and RX and conflicting with the ESP8266. Or better still get a cheap USB to UART cable (just a couple of dollars on eBay) and connect the adaptor direct to your PC without the Arduino.

  • Thank you for the response. Like you said I tried to put the RESET to GND in the arduino. I tried to tweak my adapter so that the connection would go like this and enter programming mode: ARD(TXD)-TXD, ARD(RXD)-RXD, CH-PD&VCC TO 3.3V, RESET&GND&GPIO0 TO GND, GPIO2 unplugged. But unfortunately when I try to upload the Arduino UNO/ COM12 still appears on the port list and it seems like my module cannot be read in the arduino port list for some reasons. – Duckbenok Aug 3 '17 at 7:19
  • It sounds like you are expecting your module to appear separately on the computer. It's not the module that is connected to the computer, it is the Arduino that is connected to the computer. It is the Arduino that you will always see. – Majenko Aug 3 '17 at 8:32
  • I see. I ordered an USB to UART cable online and would arrive in a couple of days. So in my understanding I will have to plug my module+adapter in the uart device and plug it in my computer so I can start programming directly inside the module without the need of arduino? Incase I successfully uploaded my code in the module I can use it in boot mode and use it with the arduino? To sum it up plug in UART(programming mode), plug in Arduino(Boot Mode)? Thank you for helping me – Duckbenok Aug 3 '17 at 8:53
  • Sure. As long as both the Arduino and the ESP8266 have been programmed in such a way that they will work together. And that doesn't mean using AT commands since the ESP8266 would no longer understand them. – Majenko Aug 3 '17 at 8:55
0

Connect GP00 to ground This is required to flash ESP8266

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.