1

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 the Arduino receives nothing, 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.

  • So, what doesn't work? – Majenko May 20 '15 at 15:55
  • With the original code I can't receive anytging over bluetooth – Robin May 20 '15 at 16:21
  • Is that "The phone doesn't receive anything transmitted by the Arduino over bluetooth", or "The Arduino doesn't receive anything transmitted by the phone over bluetooth"? You have to be explicit in what you tell us, we can't guess your meanings since we haven't seen your system not working like you have. – Majenko May 20 '15 at 16:30
  • sry, sry the arduino doesn't receive anything – Robin May 20 '15 at 16:38
  • possible duplicate of SoftwareSerial problems – Majenko May 21 '15 at 11:24

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.