Skip to main content
Fixed syntax highlighting.
Source Link
VE7JRO
  • 2.5k
  • 19
  • 28
  • 31

//SMALLER SMALLER PROGRAM - THAT WORKS

#include <SoftwareSerial.h>

SoftwareSerial btSerial(8,9); // RX, TX

void setup() {
  Serial.begin(9600);
  btSerial.begin(9600);
}

void loop() {
  //Send everything from PC-Console
  while( Serial.available() )
  {
     btSerial.write( Serial.read() ); 
  }

  //Show everything received with bluetooth to PC-Console
  if(btSerial.available())
  {
    while(btSerial.available())
          Serial.write((char)btSerial.read());
          
    Serial.println("");
  }
}
#include <SoftwareSerial.h>

SoftwareSerial btSerial(8,9); // RX, TX

void setup() {
  Serial.begin(9600);
  btSerial.begin(9600);
}

void loop() {
  //Send everything from PC-Console
  while( Serial.available() )
  {
     btSerial.write( Serial.read() ); 
  }

  //Show everything received with bluetooth to PC-Console
  if(btSerial.available())
  {
    while(btSerial.available())
          Serial.write((char)btSerial.read());
          
    Serial.println("");
  }
}

//ORIGINAL ORIGINAL PROGRAM - PROBLEM

#include <SoftwareSerial.h>


SoftwareSerial btSerial(8, 9); //RX TX
SoftwareSerial rfidSerial(11, 12);

char tagCollection4][13] = { {"6A003D68AA95"},
                             {"6A003D8879A6"},
                             {"6A003D49617F"},
                             {"6A003A426775"} }; 
                            
String tagCollection_str[4] = {"6A003D68AA95", 
                               "6A003D8879A6", 
                               "6A003D49617F",
                               "6A003A426775"};


bool tagsFound[4] = {false, false, false, false};

void setup() {
  
 Serial.begin(9600);
 btSerial.begin(9600);
 rfidSerial.begin(9600); 
}


void loop() {  
  
 //Send everything from PC-Console to Bluetooth device | that part works 
  while( Serial.available()  )
  {
    btSerial.write( Serial.read() ); 
  }
  
  //Show everything received with Bluetooth device on my PC-Console
  if( btSerial.available() )
  { 
     while(btSerial.available())
              Serial.write((char)btSerial.read());
    
    Serial.println("");
  }
 
  //Here starts the Rfid Part that I’ve done first it works mostly
  char tagString[13];
  int index = 0;
  boolean reading = false;
  
  if(rfidSerial.available() )
  {
    while( rfidSerial.available() )
    {
      int readByte = rfidSerial.read(); //read next available byte

      if(readByte == 2) reading = true; //begining of tag
      if(readByte == 3) reading = false; //end of tag

      if(reading && readByte != 2 && readByte != 10 && readByte != 13){
        //store the tag
        tagString[index] = readByte;
        index ++;
      } 
    }
    
    delay(50);
  }

  checkTag(tagString); 
  clearTag(tagString); //Clear the char of all value
*/
}
  
void checkTag( char tag[] )
{
  if(strlen(tag) == 0) {return;}
  
  int tagNum = compareTag( tag );
  
  if( tagNum == -1 )
  {
    Serial.println("");
    Serial.println("NO MATCH");
    Serial.println("");
  }
  else 
  {
   if( !tagsFound[tagNum] )
   {
      tagsFound[tagNum] = true;
   }
   else
   {
     tagsFound[tagNum] = false;
   }  
   //Just a little delay
   delay(2000);
  }

  //Show the scanned tag
  Serial.println("");
  for( int i=0; i<13; i++ )
  {
   Serial.write(tag[i]); 
  }
  
  Serial.println("");
  
  for(int i=0; i<4; i++)
  {
      Serial.println( tagsFound[i] );
  }
  
  Serial.println("");
  Serial.println("");
  
}

