With a Arduino uno (Sparfun Redboard) and a SparkFun Simultaneous RFID Reader - M6E Nano. I try to scan 50 UHF RFID tags
During the scan, each RFID tag reports its TID (20 bits long) several times. Each RFID tag has a unique TID. The TID cannot be edited.
To verify that all TIDs of the 50 RFID tags have been received. I use an array.
Each received TID is checked in a for loop to see if it is already contained in the array, if not it will be added.
The Arduino uno has only 2 KB SDRAM, so I need compress a hexadecimal number into a short string.
The best thing I found on the net is a javscript solution. I ask if someone can help me translate it to c++. So I can use it on the Arduino.
Original solution comes from here.
Working codepen version is based on the first response from stackoverflow
i hope this is the best approach to implement my plan or has someone a better idea how i can check if all 50 RFID tags have been scanned.
function hexToString(hex) {
var string = "";
while (hex.length % 8 !== 0) {
// we need it to be multiple of 8
hex = "0" + hex;
}
for (var i = 0; i < hex.length; i += 8) {
string += String.fromCharCode(
parseInt(hex.substring(i, i + 4), 16),
parseInt(hex.substring(i + 4, i + 8), 16)
);
}
return string;
}
function stringToHex(string) {
var hex = "";
for (var i = 0; i < string.length; i++) {
hex += ((i === 0 ? "" : "000") + string.charCodeAt(i).toString(16)).slice(
-4
); // get character ascii code and convert to hex a string, adding necessary 0s
}
return hex.toUpperCase();
}
var str = hexToString("0140FC0000CC2FA0090B013C00055FFBFFFFDC50");
alert(str);
alert(stringToHex(str));
20 bits requires 3 bytes, times 50 requires 150 bytes of SDRAM? You need to either post your code (preferably) or be more specific with the data types.
If only the last 10 hex digits ever change, then 5 bytes is sufficient to contain the unique part of each tag ID as a binary number, e.g. just this part:
A hash function can be used to convert a long string into a short number. But this looks like only 11 bytes so it should not take a lot of space to store that.
should be viewed like this
E2 00 00 17 22 0A 00 38 14 70 7F 97
In other words it is just 12 bytes. Storing 50 sets of 12 bytes would only take up 600 bytes - have you not got enough space for that?
If not, then the suggestion by @jremington just to store the last 5 bytes for each tag (the green part) and just store the first 7 bytes (the blue part) once as they seem to be the same for all the tags.
I suspect the problem with seeing a solution to this is the fact that the demo code just prints the values in HEX format and does not actually store the bytes as bytes.
Some "string" functions can analyze occurrence of "substring" within a string starting at selected position, even "from the end" toward the beginning of the string.
( i did not look on your implementation of "analyzing loop", but using substring analysis could be more fun).
Hex notation is just a convenient shorthand , it is still binary number occupying 4 bits, all you can really do is
to remove unwanted spaces before storing the string.
all you can really do is to remove unwanted spaces before storing the string
You can actually do much better: convert two ASCII hex digits to binary (0 to 255 in decimal notation), and store each pair in one byte rather than two bytes.
Please see replies #5, #8, #9 and #10 for more information.
jremington:
You can actually do much better: convert two ASCII hex digits to binary (0 to 255 in decimal notation), and store each pair in one byte rather than two bytes.
Please see replies #5, #8, #9 and #10 for more information.
Hex notation is just a convenient shorthand , it is still binary number occupying 4 bits,,,
232:
Hex notation is just a convenient shorthand , it is still binary number occupying 4 bits, all you can really do is
to remove unwanted spaces before storing the string.