I need help on RFID AND Bluetooth










0















I a student trying to send the RFID tag code via Bluetooth to my android app, but I think the code I combined doesn't work, BUT when I test them separately they work.
I am using an hc-06 and Sparkfun RFID Evaluation Shield(RFID Eval 13.56MHz)
the hc-06 Bluetooth code is



#include <SoftwareSerial.h>
int SW = 13;
void setup()

pinMode(SW, INPUT_PULLUP);
Serial.begin(9600);

void loop() `enter code here`
if (digitalRead(SW) == HIGH)
Serial.println("0");
delay(500);
else if (digitalRead(SW) ==LOW)
Serial.println("1");
delay(500);



and the Rfid reader code is



#include <SoftwareSerial.h>

SoftwareSerial rfid(7, 8);
SoftwareSerial xbee(10, 9);

//Prototypes
void check_for_notag(void);
void halt(void);
void parse(void);
void print_serial(void);
void read_serial(void);
void seek(void);
void set_flag(void);

//Global var
int flag = 0;
int Str1[11];

//INIT
void setup()

Serial.begin(9600);
Serial.println("Start");

// set the data rate for the SoftwareSerial ports
xbee.begin(9600);
rfid.begin(19200);
delay(10);
halt();


//MAIN
void loop()

read_serial();


void check_for_notag()

seek();
delay(10);
parse();
set_flag();

if(flag = 1)
seek();
delay(10);
parse();



void halt()

//Halt tag
rfid.write((uint8_t)255);
rfid.write((uint8_t)0);
rfid.write((uint8_t)1);
rfid.write((uint8_t)147);
rfid.write((uint8_t)148);


void parse()

while(rfid.available())
if(rfid.read() == 255)
for(int i=1;i<11;i++)
Str1[i]= rfid.read();





void print_serial()

if(flag == 1)
//print to serial port
Serial.print(Str1[8], HEX);
Serial.print(Str1[7], HEX);
Serial.print(Str1[6], HEX);
Serial.print(Str1[5], HEX);
Serial.println();
//print to XBee module
xbee.print(Str1[8], HEX);
xbee.print(Str1[7], HEX);
xbee.print(Str1[6], HEX);
xbee.print(Str1[5], HEX);
xbee.println();
delay(100);
//check_for_notag();



void read_serial()

seek();
delay(10);
parse();
set_flag();
print_serial();
delay(100);


void seek()

//search for RFID tag
rfid.write((uint8_t)255);
rfid.write((uint8_t)0);
rfid.write((uint8_t)1);
rfid.write((uint8_t)130);
rfid.write((uint8_t)131);
delay(10);


void set_flag()

if(Str1[2] == 6)
flag++;

if(Str1[2] == 2)
flag = 0;




and the code I combined is



#include <SoftwareSerial.h>

SoftwareSerial rfid(7, 8);
SoftwareSerial xbee(10, 9);
SoftwareSerial BT(2, 3);

//Prototypes
void check_for_notag(void);
void halt(void);
void parse(void);
void print_serial(void);
void read_serial(void);
void seek(void);
void set_flag(void);

//Global var
int flag = 0;
int Str1[11];
int a=0;
char data[3];

//INIT
void setup()

Serial.begin(9600);
Serial.println("Start");
BT.begin(9600);
// set the data rate for the SoftwareSerial ports
xbee.begin(9600);
rfid.begin(19200);
delay(10);
halt();


//MAIN
void loop()

read_serial();


void check_for_notag()

seek();
delay(10);
parse();
set_flag();

if(flag = 1)
seek();
delay(10);
parse();



void halt()

//Halt tag
rfid.write((uint8_t)255);
rfid.write((uint8_t)0);
rfid.write((uint8_t)1);
rfid.write((uint8_t)147);
rfid.write((uint8_t)148);


void parse()

while(rfid.available())
if(rfid.read() == 255)
for(int i=1;i<11;i++)
Str1[i]= rfid.read();





void print_serial()

if(flag == 1)
//print to serial port
Serial.print(Str1[8], HEX);
Serial.print(Str1[7], HEX);
Serial.print(Str1[6], HEX);
Serial.print(Str1[5], HEX);
Serial.println();
//print to XBee module
xbee.print(Str1[8], HEX);
xbee.print(Str1[7], HEX);
xbee.print(Str1[6], HEX);
xbee.print(Str1[5], HEX);
xbee.println();
delay(100);
++a;
sprintf(data, "%02d", a);
BT.print(data);
delay(1000);
//check_for_notag();



