Aside from the fact that you are writing 11 values of a non-existent array to EEPROM, after determining that you read 10 values from the RFID tag and stored them in another array, what is the problem?
thanks PaulS, I have solved it (from 0 to 9) my problem,
I don't understand how the EEPROM work..
my idea is read a tag and write it in EEPROM and turn on a led for example pin 13 (short pulse) after when I will read another tag check if it is saved before, if yes again short pulse in pin13 and delete it from EEPROM, but if it is not saved before then save in EEPROM in different position and turn on for example pin12 (short pulse) I would do this with 5 tag for 5 pins in ArduinoUno
uff.. I know crazy idea when I cann't understand very well how eerpom is going to work..
EEPROM is used to store data that must be available after the Arduino looses power and is restarted. If you are counting events, and don't want to lose that count, you would store the count in EEPROM each time it changed, so that on restart you could resume where you left off.
If you don't care about the scanned tag data being available after the Arduino resets, don't use EEPROM. A simple 50 byte array in (volatile) memory would be sufficient.
now, my problem is how can I do for know when the eerpom is busy from 0 to 11? if yes, then the next card must use from 12 to 23 until 5 cards
I don't have nothing =( but my current code is
#include <EEPROM.h>
int val = 0;
char code[14];
int bytesread = 0;
int led = 13;
int a = 0;
int value;
int value1;
int value2;
int value3;
void setup()
{
Serial.begin(9600);
}
void loop()
{
if(Serial.available() > 0)
{
if((val = Serial.read()) == 10)
{
bytesread = 0;
while(bytesread < 14)
{
if( Serial.available() > 0)
{
val = Serial.read();
if((val == 10)||(val == 13))
{
break;
}
code[bytesread] = val;
bytesread++;
}
}
//tag1 x2400CC392AFBxxx
//tag2 x2400CC572897xxx
Serial.print(code[8]); //test of value correct in position 8 of each tag, must be tag1=3 and tag2 = 5
//write in eerpom
EEPROM.write(0,code[2]);
EEPROM.write(1,code[3]);
EEPROM.write(2,code[4]);
EEPROM.write(3,code[5]);
EEPROM.write(4,code[6]);
EEPROM.write(5,code[7]);
EEPROM.write(6,code[8]);
EEPROM.write(7,code[9]);
EEPROM.write(8,code[10]);
EEPROM.write(9,code[11]);
EEPROM.write(10,code[12]);
EEPROM.write(11,code[13]);
delay(500);
//read from eeprom
//test show in serial monitor position two and thirteen tag1= 2 and B, tag2= 2 and 7
Serial.print(EEPROM.read(0));
Serial.print(EEPROM.read(11));
delay(200);
}
bytesread = 0;
}
}
You could use address 0 to store a byte. Bit 1 shows whether tag 1 has been stored. Bit 2 shows whether tag 2 has been stored. Etc. Look at bitRead() and bitWrite(). And, of course, EEPROM.read().
then I have tried using a "for" and "if" but I haven't have good luck, I have attached a pic 8)
//check value from positions 0 to 4 in eeprom
for (int q=0; q<4; q++) {
valor3[q] = EEPROM.read(q);
}
Serial.print("eeprom: ");
Serial.println(valor3);
//1º tag
if (valor3[0] == '0')
{
EEPROM.write(addr, code[bytesread]);
//addr start in 6 for fisrt tag
//position 0, 1, 2, 3 and 4
//will be used for know what position in the eerpom is free..
addr = addr + 1;
if (addr == 17)
addr = 6; //I am not sure about of it
delay(100);
//write 1 in position zero of eeprom after saved a tag
EEPROM.write(0, 1);
delay(100);
//set a pulse pin13
digitalWrite(13, HIGH);
delay(100);
digitalWrite(13, LOW);
delay(100);
}
I am not sure if my code is going to save ok in eeprom..
EEPROM.write(addr, code[bytesread]);
maybe bytesread is not fine here because I must write from code[2] to code[13]
here my code
#include <EEPROM.h>
int val = 0;
char code[14];
int bytesread = 0;
char busy[5];
char valor[12];//12 long of the string of my card
char valor1[12];//12 long of the string of my card
char valor2[12];//12 long of the string of my card
char valor3[5];
int a = 0;
int value;
int value1;
int value2;
int value3;
int addr = 6; //for 1º tag
int addrr = 18; //for 2º tag
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
}
void loop()
{
if(Serial.available() > 0)
{
if((val = Serial.read()) == 10)
{
bytesread = 0;
while(bytesread < 14)
{
if( Serial.available() > 0)
{
val = Serial.read();
if((val == 10)||(val == 13))
{
break;
}
code[bytesread] = val;
bytesread++;
}
}
//tag1 x2400CC392AFBxxx
//tag2 x2400CC572897xxx
//Serial.print(code[13]); //test of value correct in position 8 of each tag, must be tag1=3 and tag2 = 5
Serial.print("tag read: ");
Serial.println(code);
//write in eerpom
/*check if positions 6 to 17 or 18 to 29 are free/busy
example if position 0 has '0' is free from 6 to 17
if position 0 has '1' is busy from 6 to 17
if position 1 has '0' is free from 18 to 29
if position 1 has '1' is busy from 18 to 29
*/
//check value from positions 0 to 4 in the eeprom
for (int q=0; q<4; q++)
{
valor3[q] = EEPROM.read(q);
}
Serial.print("eeprom: ");
Serial.println(valor3);
//1º tag
if (valor3[0] == '0')
{
EEPROM.write(addr, code[bytesread]);
//addr start in 6 for fisrt tag
//position 0, 1, 2, 3 and 4
//will be used for know what position in the eerpom is free..
addr = addr + 1;
if (addr == 17)
addr = 6; //I am not sure about of it
delay(100);
//write 1 in position zero of eeprom after saved a tag
EEPROM.write(0, 1);
delay(100);
//set a pulse pin13
digitalWrite(13, HIGH);
delay(100);
digitalWrite(13, LOW);
delay(100);
}
//2º tag
if (valor3[1] == '0')
{
EEPROM.write(addrr, code[bytesread]);
//addr start in 18 for second tag
addrr = addrr + 1;
if (addrr == 29)
addrr = 18; //I am not sure about of it
delay(100);
//write 1 in position one of eeprom after saved a tag
EEPROM.write(1, 1);
delay(100);
//set a pulse pin12
digitalWrite(12, HIGH);
delay(100);
digitalWrite(12, LOW);
delay(100);
}
//read eeprom
//test show in serial monitor tags saved in eeprom
for (int k=6; k<17; k++)
{
valor[k] = EEPROM.read(k);
}
Serial.print("tag1: ");
Serial.println(valor);
for (int p=18; p<29; p++)
{
valor2[p] = EEPROM.read(p);
}
Serial.print("tag2: ");
Serial.println(valor2);
}
bytesread = 0;
}
}
Pauls, Do you know why I cant write "1" in position zero of the eeprom??
Why are you assuming that you can't?
You are not writing "1" to address 0. You are not even writing '1' to address 0. You are writing 1. Then, you are print()ing the value read from that address, but the overloaded method that gets called is not doing what you think it is, because EEPROM.read() returns a byte. That byte is printed as-is, not converted to a string. 1 is a non-printing character. Store the value read from EEPROM in a different kind of variable, first, such as an int, and you'll see different results.
finally my code is going fine.. just now I want to do a verification "value1==code"
value1 is my value saved in EEMPRON
code is my serial value from tag
here my idea (bad idea :~) )
//comparation value in eeprom with value read tag
if (value1 == code)
{
Serial.println("ok");
}
I dont know how do it
#include <EEPROM.h>
char code[15];
char valor[12];
int val = 0;
byte value1;
byte value2;
int bytesread = 0;
int led = 13;
int addr = 10;
int addr2 = 30;
int a = 0;
byte x= 1; // (00000001)
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
}
void loop()
{
if(Serial.available() > 0)
{
if((val = Serial.read()) == 10)
{
bytesread = 0;
while(bytesread < 15)
{
if( Serial.available() > 0)
{
val = Serial.read();
if((val == 10)||(val == 15))
{
break;
}
code[bytesread] = val;
bytesread++;
}
}
Serial.print("tag read: ");
Serial.println(code); //tag1 x2400CC392AFBxxx tag2 x2400CC572897xxx
Serial.print(" bitRead: ");
//test read bit to bit (00000001)
Serial.print(bitRead(x,7));
Serial.print(bitRead(x,6));
Serial.print(bitRead(x,5));
Serial.print(bitRead(x,4));
Serial.print(bitRead(x,3));
Serial.print(bitRead(x,2));
Serial.print(bitRead(x,1));
Serial.println(bitRead(x,0));
//read eerpom 10 to 24
Serial.print("EEPROM desde 10 to 24: ");
for (int k=10; k<24; k++)
{
// Serial.print(EEPROM.read(k));
value1 = EEPROM.read(k);
Serial.print(value1);
}
Serial.println(" ");
//read eerpom 30 to 44
Serial.print("EEPROM desde 30 to 44: ");
for (int k=30; k<44; k++)
{
value2 = EEPROM.read(k);
Serial.print(value2);
}
Serial.println(" ");
//comparation value in eeprom with value read tag
if (value1 == code) //here is my problem
{
Serial.println("ok");
}
//bitread position 1
if (bitRead(x,1) == 0)
{
//write 1
bitWrite(x, 1, 1);
//write in eerpom
for(byte b=0; b<bytesread; b++)
{ //addr = star in position 10
EEPROM.write(addr + b, code[b]);
}
//turn on led pin13
digitalWrite(13, HIGH);
delay(250);
digitalWrite(13, LOW);
delay(250);
Serial.println("1 at position 1 of X");
}
//bitread position 2
else if (bitRead(x,2) == 0)
{
//write 1
bitWrite(x, 2, 1);
//write in eerpom
for(byte b=0; b<bytesread; b++)
{ //addr2 = star in position 30
EEPROM.write(addr2 + b, code[b]);
}
//turn on led pin13
digitalWrite(12, HIGH);
delay(250);
digitalWrite(12, LOW);
delay(250);
Serial.println("1 at position 2 of X");
}
//test read bit to bit (00000001)
Serial.print(" bitRead: ");
Serial.print(bitRead(x,7));
Serial.print(bitRead(x,6));
Serial.print(bitRead(x,5));
Serial.print(bitRead(x,4));
Serial.print(bitRead(x,3));
Serial.print(bitRead(x,2));
Serial.print(bitRead(x,1));
Serial.println(bitRead(x,0));
//test read EEPROM
Serial.print("EEPROM desde 0 to 44: ");
for (int k=0; k<44; k++)
{
Serial.print(EEPROM.read(k));
}
Serial.println(" ");
Serial.println("__________________________");
}
}
}
The idea sounds OK in general. What happens when you run the code ?
Try printing the 2 variables that you are trying to compare just before the comparison code and print something immediately before and after them, perhaps > and < so that you can see any leading or training spaces if they are there.
yes, I think its fine but "value1 = code" dont work
after programming my firmware and after I have cleaned my eeprom
x = 00000001
when read the first card:
-read 2400CC392AFB (tag1)
-if position 1 of x = 0 then save tag1 in EEPROM using postion 10 to 24
now write 1 in position 1 of x (then x = 00000011)
give a pulse pin13
when read a second card, ask if position 1 of x = 0 if also
-read 2400CC572897 (tag2)
then save tag2 in EEPROM using postion 30 to 44
now write 1 in position 2 of x (then x = 00000111)
give a pulse pin12
until here is fine i can see it in serial monitor and in my leds
but I want to write "ok" (for now) in serial monitor if some card is already saved in eeprom
value1 == code isnt working because I cant see "ok" in serial monitor =(