int compareTag( String tag )
{

  if(tag[9] == tagCollection4[0][9])
      return 0;
  
  if(tag[9] == tagCollection4[1][9])
      return 1; 
  
 if(tag[9] == tagCollection4[2][9])
      return 2;
  
  if(tag[9] == tagCollection4[3][9])
      return 3;
  
  return -1;
}


void clearTag(char one[]){
///////////////////////////////////
//clear the char array by filling with null - ASCII 0
//Will think same tag has been read otherwise
///////////////////////////////////
  for(int i = 0; i < strlen(one); i++){
    one[i] = 0;
  }
}
#include <SoftwareSerial.h>

SoftwareSerial btSerial(8, 9); //RX TX
SoftwareSerial rfidSerial(11, 12);

char tagCollection4][13] = { {"6A003D68AA95"},
                             {"6A003D8879A6"},
                             {"6A003D49617F"},
                             {"6A003A426775"} }; 
                            
String tagCollection_str[4] = {"6A003D68AA95", 
                               "6A003D8879A6", 
                               "6A003D49617F",
                               "6A003A426775"};


bool tagsFound[4] = {false, false, false, false};

void setup() {
  Serial.begin(9600);
  btSerial.begin(9600);
  rfidSerial.begin(9600); 
}

void loop() {  
  
 //Send everything from PC-Console to Bluetooth device | that part works 
  while( Serial.available()  )
  {
    btSerial.write( Serial.read() ); 
  }
  
  //Show everything received with Bluetooth device on my PC-Console
  if( btSerial.available() )
  { 
     while(btSerial.available())
              Serial.write((char)btSerial.read());
    
    Serial.println("");
  }
 
  //Here starts the Rfid Part that I’ve done first it works mostly
  char tagString[13];
  int index = 0;
  boolean reading = false;
  
  if(rfidSerial.available() )
  {
    while( rfidSerial.available() )
    {
      int readByte = rfidSerial.read(); //read next available byte

      if(readByte == 2) reading = true; //begining of tag
      if(readByte == 3) reading = false; //end of tag

      if(reading && readByte != 2 && readByte != 10 && readByte != 13){
        //store the tag
        tagString[index] = readByte;
        index ++;
      } 
    }
    
    delay(50);
  }

  checkTag(tagString); 
  clearTag(tagString); //Clear the char of all value
*/
}
  
void checkTag( char tag[] )
{
  if(strlen(tag) == 0) {return;}
  
  int tagNum = compareTag( tag );
  
  if( tagNum == -1 )
  {
    Serial.println("");
    Serial.println("NO MATCH");
    Serial.println("");
  }
  else 
  {
   if( !tagsFound[tagNum] )
   {
      tagsFound[tagNum] = true;
   }
   else
   {
     tagsFound[tagNum] = false;
   }  
   //Just a little delay
   delay(2000);
  }

  //Show the scanned tag
  Serial.println("");
  for( int i=0; i<13; i++ )
  {
   Serial.write(tag[i]); 
  }
  
  Serial.println("");
  
  for(int i=0; i<4; i++)
  {
      Serial.println( tagsFound[i] );
  }
  
  Serial.println("");
  Serial.println("");
  
}

int compareTag( String tag )
{

  if(tag[9] == tagCollection4[0][9])
      return 0;
  
  if(tag[9] == tagCollection4[1][9])
      return 1; 
  
 if(tag[9] == tagCollection4[2][9])
      return 2;
  
  if(tag[9] == tagCollection4[3][9])
      return 3;
  
  return -1;
}


void clearTag(char one[]){
///////////////////////////////////
//clear the char array by filling with null - ASCII 0
//Will think same tag has been read otherwise
///////////////////////////////////
  for(int i = 0; i < strlen(one); i++){
    one[i] = 0;
  }
}

//SMALLER PROGRAM - THAT WORKS

#include <SoftwareSerial.h>

SoftwareSerial btSerial(8,9); // RX, TX

void setup() {
  Serial.begin(9600);
  btSerial.begin(9600);
}