void read_serial()

seek();
delay(10);
parse();
set_flag();
print_serial();
delay(100);


void seek()

//search for RFID tag
rfid.write((uint8_t)255);
rfid.write((uint8_t)0);
rfid.write((uint8_t)1);
rfid.write((uint8_t)130);
rfid.write((uint8_t)131);
delay(10);


void set_flag()

if(Str1[2] == 6)
flag++;

if(Str1[2] == 2)
flag = 0;




is the code I combined right or if not right can you tell me where the code is wrong.










share|improve this question




























    0















    I a student trying to send the RFID tag code via Bluetooth to my android app, but I think the code I combined doesn't work, BUT when I test them separately they work.
    I am using an hc-06 and Sparkfun RFID Evaluation Shield(RFID Eval 13.56MHz)
    the hc-06 Bluetooth code is



    #include <SoftwareSerial.h>
    int SW = 13;
    void setup()

    pinMode(SW, INPUT_PULLUP);
    Serial.begin(9600);

    void loop() `enter code here`
    if (digitalRead(SW) == HIGH)
    Serial.println("0");
    delay(500);
    else if (digitalRead(SW) ==LOW)
    Serial.println("1");
    delay(500);



    and the Rfid reader code is



    #include <SoftwareSerial.h>

    SoftwareSerial rfid(7, 8);
    SoftwareSerial xbee(10, 9);

    //Prototypes
    void check_for_notag(void);
    void halt(void);
    void parse(void);
    void print_serial(void);
    void read_serial(void);
    void seek(void);
    void set_flag(void);

    //Global var
    int flag = 0;
    int Str1[11];

    //INIT
    void setup()

    Serial.begin(9600);
    Serial.println("Start");

    // set the data rate for the SoftwareSerial ports
    xbee.begin(9600);
    rfid.begin(19200);
    delay(10);
    halt();


    //MAIN
    void loop()

    read_serial();


    void check_for_notag()

    seek();
    delay(10);
    parse();
    set_flag();

    if(flag = 1)
    seek();
    delay(10);
    parse();



    void halt()

    //Halt tag
    rfid.write((uint8_t)255);
    rfid.write((uint8_t)0);
    rfid.write((uint8_t)1);
    rfid.write((uint8_t)147);
    rfid.write((uint8_t)148);


    void parse()

    while(rfid.available())
    if(rfid.read() == 255)
    for(int i=1;i<11;i++)
    Str1[i]= rfid.read();





    void print_serial()

    if(flag == 1)
    //print to serial port
    Serial.print(Str1[8], HEX);
    Serial.print(Str1[7], HEX);
    Serial.print(Str1[6], HEX);
    Serial.print(Str1[5], HEX);
    Serial.println();
    //print to XBee module
    xbee.print(Str1[8], HEX);
    xbee.print(Str1[7], HEX);
    xbee.print(Str1[6], HEX);
    xbee.print(Str1[5], HEX);
    xbee.println();
    delay(100);
    //check_for_notag();



    void read_serial()

    seek();
    delay(10);
    parse();
    set_flag();
    print_serial();
    delay(100);


    void seek()

    //search for RFID tag
    rfid.write((uint8_t)255);
    rfid.write((uint8_t)0);
    rfid.write((uint8_t)1);
    rfid.write((uint8_t)130);
    rfid.write((uint8_t)131);
    delay(10);


    void set_flag()

    if(Str1[2] == 6)
    flag++;

    if(Str1[2] == 2)
    flag = 0;




    and the code I combined is



    #include <SoftwareSerial.h>

    SoftwareSerial rfid(7, 8);
    SoftwareSerial xbee(10, 9);
    SoftwareSerial BT(2, 3);

    //Prototypes
    void check_for_notag(void);
    void halt(void);
    void parse(void);
    void print_serial(void);
    void read_serial(void);
    void seek(void);
    void set_flag(void);

    //Global var
    int flag = 0;
    int Str1[11];
    int a=0;
    char data[3];

    //INIT
    void setup()

    Serial.begin(9600);
    Serial.println("Start");
    BT.begin(9600);
    // set the data rate for the SoftwareSerial ports
    xbee.begin(9600);
    rfid.begin(19200);
    delay(10);
    halt();


    //MAIN
    void loop()

    read_serial();


    void check_for_notag()

    seek();
    delay(10);
    parse();
    set_flag();

    if(flag = 1)
    seek();
    delay(10);
    parse();



    void halt()

    //Halt tag
    rfid.write((uint8_t)255);
    rfid.write((uint8_t)0);
    rfid.write((uint8_t)1);
    rfid.write((uint8_t)147);
    rfid.write((uint8_t)148);


    void parse()

    while(rfid.available())
    if(rfid.read() == 255)
    for(int i=1;i<11;i++)
    Str1[i]= rfid.read();





    void print_serial()

    if(flag == 1)
    //print to serial port
    Serial.print(Str1[8], HEX);
    Serial.print(Str1[7], HEX);
    Serial.print(Str1[6], HEX);
    Serial.print(Str1[5], HEX);
    Serial.println();
    //print to XBee module
    xbee.print(Str1[8], HEX);
    xbee.print(Str1[7], HEX);
    xbee.print(Str1[6], HEX);
    xbee.print(Str1[5], HEX);
    xbee.println();
    delay(100);
    ++a;
    sprintf(data, "%02d", a);
    BT.print(data);
    delay(1000);
    //check_for_notag();



    void read_serial()

    seek();
    delay(10);
    parse();
    set_flag();
    print_serial();
    delay(100);


    void seek()

    //search for RFID tag
    rfid.write((uint8_t)255);
    rfid.write((uint8_t)0);
    rfid.write((uint8_t)1);
    rfid.write((uint8_t)130);
    rfid.write((uint8_t)131);
    delay(10);


    void set_flag()

    if(Str1[2] == 6)
    flag++;

    if(Str1[2] == 2)
    flag = 0;




    is the code I combined right or if not right can you tell me where the code is wrong.










    share|improve this question


























      0












      0








      0


      0






      I a student trying to send the RFID tag code via Bluetooth to my android app, but I think the code I combined doesn't work, BUT when I test them separately they work.
      I am using an hc-06 and Sparkfun RFID Evaluation Shield(RFID Eval 13.56MHz)
      the hc-06 Bluetooth code is



      #include <SoftwareSerial.h>
      int SW = 13;
      void setup()

      pinMode(SW, INPUT_PULLUP);
      Serial.begin(9600);

      void loop() `enter code here`
      if (digitalRead(SW) == HIGH)
      Serial.println("0");
      delay(500);
      else if (digitalRead(SW) ==LOW)
      Serial.println("1");
      delay(500);



      and the Rfid reader code is



      #include <SoftwareSerial.h>

      SoftwareSerial rfid(7, 8);
      SoftwareSerial xbee(10, 9);

      //Prototypes
      void check_for_notag(void);
      void halt(void);
      void parse(void);
      void print_serial(void);
      void read_serial(void);
      void seek(void);
      void set_flag(void);

      //Global var
      int flag = 0;
      int Str1[11];

      //INIT
      void setup()

      Serial.begin(9600);
      Serial.println("Start");

      // set the data rate for the SoftwareSerial ports
      xbee.begin(9600);
      rfid.begin(19200);
      delay(10);
      halt();


      //MAIN
      void loop()

      read_serial();


      void check_for_notag()

      seek();
      delay(10);
      parse();
      set_flag();

      if(flag = 1)
      seek();
      delay(10);
      parse();



      void halt()

      //Halt tag
      rfid.write((uint8_t)255);
      rfid.write((uint8_t)0);
      rfid.write((uint8_t)1);
      rfid.write((uint8_t)147);
      rfid.write((uint8_t)148);


      void parse()

      while(rfid.available())
      if(rfid.read() == 255)
      for(int i=1;i<11;i++)
      Str1[i]= rfid.read();





      void print_serial()

      if(flag == 1)
      //print to serial port
      Serial.print(Str1[8], HEX);
      Serial.print(Str1[7], HEX);
      Serial.print(Str1[6], HEX);
      Serial.print(Str1[5], HEX);
      Serial.println();
      //print to XBee module
      xbee.print(Str1[8], HEX);
      xbee.print(Str1[7], HEX);
      xbee.print(Str1[6], HEX);
      xbee.print(Str1[5], HEX);
      xbee.println();
      delay(100);
      //check_for_notag();



      void read_serial()

      seek();
      delay(10);
      parse();
      set_flag();
      print_serial();
      delay(100);


      void seek()

      //search for RFID tag
      rfid.write((uint8_t)255);
      rfid.write((uint8_t)0);
      rfid.write((uint8_t)1);
      rfid.write((uint8_t)130);
      rfid.write((uint8_t)131);
      delay(10);


      void set_flag()

      if(Str1[2] == 6)
      flag++;

      if(Str1[2] == 2)
      flag = 0;




      and the code I combined is



      #include <SoftwareSerial.h>

      SoftwareSerial rfid(7, 8);
      SoftwareSerial xbee(10, 9);
      SoftwareSerial BT(2, 3);

      //Prototypes
      void check_for_notag(void);
      void halt(void);
      void parse(void);
      void print_serial(void);
      void read_serial(void);
      void seek(void);
      void set_flag(void);

      //Global var
      int flag = 0;
      int Str1[11];
      int a=0;
      char data[3];

      //INIT
      void setup()

      Serial.begin(9600);
      Serial.println("Start");
      BT.begin(9600);
      // set the data rate for the SoftwareSerial ports
      xbee.begin(9600);
      rfid.begin(19200);
      delay(10);
      halt();


      //MAIN
      void loop()

      read_serial();


      void check_for_notag()

      seek();
      delay(10);
      parse();
      set_flag();

      if(flag = 1)
      seek();
      delay(10);
      parse();



      void halt()

      //Halt tag
      rfid.write((uint8_t)255);
      rfid.write((uint8_t)0);
      rfid.write((uint8_t)1);
      rfid.write((uint8_t)147);
      rfid.write((uint8_t)148);


      void parse()

      while(rfid.available())
      if(rfid.read() == 255)
      for(int i=1;i<11;i++)
      Str1[i]= rfid.read();





      void print_serial()

      if(flag == 1)
      //print to serial port
      Serial.print(Str1[8], HEX);
      Serial.print(Str1[7], HEX);
      Serial.print(Str1[6], HEX);
      Serial.print(Str1[5], HEX);
      Serial.println();
      //print to XBee module
      xbee.print(Str1[8], HEX);
      xbee.print(Str1[7], HEX);
      xbee.print(Str1[6], HEX);
      xbee.print(Str1[5], HEX);
      xbee.println();
      delay(100);
      ++a;
      sprintf(data, "%02d", a);
      BT.print(data);
      delay(1000);
      //check_for_notag();



      void read_serial()

      seek();
      delay(10);
      parse();
      set_flag();
      print_serial();
      delay(100);


      void seek()

      //search for RFID tag
      rfid.write((uint8_t)255);
      rfid.write((uint8_t)0);
      rfid.write((uint8_t)1);
      rfid.write((uint8_t)130);
      rfid.write((uint8_t)131);
      delay(10);


      void set_flag()

      if(Str1[2] == 6)
      flag++;

      if(Str1[2] == 2)
      flag = 0;




      is the code I combined right or if not right can you tell me where the code is wrong.










      share|improve this question
















      I a student trying to send the RFID tag code via Bluetooth to my android app, but I think the code I combined doesn't work, BUT when I test them separately they work.
      I am using an hc-06 and Sparkfun RFID Evaluation Shield(RFID Eval 13.56MHz)
      the hc-06 Bluetooth code is



      #include <SoftwareSerial.h>
      int SW = 13;
      void setup()

      pinMode(SW, INPUT_PULLUP);
      Serial.begin(9600);

      void loop() `enter code here`
      if (digitalRead(SW) == HIGH)
      Serial.println("0");
      delay(500);
      else if (digitalRead(SW) ==LOW)
      Serial.println("1");
      delay(500);



      and the Rfid reader code is



      #include <SoftwareSerial.h>

      SoftwareSerial rfid(7, 8);
      SoftwareSerial xbee(10, 9);

      //Prototypes
      void check_for_notag(void);
      void halt(void);
      void parse(void);
      void print_serial(void);
      void read_serial(void);
      void seek(void);
      void set_flag(void);

      //Global var
      int flag = 0;
      int Str1[11];

      //INIT
      void setup()

      Serial.begin(9600);
      Serial.println("Start");

      // set the data rate for the SoftwareSerial ports
      xbee.begin(9600);
      rfid.begin(19200);
      delay(10);
      halt();


      //MAIN
      void loop()

      read_serial();


      void check_for_notag()

      seek();
      delay(10);
      parse();
      set_flag();

      if(flag = 1)
      seek();
      delay(10);
      parse();



      void halt()

      //Halt tag
      rfid.write((uint8_t)255);
      rfid.write((uint8_t)0);
      rfid.write((uint8_t)1);
      rfid.write((uint8_t)147);
      rfid.write((uint8_t)148);


      void parse()

      while(rfid.available())
      if(rfid.read() == 255)
      for(int i=1;i<11;i++)
      Str1[i]= rfid.read();





      void print_serial()

      if(flag == 1)
      //print to serial port
      Serial.print(Str1[8], HEX);
      Serial.print(Str1[7], HEX);
      Serial.print(Str1[6], HEX);
      Serial.print(Str1[5], HEX);
      Serial.println();
      //print to XBee module
      xbee.print(Str1[8], HEX);
      xbee.print(Str1[7], HEX);
      xbee.print(Str1[6], HEX);
      xbee.print(Str1[5], HEX);
      xbee.println();
      delay(100);
      //check_for_notag();



      void read_serial()

      seek();
      delay(10);
      parse();
      set_flag();
      print_serial();
      delay(100);


      void seek()

      //search for RFID tag
      rfid.write((uint8_t)255);
      rfid.write((uint8_t)0);
      rfid.write((uint8_t)1);
      rfid.write((uint8_t)130);
      rfid.write((uint8_t)131);
      delay(10);


      void set_flag()

      if(Str1[2] == 6)
      flag++;

      if(Str1[2] == 2)
      flag = 0;




      and the code I combined is



      #include <SoftwareSerial.h>

      SoftwareSerial rfid(7, 8);
      SoftwareSerial xbee(10, 9);
      SoftwareSerial BT(2, 3);

      //Prototypes
      void check_for_notag(void);
      void halt(void);
      void parse(void);
      void print_serial(void);
      void read_serial(void);
      void seek(void);
      void set_flag(void);

      //Global var
      int flag = 0;
      int Str1[11];
      int a=0;
      char data[3];

      //INIT
      void setup()

      Serial.begin(9600);
      Serial.println("Start");
      BT.begin(9600);
      // set the data rate for the SoftwareSerial ports
      xbee.begin(9600);
      rfid.begin(19200);
      delay(10);
      halt();


      //MAIN
      void loop()

      read_serial();


      void check_for_notag()

      seek();
      delay(10);
      parse();
      set_flag();

      if(flag = 1)
      seek();
      delay(10);
      parse();



      void halt()

      //Halt tag
      rfid.write((uint8_t)255);
      rfid.write((uint8_t)0);
      rfid.write((uint8_t)1);
      rfid.write((uint8_t)147);
      rfid.write((uint8_t)148);


      void parse()

      while(rfid.available())
      if(rfid.read() == 255)
      for(int i=1;i<11;i++)
      Str1[i]= rfid.read();





      void print_serial()

      if(flag == 1)
      //print to serial port
      Serial.print(Str1[8], HEX);
      Serial.print(Str1[7], HEX);
      Serial.print(Str1[6], HEX);
      Serial.print(Str1[5], HEX);
      Serial.println();
      //print to XBee module
      xbee.print(Str1[8], HEX);
      xbee.print(Str1[7], HEX);
      xbee.print(Str1[6], HEX);
      xbee.print(Str1[5], HEX);
      xbee.println();
      delay(100);
      ++a;
      sprintf(data, "%02d", a);
      BT.print(data);
      delay(1000);
      //check_for_notag();



      void read_serial()

      seek();
      delay(10);
      parse();
      set_flag();
      print_serial();
      delay(100);


      void seek()

      //search for RFID tag
      rfid.write((uint8_t)255);
      rfid.write((uint8_t)0);
      rfid.write((uint8_t)1);
      rfid.write((uint8_t)130);
      rfid.write((uint8_t)131);
      delay(10);


      void set_flag()

      if(Str1[2] == 6)
      flag++;

      if(Str1[2] == 2)
      flag = 0;




      is the code I combined right or if not right can you tell me where the code is wrong.







      bluetooth rfid






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 '18 at 16:40







      danieloh1111

















      asked Nov 13 '18 at 14:21









      danieloh1111danieloh1111

      12




      12






















          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53283116%2fi-need-help-on-rfid-and-bluetooth%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53283116%2fi-need-help-on-rfid-and-bluetooth%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          How to read a connectionString WITH PROVIDER in .NET Core?

          Node.js Script on GitHub Pages or Amazon S3

          Museum of Modern and Contemporary Art of Trento and Rovereto