My Question is, how can I convert the array into a single string with the content from the array ?
Is this an array of chars or some other data type ? If it is an array of chars then put '\0' into the final + 1 array position, making sure that the array is big enough, and you have created a string.
This converts the value to a string, in a specific format.
YOU CAN NOT DO THAT FOR ALL VALUES IN AN ARRAY IN ONE STEP!
Do you understand that?
It makes no difference whatsoever if there are 7 Serial.print() calls or 1. The EXACT same amount of data goes out the serial port in exactly the same amount of time. Get over it.
Can you please post an example program that illustrates putting the char values into the array and printing them one by one ? It does not have to be the real program, but it should illustrate what you are doing.
byte karte[7];
void setup() {
// initialize both serial ports:
Serial.begin(9600);
Serial1.begin(9600);
Serial.println("Serial Monitor ready...");
for (int i = 0 ; i <= 6 ; i++) //Feld initialisieren
karte[i] = 0;
}
void loop() {
int i = 0;
int k = 0;
while (Serial1.available() > 0 ) {
delay(20);
karte[i] = Serial1.read();
i++;
k = 1;
}
while (k == 1){
for (i ; i < 8; i++)
karte[i] = 0;
for (int i = 0 ; i < 7 ; i++){
Serial.print(karte[i],HEX);
Serial.print(" ");}
for (int i = 0 ; i < 7 ; i++){ //Feld resetten
karte[i] = 0;
k = 0;}
Serial.println();
}
}
If all you are trying to do is print the rfid on the serial monitor than a program like this is all you need
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial1.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial1.available()>0){
Serial.print(Serial1.read(),HEX);
}
}
There are a number of other points about the code you provided.
First
for (int i = 0 ; i <= 6 ; i++) //Feld initialisieren
karte[i] = 0;
is not required. Most globals are initialized to 0 by default.
while (Serial1.available() > 0 ) {
delay(20);
karte[i] = Serial1.read();
i++;
k = 1;
}
You are assuming that all the data will be available at this point its not safe to do this. You should be looking for some kind of end of rfid tag marker. What does your read output at the end of the rfid data?
You must learn to auto format your code it makes it a lot easer to find bugs!
I didn't knew, that I do not have to initializie the array before using it. But thanks for the comment
The antenna that I'm using is not sending out any kind of "end bit/byte" or something.
I only got the information that it's sending out 5 Bytes in a row.
I tested every RFID-Tag I have got and the Code works fine with the delay.
To come back to my initial question:
I have read out all my rfid tags and saved them like this in my arduino as DEC numbers:
int RFID_Tag_Card1 = 2232211347000
and so on....
When I read the Tags out, as you can see in my code, I save them in a char array like this:
char RIFD_Tag[7];
My Problem is now - Which is the easiest way to compare the two values ?
At the end I would like to make a comparision like this:
...
if (RFID_Tag == RFID_Tag_Card1)
bla bla
But since the read out RFID_Tag is a char array and even if I typecast the char array with - (int)RFID_Tag , I still can't compare it with my stored value in the database (RIFD_Tag_Card1).
I hope my problem get's a bit clearer now.
I just don't know how to make the comparision without converting the char array into a int or a string or anything else
int RFID_Tag_Card1 = 2232211347000 Have you really done that ? I assume that the missing semi-colon at the end is a typo but that aside, that number will not fit in an int.