4

We're using two RDM6300 RFID readers for this, and the code works when plugged into an UNO, but not when connected to the Yun. We have one of the rfids plugged into the rx pin (0 on the digital side) and the other plugged into pin 2 (same exact way we had it working on the UNO). Anyway, is there something majorly different between working with just sketches on Yun vs UNO? This code doesn't even involve using the Linux side yet as we couldn't get this major part figured out. Any help would be appreciated

#include <SoftwareSerial.h>
 //2nd RFID using SoftwareSerial
 SoftwareSerial RFID(2, 3); // RX and TX
 // define constants for pins
 int UNLOCK = 8;
 // variables to keep state
 int readVal = 0; // individual character read from serial
 unsigned int readData[10]; // data read from serial
 int counter = -1; // counter to keep position in the buffer
 char tagId[11]; // final tag ID converted to a string
 char* authorizedTags[4]; // array to hold the list of authorized tags
 // fills the list of authorzied tags
 void initAuthorizedTags() {
 //tags
 authorizedTags[0] = "02006750B7"; 
 authorizedTags[1] = "02006750B1";
 authorizedTags[2] = "02006750B2";
 authorizedTags[3] = "02006750B3";
 authorizedTags[4] = "02006750B4";
 }
 void setup() { 
 Serial.begin(9600);
 //start serial to RFID reader2
 RFID.begin(9600); 
 pinMode(UNLOCK, OUTPUT);
 // pinMode(SUCCESS, OUTPUT);
 // pinMode(ERROR, OUTPUT);
 initAuthorizedTags();
 }
 // check if the tag ID we just read is any of the authorized tags
 int checkTag() {
 int i;
 for (i = 0; i < 4; ++i) {
 if (strcmp(authorizedTags[i], tagId) == 0) {
 return 1;
 }
 }
 return 0;
 }
 // convert the int values read from serial to ASCII chars
 void parseTag() {
 int i;
 for (i = 0; i < 10; ++i) {
 tagId[i] = readData[i];
 }
 tagId[10] = 0;
 }
 // once a whole tag is read, process it
 void processTag() {
 // convert id to a string
 parseTag();
 // print it
 printTag();
 // check if the tag is authorized
 if (checkTag() == 1) {
 tagSuccess(); // unlock solenoid
 } else {
 tagFailed(); 
 }
 }
 void printTag() {
 Serial.print("Tag value: ");
 Serial.println(tagId);
 }
 // perform an action when an authorized tag was read
 void tagSuccess() {
 Serial.println("Tag authorized.");
 //activate solenoid, 
 digitalWrite(8, HIGH);
 delay(3000);
 digitalWrite(8, LOW);
 }
 // inform the user that the tag is not authorized
 void tagFailed() {
 Serial.println("Unauthorized access!");
 }
 // this function clears the rest of data on the serial, to prevent multiple scans
 void clearSerial() {
 while (Serial.read() >= 0) {
 ; // do nothing
 }
 }
 void loop() {
 //RFID 1
 if (Serial.available() > 0) {
 // read the incoming byte:
 readVal = Serial.read();
 // a "2" signals the beginning of a tag
 if (readVal == 2) {
 counter = 0; // start reading
 } 
 // a "3" signals the end of a tag
 else if (readVal == 3) {
 // process the tag we just read
 processTag();
 // clear serial to prevent multiple reads
 clearSerial();
 // reset reading state
 counter = -1;
 }
 // if we are in the middle of reading a tag
 else if (counter >= 0) {
 // save valuee
 readData[counter] = readVal;
 // increment counter
 ++counter;
 } 
 }
 if (RFID.available() > 0) 
 {
 // read the incoming byte:
 readVal = RFID.read();
 // a "2" signals the beginning of a tag
 if (readVal == 2) {
 counter = 0; // start reading
 } 
 // a "3" signals the end of a tag
 else if (readVal == 3) {
 // process the tag we just read
 processTag();
 // clear serial to prevent multiple reads
 clearSerial();
 // reset reading state
 counter = -1;
 }
 // if we are in the middle of reading a tag
 else if (counter >= 0) {
 // save valuee
 readData[counter] = readVal;
 // increment counter
 ++counter;
 } 
 }
 }
asked Apr 21, 2016 at 23:47
10
  • Does it work for one reader? Commented Apr 22, 2016 at 0:18
  • Nope. Please don't tell me it's incompatible with the Yun... Commented Apr 22, 2016 at 0:44
  • I doubt that. Its a basic serial device. Have you communicated with anything over serial with the Yun? Commented Apr 22, 2016 at 0:47
  • Are you using the Yun over WiFi? Commented Apr 22, 2016 at 0:54
  • 3
    From what I found, Serial is reserved for comms between the atmega32u4 and the PC, while Serial1 (on pins 0 and 1) is reserved for comms btw the Arduino and Linux parts of the Yun. You have to use 2 SoftwareSerial ports for your project; and it seems even that option is buggy on the Yun. But try with one reader anyways; disconnect the other from pins 0 and 1 and try printing whatever you read from the SoftSerial reader to the PC; keep the sketch simple Commented Apr 22, 2016 at 1:16

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.