Reading Rfid on Arduino Micro

Good evening

I am relatively new to arduino micro and completly new to the subject of reading something else then HIGH or LOW from a pin. I have to read from an rfid-reader which is connected to pin 4, which should be the TX pin if i got that right. I have to compare those readings to constants and then, if one of them matches to one of the 2 constants. led's on the pins 8 and 10 should light, depending on which one was matching. The part i would need help with is the reading of the rfid uid from the pin. I am searching the board for like 2 hours now and i didn't find anything. It would be really nice if you could give me a hint how i should do that.

Best regards Nodua

What RFID reader are you using? How is it wired? What code do you have so far?

Sorry about the lack of information. I just got assinged to this project so i have like nothing if it comes to code. Anyway, here's what i've got so far:

void setup()
{
  Serial.begin(9600);
  pinMode(4, INPUT);
}

void loop() {
  int data = digitalRead(2);
  Serial.println(data, DEC);
}

In the Serial Monitor i get spammed with 0's right now, which isn't a big suprise. It's like nothing but i've like never used arduino before so i guess im making babysteps. I got told that the RFID-reader is called "SM2300". Although i cant tell you how its wired. The one which wired it told me the UID will be sent to the pin4 and i "just" have to read it from there. He's already at home so i cant ask him for like a plan or something, but, in theory, the hardware shouldn't be a problem.

I've already looked into digitalRead but it appears to me i can only read HIGH or LOW from it. Is there any way i can put it into a buffer and convert that to hex or even to ascii?

Very difficult to offer any suggestions without knowing more about the hardware and how it is all wired up. A google search for 'SM2330 RFID reader' doesn't return any results, so I don't have any idea what sort of data should be sent to your arduino.

If I read one of the tags in HTerm i get the following:

Hex: 0D 0A 08 00 FE 00 04 BA EA 89 A2 25 80 88 Bin: 00001101 00001010 00001000 00000000 11111110 00000000 00000100 10111010 11101010 10001001 10100010 00100101 10000000 10001000

I guess i would recieve the binary stuff from pin4. If that is any help... I guess i have to buffer it an convert it to hex or ascii, since its only a demonstration, even comparing the binary stuff would work. The code would be ugly as f*** but it has to be done in 20 hours. Typical pre-holyday stress i guess.

After some googling i found out that it should be a Sonmicro rfid reader. SM2300 is written on the reader itself.

This link looks promising:

https://trac.mediamatic.nl/devcamps/wiki/RfiDuino

Essentially, you have to establish a serial connection with the reader (an input signal and an output signal), and then read in each individual byte, store them, and then convert them to HEX, BIN, DEC, OCT, etc.

Thank you very much, this helps a lot.

One question though, how does this I2C-Adress work? He’s using a SM130 with the following code:

13	// I2C address of SM130 module 
14	#define SM130 0x42

Is this 0x42 adress assinged to the piece of hardware so i have to find out which adress my SM2300 has or does it depend on the pin its wired with the arduino? Google-search didn’t bring anything up since the SM2300 doesn’t seem to exist.

Also, i was working on the following code overnight:

#include <SoftwareSerial.h>

#define rxPin 4
#define txPin 3
#define upPin 8
#define downPin 10

SoftwareSerial mySerial(rxPin, txPin);

int val = 0;
char code[10];
int bytesread = 0;

void setup()
{
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  pinMode(upPin, OUTPUT);
  pinMode(downPin, OUTPUT);
  
  mySerial.begin(9600);
}

void loop()
{
    digitalWrite(txPin, LOW);
    digitalWrite(downPin, LOW);
    
    val = mySerial.read();
}

But i dont know if thats worth anything.

does it depend on the pin its wired with the arduino

No. It is assigned when the manafacaturer designes the chip. Sometimes the user can change a few bits of the address with external inputs on the chip.

Finally it works. Thank’s for the great help.

I feel kinda stupid it was so simple, I just had to use Serial1 to read from the TX pin:

char inData[15]; // Allocate some space for the string
char inChar; // Where to store the character read
byte index = 0; // Index into array; where to store the character

void setup()
{
Serial1.begin(115200);
}
void loop()
{
while(Serial1.available() > 0){
     if(index < 14) // One less than the size of the array
       {
           inChar = Serial1.read(); // Read a character
           Serial.print(index);
           Serial.print((byte)inChar);
           if(index > 6)
           {
             inData[index - 7] = inChar; // Store it
           }
           index++; // Increment where to write next
           inData[index] = '\0'; // Null terminate the string
       }
    }
}

It’s not pretty but it works.
Again, thank you very much for your help and patience.
Best Regards
Nodua

Glad it worked out for you!