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
In my understanding, there are 2 ways to use this wifi module.
Upload the code to the Arduino Uno and use AT commands in the module to send data to the web.
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:
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:
Can I input/flash code in my module using my Arduino and adapter?
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?
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!