-
• #2
Please follow this link also.
http://www.seeedstudio.com/depot/125Khz-RFID-module-UART-p-171.html -
• #3
Attached is wiring visual. VBAT output of Espruino is not exactly 5V, but it should be sufficient for the RFID reader to work. If it is not sufficient, connect USB 5V and GND directly to the reader. You can use P3: PIN2 and PIN3 for that. The antenna you connect to P2.
Documentation is a bit sparse. Documentation about required VCC is not very conclusive: Module description on git hub says: VCC 3.3 .. 5V, forum entries contradict that.
The code below just reads incoming data and for each byte writes a line onto the console:
Serial1.setup(9600,{tx:B6, rx:B7, bytesize:8, parity:"none", stopbits:1}); Serial1.on("data",function(data){ // - for every received character print on console: // character 0xHexValue asciiValueIn3Digits // - for example: // M 0x4D 077 if (data) { // data is string received from RFID reader var s, c, a; // s - output String, c = character, a = ASCII value of char for (var idx = 0; idx < data.length(); idx++) { a = (c = data.charAt(idx)).charCodeAt(0); s = ((c >= " ") && (c <= "~")) ? c : "~"; s += (a < 16) ? " 0x0" : " 0x"; s += a.toString(16); s += (a < 10) ? " " : (a < 100) ? " " : " "; s += a; console.log(s); } } });
This code is only partially tested, since I do not have the device at hand.
Since Espruino delivers data as soon it can, the received data may not be all the 11 bytes - 10 bytes tag ID plus 1 byte CRC. The device controller obviously does signal when a read has happened, but I do not see it pointed out on the connectors P1 through P3. May be it is P1:PIN3, or P3:PIN1 -LED. You may need to test this out.
If one of these pins provides you with a raising or falling edge on card detection, you may set a watch on it and initialize a byte counter and a array buffer or string. On receipt you then count the bytes and store them in an array or append it to the string, and on reception of the 11th byte you perform the CRC calculation. If the CRC is ok, you accept the data, otherwise you drop the reading.
If you do not get a signal, you wait for the 11th byte to be read or maximum 50[ms] what ever comes first. 50[mx] is way enough to receive the 11 bytes: (1/9600[baud]) * 11(bytes) * 9[bit] = 10.31[ms]. If you got 11 bytes you 'do the math' (processing), otherwise you just initialize (and buzz: nope) and wait for the next data burst.
Code below is implementing above solution approach:
// ...thinking about a RDM630 module / 'faking' it here /* ` ` ` require("RDM630").connect(Serial1, B6, B7, function(err, tagId){ if (!err) { console.log("Tag ID = " + tagId); } else { console.log("Error: " + err + " - error info: " + tagId); } }, 100); // 100[ms] is optional read timeout (default = 50[ms]) ` ` ` */ // NOTE: module is built with single reader only in mind var RDM630_module = { connect: function(serial, tx, rx, callback, timeout) { serial.setup(9600,{tx:tx, rx:rx, bytesize:8, parity:"none", stopbits:1}); var s = "", t = null, tt = ((t) ? t : 50), v, l, r, x, initRead = function(){ t = null; v = s; s = ""; callback("Timeout (reading)", v); }; serial.on("data", function(d){ s += d; while (s.length >= 11) { if (t) { clearTimeout(t); t = null; } v = s.substr(0,11); s = s.substr(11); r = v.charCodeAt(0); for (x = 1; x < 10; x++) { r ^= v.charCodeAt(x); } if (r === v.charCodeAt(10)) { callback(null, v.substr(0,10)); } else { callback("CRC Error", v); } } if (s.length && !t) t = setTimeout(initRead, tt); }); } }; // ...application with RDM630 (module) code: // require("RDM630").connect(Serial1, B6, B7, function(err, tagId){ // when available RDM630_module.connect(Serial1, B6, B7, function(err, tagId){ // until available if (!err) { console.log("Tag ID = " + tagId); } else { console.log("Error: " + err + " - error info: " + tagId); } }); // using default read timeout (50[ms])
Accepting data from the tag and passing it on to PICO is a new, different ball game. Same is as sending control information to the RFID reader. Until better documentation of the RFID reader is available: RFID UART R.I.P. - Read In Peace tag IDs!
In the past, I used a different RFID reader: MFRC522 connected using SPI.
@user63048, how is it going?
2 Attachments
-
• #4
Wow, thanks for the detailed post @allObjects!
Just a note that there are already two different RFID modules that have code and examples for them already - MFRC522 and PN532:
http://www.espruino.com/Search?kw=rfid
It looks like @allObjects has you covered, but in general it's easier to use hardware that we've already got working with Espruino.
-
• #5
In your pin connections, you write:
VBAT -- red -- PIN4 GND
GND -- grey -- PIN5 +5V (DC).
Should it not be:
VBAT -- red -- PIN5 +5V (DC)
GND -- grey -- PIN4 GND.
as you has drawn it. -
• #7
Thanks Everyone
Hi,
I just buy a RFID reader from https://github.com/Seeed-Studio/RFID_Library . I wanna use this with espruino pico.
i didn't get suitable docs and suggestions.
PLz help me to accomplish this task