0

I have connected esp8266 with Arduino Uno and programmed 8266 with Arduino IDE to send data to firebase over WiFi. Now I also want to interface EM18 RFID Reader with Arduino in order to read the RFID tag and send information to firebase through esp8266. I have integrated the code for the same.

Now after uploading the code, only one of the interface works at a time, i.e if both esp8266 and EM18 are connected to Arduino, esp8266 connects to WiFi and sends data(verification data to check esp8366 is working) also, but not the data I want because EM18 is not reading the tag id. Having uploaded the same code if I remove connections with esp8266, the EM18 works fine(i.e. ID is printed in serial monitor after being read by EM18 Reader module).

Please help me with this, how can I send the information read by EM18 to esp8266 because they are not working together.

P.S. In my code there is different Rx Tx pin defined for esp8266(digital pin 0,1) and for EM18(digital pin 9,10(random)). Used softwareserial library for defining new Rx Tx.

My Connections:

Arduino and ESP8266 RX with RX; TX with TX; GND with GND; 3.3V with VCC; 3.3v with CH_PD; GND with GPIO0(To Flash ESP8266);

Arduino's Reset pin is connected to Ground

Arduino and EM18 RFID Module 5v wuth VCC; GND with GND; Pin 13(Set as Rx) with TX;

My Code:

#include <BearSSLHelpers.h>
#include <CertStoreBearSSL.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiAP.h>
#include <ESP8266WiFiGeneric.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266WiFiScan.h>
#include <ESP8266WiFiSTA.h>
#include <ESP8266WiFiType.h>
#include <WiFiClient.h>
#include <WiFiClientSecure.h>
#include <WiFiClientSecureAxTLS.h>
#include <WiFiClientSecureBearSSL.h>
#include <WiFiServer.h>
#include <WiFiServerSecure.h>
#include <WiFiServerSecureAxTLS.h>
#include <WiFiServerSecureBearSSL.h>
#include <WiFiUdp.h>

#include <Firebase.h>
#include <FirebaseArduino.h>
#include <FirebaseCloudMessaging.h>
#include <FirebaseError.h>
#include <FirebaseHttpClient.h>
#include <FirebaseObject.h>

#include <ArduinoJson.h>

#include <SoftwareSerial.h>
//firebase and wifi 
#define FIREBASE_HOST "my-shopping-d.firebaseio.com"
#define FIREBASE_AUTH "rkyF4AuzssSIO5VYRO6iP"  
#define WIFI_SSID "****"  
#define WIFI_PASSWORD "****" 

const int disp=9;
//int j;
int tx=10,rx=13;
SoftwareSerial emSerial(rx,tx);  //EM18 Rx,Tx 
int buttonState2 = 0;   
int count = 0;                                          // count = 0
char input[12];                                         // character array of size 12 
int count_arr[5]={0,0,0,0,0};
int i,cnt,total=0;
int price[5]={295,20,50,500,15};
char id_arr[6]={'2','F','7','E','3'};
char *myStrings1[] = {"Rice Rs.295", "Oreo Rs.20", "Silk Rs.50",
                     "Ghee Rs.500", "Nestle Rs.15", "TOTAL : "
                    };
char *myStrings2[] = {"Removed Rice Rs.295", "Removed Oreo Rs.20", "Removed Silk Rs.50",
                     "Removed Ghee Rs.500", "Removed Nestle Rs.15", "TOTAL : "
                    };

void setup()
{
   Serial.begin(9600);
   emSerial.begin(9600);


   //connect to wi-fi
   WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("connecting");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);

   pinMode(disp,INPUT);
}
 Serial.println();
  Serial.print("connected: ");
  Serial.println(WiFi.localIP());

  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
  Serial.println("Firebase Connected");
}

int n = 0;

void loop()
{


   if(emSerial.available())
   {
    Serial.println("Card reader");
      count=0;
      while(emSerial.available() && count < 12)          // Read 12 characters and store them in input array
      {
         input[count] = emSerial.read();
         count++;
         delay(5);
      }
      Serial.print("id inpiut");
      Serial.println(input);
      for(i=0;i<5;i++)
      {
        if(input[10] == id_arr[i])
        {
          cnt=i;
          break;
        }
      }

      if(count_arr[cnt] == 0)
      {
        total=total+price[cnt];
        Serial.println(myStrings1[cnt]);
        Serial.print("TOTAL : ");
        Serial.println(total);
        count_arr[cnt]=1;
      }
      else if(count_arr[cnt] == 1)
      {
        total=total-price[cnt];
        Serial.println(myStrings2[cnt]);
        Serial.print("TOTAL : ");
        Serial.println(total);
        count_arr[cnt]=0;
      }

   } 
      buttonState2 = digitalRead(disp);   // read the state of the pushbutton value:

      // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
      if (buttonState2 == HIGH)
      {

        j=1;
        for(i=0;i<5;i++)
        {
          if(count_arr[i]==1)
          {

            Firebase.setString("Items in Cart: ", myStrings1[i]);
             // handle error
            if (Firebase.failed()) 
            {
               Serial.print("setting /message failed:");
               Serial.println(Firebase.error());  
               return;
            }
            delay(1000);
            String name = Firebase.pushInt("Total: ",total);
             // handle error
            if (Firebase.failed()) 
            {
                Serial.print("pushing /logs failed:");
                Serial.println(Firebase.error());  
                return;
             }
            //j++;
          }
          delay(2000);

        }
      }
      int test = 5;
  String name = Firebase.pushInt("cart",test);
  // handle error
  if (Firebase.failed()) {
      Serial.print("pushing /logs failed:");
      Serial.println(Firebase.error());  
      return;
  }
  Serial.print("pushed: /cart/");
}
  • You can only reliably (for given values of "reliably") use one SoftwareSerial at a time. – Majenko Apr 24 at 22:26
  • I have added connections and code, plz see and reply :) – Baz_83 Apr 25 at 8:55
  • Do you have the EM18 wired to the Arduino's pins 10 and 13, or the ESP8266's pins 10 and 13? – Majenko Apr 25 at 9:23
  • Em18 is wired with pin 13, i do not need tx pin for em18(only one way communication), and esp8266 is connected with default tx rx pins of arduino – Baz_83 Apr 25 at 9:26
  • Which pin 13? ESP8266 pin 13, or Arduino pin 13? – Majenko Apr 25 at 10:12

Your Answer

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

Browse other questions tagged or ask your own question.