EM18 RFID Receiver Overlay Shield for Bluz, Particle Photon and Electron

Hello,
I recently purchased RFID Receiver Overlay Shield for Bluz, Particle Photon and Electron from NCD.

I have assembled these parts with a I2C shield and Particle Photon (see pictures)

I have tried to use the following code to get the RFID to read the supplied fob and card but the nothing is returned

int count = 0;                                          // count = 0
char input[11];                                         // character array of size 12 
                                 
void setup()
{
   Serial1.begin(9600);                                  // begin serial port with baud rate 9600bps
}
void loop()
{
   
   if(Serial1.available())
   {
      count = 0;
      while(Serial1.available() && count < 12)          // Read 12 characters and store them in input array
      {
         input[count] = Serial1.read();
         count++;
         delay(5);
      }
      Serial1.print(input);                             // Print RFID tag number 
      Serial1.print("\n");   
   }
}

after adding debugging lines, i’ve managed to find that Serial1.available() is returning a null value.

Does anyone know where I am going wrong with the code? i’ve seen some code using Serial. and not Serial1. however the documentation suggests that serial is the usb and serial1. is for UART (which is the connection in use)

Any help would be appreciated.

Kind regards
Phill

@Travis do you have code for particle RFID.

I thought I had written some sample code for the RFID reader a long time ago but I cannot seem to locate it. As I remember though it was really pretty straight forward just monitoring Serial1 for incoming data which was transmitted when a tag came within range of the reader.

I will see if I can locate an RFID reader here and put together a quick sample.

Thanks, that would be great. I’ve tired the code in my OP, which monitors serial1 (supposedly the UART) but i just get a null response.

Hi Phill,

I’m still waiting on hardware from production so I can write some sample code. However I do see a couple of issues with your code.

input should be a size of 12, if you have it set to 11 then your application will surely crash. So change that line to:
char input[12];

The next issue I see is your serial prints are going to Serial1 which means you are trying to print to the RFID reader. So change those lines to:
Serial.print(input);
Serial.print("\n");

Here’s the revised code:

int count = 0;                                          // count = 0
char input[12];                                         // character array of size 12 
                                 
void setup()
{
   Serial1.begin(9600);                                  // begin serial port with baud rate 9600bps
}
void loop()
{
   
   if(Serial1.available())
   {
      count = 0;
      while(Serial1.available() && count < 12)          // Read 12 characters and store them in input array
      {
         input[count] = Serial1.read();
         count++;
         delay(5);
      }
      Serial.print(input);                             // Print RFID tag number 
      Serial.print("\n");   
   }
}
2 Likes

Hi Travis,
Thanks for your code. I didn’t realise setting input variable to 12 would cause an issue.

Seeing your code made me realise not only was i trying to output to serial1 (the UART connection which is connected to RFID as you mentioned) but also, as i am using usb into mains, I need to publish the results elsewhere rather than to the usb serial.

This code worked perfectly (used your code but replaced the print commands with particle.publish() instead )

int count = 0; // count = 0
char input[11]; // character array of size 12

void setup()
{
Serial1.begin(9600); // begin serial port with baud rate 9600bps
}
void loop()
{
if(Serial1.available())
{
count = 0;
while(Serial1.available() && count < 12) // Read 12 characters and store them in input array
{
input[count] = Serial1.read();
count++;
delay(5);
}

Particle.publish(input);
Particle.publish("\n");
}
}

Thanks :slight_smile:

Just one follow up newbie question for my own understanding of c++, why does the code crash if the character array variable declared is 12?

Cheers
Phill

Looking at it now it actually won’t crash. I think I just got confused because you created the input char array with a size of 11 but your comment says 12. Your while loop is breaking once count = 12 so it would not crash. Sorry for that bit of miss information. I was worried that count would = 12 which would be out of input’s bounds. Anyway you can ignore all that :stuck_out_tongue_winking_eye:

1 Like