void loop() {
  //Send everything from PC-Console
  while( Serial.available() )
  {
     btSerial.write( Serial.read() ); 
  }

  //Show everything received with bluetooth to PC-Console
  if(btSerial.available())
  {
    while(btSerial.available())
          Serial.write((char)btSerial.read());
          
    Serial.println("");
  }
}

//ORIGINAL PROGRAM - PROBLEM

#include <SoftwareSerial.h>


SoftwareSerial btSerial(8, 9); //RX TX
SoftwareSerial rfidSerial(11, 12);

char tagCollection4][13] = { {"6A003D68AA95"},
                             {"6A003D8879A6"},
                             {"6A003D49617F"},
                             {"6A003A426775"} }; 
                            
String tagCollection_str[4] = {"6A003D68AA95", 
                               "6A003D8879A6", 
                               "6A003D49617F",
                               "6A003A426775"};


bool tagsFound[4] = {false, false, false, false};

void setup() {
  
 Serial.begin(9600);
 btSerial.begin(9600);
 rfidSerial.begin(9600); 
}


void loop() {  
  
 //Send everything from PC-Console to Bluetooth device | that part works 
  while( Serial.available()  )
  {
    btSerial.write( Serial.read() ); 
  }
  
  //Show everything received with Bluetooth device on my PC-Console
  if( btSerial.available() )
  { 
     while(btSerial.available())
              Serial.write((char)btSerial.read());
    
    Serial.println("");
  }
 
  //Here starts the Rfid Part that I’ve done first it works mostly
  char tagString[13];
  int index = 0;
  boolean reading = false;
  
  if(rfidSerial.available() )
  {
    while( rfidSerial.available() )
    {
      int readByte = rfidSerial.read(); //read next available byte

      if(readByte == 2) reading = true; //begining of tag
      if(readByte == 3) reading = false; //end of tag

      if(reading && readByte != 2 && readByte != 10 && readByte != 13){
        //store the tag
        tagString[index] = readByte;
        index ++;
      } 
    }
    
    delay(50);
  }

  checkTag(tagString); 
  clearTag(tagString); //Clear the char of all value
*/
}
  
void checkTag( char tag[] )
{
  if(strlen(tag) == 0) {return;}
  
  int tagNum = compareTag( tag );
  
  if( tagNum == -1 )
  {
    Serial.println("");
    Serial.println("NO MATCH");
    Serial.println("");
  }
  else 
  {
   if( !tagsFound[tagNum] )
   {
      tagsFound[tagNum] = true;
   }
   else
   {
     tagsFound[tagNum] = false;
   }  
   //Just a little delay
   delay(2000);
  }

  //Show the scanned tag
  Serial.println("");
  for( int i=0; i<13; i++ )
  {
   Serial.write(tag[i]); 
  }
  
  Serial.println("");
  
  for(int i=0; i<4; i++)
  {
      Serial.println( tagsFound[i] );
  }
  
  Serial.println("");
  Serial.println("");
  
}

int compareTag( String tag )
{

  if(tag[9] == tagCollection4[0][9])
      return 0;
  
  if(tag[9] == tagCollection4[1][9])
      return 1; 
  
 if(tag[9] == tagCollection4[2][9])
      return 2;
  
  if(tag[9] == tagCollection4[3][9])
      return 3;
  
  return -1;
}


void clearTag(char one[]){
///////////////////////////////////
//clear the char array by filling with null - ASCII 0
//Will think same tag has been read otherwise
///////////////////////////////////
  for(int i = 0; i < strlen(one); i++){
    one[i] = 0;
  }
}

SMALLER PROGRAM - THAT WORKS

#include <SoftwareSerial.h>

SoftwareSerial btSerial(8,9); // RX, TX

void setup() {
  Serial.begin(9600);
  btSerial.begin(9600);
}

void loop() {
  //Send everything from PC-Console
  while( Serial.available() )
  {
     btSerial.write( Serial.read() ); 
  }

  //Show everything received with bluetooth to PC-Console
  if(btSerial.available())
  {
    while(btSerial.available())
          Serial.write((char)btSerial.read());
          
    Serial.println("");
  }
}

