1
votes

I built a system which can talk to my Firebase application using ESP8266 with firebase Arduino library,

Everything works flawlessly however I now have a problem making the ESP8266 talk and listen to the Microcontroller which is StandAlone Atmega328P (The one used in Arduino Uno).

here are the points 1- cannot use softwareSerial as all the digital pins are occupied. 2- Tried different Bauds with the same issue. 3- only one time worked, where the Arduino was able to listen to the Serial correctly. but couldn't read from serial by ESP.

I am definitely able to Write Strings to the Serial from ESP and read it by Arduino but when trying to use IF statement, cannot recognize the String,

So I tried to Println the String 4 times, and this is what I got.

Lock Door

Lock Door

Lock Door

Lock Door

if anyone can address the problem, I posted the Code for both Arduino and ESP

ESP Code

void getData(){

FirebaseObject object = Firebase.get(EspMac);
String Door = object.getString("Door");
String Connection = object.getString("Connect");
if(Door == "Open Door"){
  Serial.println(Door);
  delay(100);
  Firebase.set(path3,"");
  Door = "";
}else if(Door == "Lock Door"){
  Serial.println(Door);
  delay(100);
  Firebase.set(path3,"");
  Door = "";
}else if (Connection == "Connect"){
  Firebase.set(path5,"Received");
  Connection = "";
  }

}

ARDUINO Code

do {
  if(digitalRead(wipeB) == LOW)
      servoDoorOpen ();
  while (Serial.available() > 0){
    String Door = Serial.readString();
    delay(100);
    Serial.println(Door);
    Serial.println(Door);
    Serial.println(Door);
    Serial.println(Door);


    if (Door.equals("Open Door")){
      //Serial.println("We open Doors");
      servoDoorOpen();
      Door = "";
    }
    else if (Door.equals("Lock Door")){
      //Serial.println("We Lock Doors");
        servoDoorLock();
        Door = "";
    }
  }

Thank you.

1
What's your wiring? You need a logic level converter in between the ESP8266 and the Arduino, as these are 3.3V, respectively 5V devices. Hardware Serial (RX,TX) connection works fine with level shifting, I've done this multiple times myself at a baud rate of 250,000 baud, flawlessly.Maximilian Gerhardt
I am using voltage divider, which is 2 resistors one 1k and the second 2.2k between Arduino TX and ESP8266 RX. do I need to change the resistors to something else? @MaximilianGerhardtRamiRihawi

1 Answers

0
votes

Finally I have solved my own issue, Still not quite yet sure how I resolved the problem, but I added some Delays in the code and not everything works great

void getData(){
    FirebaseObject object = Firebase.get(EspMac);
    String Door = object.getString("Door");
    String Connection = object.getString("Connect");
    if(Door == "Open Door"){
        Serial.println(Door);
        Firebase.set(path3,"");
        Door = "";
    }else if(Door == "Lock Door"){
        Serial.println(Door);
        Firebase.set(path3,"");
        Door = "";
    }else if (Connection == "Connect"){
        Firebase.set(path5,"Received");
        Connection = "";
    }  
}

void loop() {
   getData();
   while (Serial.available() > 0){
     delay (100);
     String h = Serial.readString();
     String DoorStat = h.substring(0,11);
     if (DoorStat.equals("Door Opened")){
        Firebase.set(path2, DoorStat.c_str());
        DoorStat="";
        delay(100);
     }else if (DoorStat.equals("Door Locked"))
        Firebase.set(path2, DoorStat.c_str());
   }
}

Android Code

  do {
  if(digitalRead(wipeB) == LOW)
      servoDoorOpen ();
  while (Serial.available() > 0){
    delay (100);
    String h = Serial.readString();
    String Door = h.substring(0,9);

    if (Door.equals("Open Door")){
      //Serial.println("We open Doors");
      servoDoorOpen();
      Door = "";
    }
    else if (Door.equals("Lock Door")){
      //Serial.println("We Lock Doors");
        servoDoorLock();
        Door = "";
    }
  }