ORIGINAL PROGRAM - PROBLEM

#include <SoftwareSerial.h>

SoftwareSerial btSerial(8, 9); //RX TX
SoftwareSerial rfidSerial(11, 12);

char tagCollection4][13] = { {"6A003D68AA95"},
                             {"6A003D8879A6"},
                             {"6A003D49617F"},
                             {"6A003A426775"} }; 
                            
String tagCollection_str[4] = {"6A003D68AA95", 
                               "6A003D8879A6", 
                               "6A003D49617F",
                               "6A003A426775"};


bool tagsFound[4] = {false, false, false, false};

void setup() {
  Serial.begin(9600);
  btSerial.begin(9600);
  rfidSerial.begin(9600); 
}

void loop() {  
  
 //Send everything from PC-Console to Bluetooth device | that part works 
  while( Serial.available()  )
  {
    btSerial.write( Serial.read() ); 
  }
  
  //Show everything received with Bluetooth device on my PC-Console
  if( btSerial.available() )
  { 
     while(btSerial.available())
              Serial.write((char)btSerial.read());
    
    Serial.println("");
  }
 
  //Here starts the Rfid Part that I’ve done first it works mostly
  char tagString[13];
  int index = 0;
  boolean reading = false;
  
  if(rfidSerial.available() )
  {
    while( rfidSerial.available() )
    {
      int readByte = rfidSerial.read(); //read next available byte

      if(readByte == 2) reading = true; //begining of tag
      if(readByte == 3) reading = false; //end of tag

      if(reading && readByte != 2 && readByte != 10 && readByte != 13){
        //store the tag
        tagString[index] = readByte;
        index ++;
      } 
    }
    
    delay(50);
  }

  checkTag(tagString); 
  clearTag(tagString); //Clear the char of all value
*/
}
  
void checkTag( char tag[] )
{
  if(strlen(tag) == 0) {return;}
  
  int tagNum = compareTag( tag );
  
  if( tagNum == -1 )
  {
    Serial.println("");
    Serial.println("NO MATCH");
    Serial.println("");
  }
  else 
  {
   if( !tagsFound[tagNum] )
   {
      tagsFound[tagNum] = true;
   }
   else
   {
     tagsFound[tagNum] = false;
   }  
   //Just a little delay
   delay(2000);
  }

  //Show the scanned tag
  Serial.println("");
  for( int i=0; i<13; i++ )
  {
   Serial.write(tag[i]); 
  }
  
  Serial.println("");
  
  for(int i=0; i<4; i++)
  {
      Serial.println( tagsFound[i] );
  }
  
  Serial.println("");
  Serial.println("");
  
}

int compareTag( String tag )
{

  if(tag[9] == tagCollection4[0][9])
      return 0;
  
  if(tag[9] == tagCollection4[1][9])
      return 1; 
  
 if(tag[9] == tagCollection4[2][9])
      return 2;
  
  if(tag[9] == tagCollection4[3][9])
      return 3;
  
  return -1;
}


void clearTag(char one[]){
///////////////////////////////////
//clear the char array by filling with null - ASCII 0
//Will think same tag has been read otherwise
///////////////////////////////////
  for(int i = 0; i < strlen(one); i++){
    one[i] = 0;
  }
}
added 6 characters in body
Source Link
Robin
  • 133
  • 6

I thought everything is fine so I've changed a few things in my original code. But still not receiving anythingthe Arduino receives nothing, sending is no problem.

I thought everything is fine so I've changed a few things in my original code. But still not receiving anything, sending is no problem.

I thought everything is fine so I've changed a few things in my original code. But still the Arduino receives nothing, sending is no problem.

Source Link
Robin
  • 133
  • 6

Arduino code issue (using Bluetooth and Rfid technology)

I am building a device that communicates with my Android phone. I know that my App works but my Arduino code seems to have a problem. So I have made a smaller programm and everything works fine there.

//SMALLER PROGRAM - THAT WORKS

#include <SoftwareSerial.h>

SoftwareSerial btSerial(8,9); // RX, TX

void setup() {
  Serial.begin(9600);
  btSerial.begin(9600);
}

void loop() {
  //Send everything from PC-Console
  while( Serial.available() )
  {
     btSerial.write( Serial.read() ); 
  }

  //Show everything received with bluetooth to PC-Console
  if(btSerial.available())
  {
    while(btSerial.available())
          Serial.write((char)btSerial.read());
          
    Serial.println("");
  }
}

I thought everything is fine so I've changed a few things in my original code. But still not receiving anything, sending is no problem.

//ORIGINAL PROGRAM - PROBLEM

#include <SoftwareSerial.h>


SoftwareSerial btSerial(8, 9); //RX TX
SoftwareSerial rfidSerial(11, 12);

char tagCollection4][13] = { {"6A003D68AA95"},
                             {"6A003D8879A6"},
                             {"6A003D49617F"},
                             {"6A003A426775"} }; 
                            
String tagCollection_str[4] = {"6A003D68AA95", 
                               "6A003D8879A6", 
                               "6A003D49617F",
                               "6A003A426775"};


bool tagsFound[4] = {false, false, false, false};

void setup() {
  
 Serial.begin(9600);
 btSerial.begin(9600);
 rfidSerial.begin(9600); 
}


void loop() {  
  
 //Send everything from PC-Console to Bluetooth device | that part works 
  while( Serial.available()  )
  {
    btSerial.write( Serial.read() ); 
  }
  
  //Show everything received with Bluetooth device on my PC-Console
  if( btSerial.available() )
  { 
     while(btSerial.available())
              Serial.write((char)btSerial.read());
    
    Serial.println("");
  }
 
  //Here starts the Rfid Part that I’ve done first it works mostly
  char tagString[13];
  int index = 0;
  boolean reading = false;
  
  if(rfidSerial.available() )
  {
    while( rfidSerial.available() )
    {
      int readByte = rfidSerial.read(); //read next available byte

      if(readByte == 2) reading = true; //begining of tag
      if(readByte == 3) reading = false; //end of tag

      if(reading && readByte != 2 && readByte != 10 && readByte != 13){
        //store the tag
        tagString[index] = readByte;
        index ++;
      } 
    }
    
    delay(50);
  }

  checkTag(tagString); 
  clearTag(tagString); //Clear the char of all value
*/
}
  
void checkTag( char tag[] )
{
  if(strlen(tag) == 0) {return;}
  
  int tagNum = compareTag( tag );
  
  if( tagNum == -1 )
  {
    Serial.println("");
    Serial.println("NO MATCH");
    Serial.println("");
  }
  else 
  {
   if( !tagsFound[tagNum] )
   {
      tagsFound[tagNum] = true;
   }
   else
   {
     tagsFound[tagNum] = false;
   }  
   //Just a little delay
   delay(2000);
  }

  //Show the scanned tag
  Serial.println("");
  for( int i=0; i<13; i++ )
  {
   Serial.write(tag[i]); 
  }
  
  Serial.println("");
  
  for(int i=0; i<4; i++)
  {
      Serial.println( tagsFound[i] );
  }
  
  Serial.println("");
  Serial.println("");
  
}

int compareTag( String tag )
{

  if(tag[9] == tagCollection4[0][9])
      return 0;
  
  if(tag[9] == tagCollection4[1][9])
      return 1; 
  
 if(tag[9] == tagCollection4[2][9])
      return 2;
  
  if(tag[9] == tagCollection4[3][9])
      return 3;
  
  return -1;
}


void clearTag(char one[]){
///////////////////////////////////
//clear the char array by filling with null - ASCII 0
//Will think same tag has been read otherwise
///////////////////////////////////
  for(int i = 0; i < strlen(one); i++){
    one[i] = 0;
  }
}

Please help me, it's for a school project.

Thanks for everything in advance.