For one user it works perfect, but when I add more user it doesn´t work. I believe the problem is in the setup while reading the EEPROM the way I show in the code. Is it wrong to write "EEPROM.read(i+5);"?? Is the way I tought to write all my users codes in EEPROM. Anny suggestion of how to do it properly?
But when I enter the code in my keypad it doesnt recognize it. What surprise me the most is that if I just write one user in EEPROM it works. Thsi code works perfect:
char user[100][6] = { "67202", "35426", "52565", "44234", "84583", "51511", "81510", ... , "00239" };
for(byte u=0; u<userCount; u++)
{
for(byte b=0; b<5; b++)
{
EEPROM.write(u5, user; ** }** }[/quote]
[u]__By doing "EEPROM.write(u5," you write one number i one byte?? I mean, byte0 = '6', byte1='7', byte2 = '2'...??__[/u] With "read" I mean extract data from EEPROM, read the values of the EEPROM and assign it to my users list. The idea is to not declare the users code numbers in the flash memory (because the users can be modify by sms), just write it once in EEPROM (by the way you teach me) and then delete the part of the code that writes in EEPROM and load the program in the Arduino again. So each time the program runs the first thing to do is read the values of the EEPROM and assign it to my users list. I made it like this (example for 3 users): **[/u] [u]**for(i=0; i<5; i++){ user1[i]=EEPROM.read(i); user2[i]=EEPROM.read(i+5); user3[i]=EEPROM.read(i+10); }**[/u] [u]** With "doesn't work" I mean that the keypad did not recognize the codes. At first I tried just with one user and the keypad recognize it ```
[u]** EEPROM.write(0, '6');
EEPROM.write(1, '7');
EEPROM.write(2, '2');
EEPROM.write(3, '0');
EEPROM.write(4, '2');
``` So I attempt to do the same with more users but "doesn't work". I really hope I explain my self a little better. Thanks for your time PaulS, thanks so much.
By doing "EEPROM.write(u*5," you write one number i one byte?
The value in u is multiplied by 5, so that the address being written to is 0, 5, 10, 15, etc.
It should, of course, be u*5 + b, so that the inner loop is writing to 0, 1, 2, 3, and 4 when u is 0, and to 5, 6, 7, 8, and 9, when u is 1.
And, of course, there is a ) missing on the end...
I made it like this (example for 3 users):
That should work, if the data is written correctly. So, add Serial.print() statements to see what is being read, what is being assigned to user1, etc. Don't forget that strings need to be NULL terminated, and yours are not (yet), if you are using them as strings, rather than just arrays of chars.
Yes, this method for 100 user is going to be crazy but at least it works. Next step is to receive sms and modify the EEPROM data if it is neccesary. Then I'll proceed to optimize the code, is insane right now!
to store the data, you can use a similar set of loops to read the data.
I'd suggest that you also store the user count in EEPROM, so you have a way of knowing how many users there are. Perhaps write that in address 0, and add a +1 to all the EEPROM.write() addresses, to not overwrite that value.
I'll do it for sure. There is part of the code where I need to save array elements to EEPROM that don't know at the begining cause it arrive to my arduino via sms. For example an sms that sends me a text with the code "67202" I want to save the first element in byte 10, second one in byte 11... I tried like the next code show but it prints me in the serial "93" instead of 7. Do you know what i'm doing wrong?
char intento1[]="67202";
EEPROM.write(10, 'intento1[1]'); // also tried EEPROM.write(10, intento1[1]);
Serial.println(EEPROM.read(10));
EEPROM.write(10, 'intento1[1]'); // also tried EEPROM.write(10, intento1[1]);
The first byte, the 6, is in intento1[0].
The code (snippet) does something. "It doesn't work" only means that what it does is not what you want, without defining either what it does OR what you want.
You need to store all 5 characters, don't you?
Knowing where to store them is important. That's why I suggested storing the number of users in 0, so that you could read and update that number if a new user needs to be added. You could also use the number of users to determine the next available address to write to.
I guess is something relative to the command "Serial.println" cause even it prints 55, 54, 50... the keypad recognizes it as '6', '7', '2'... So the problem seems to be over!
#include<EEPROM.h> #include <PN532.h> #include <SPI.h>
int led = 13;
int EEsize = 1;
int taha;
String input = ""; #define PN532_CS 10
PN532 nfc(PN532_CS); #define NFC_DEMO_DEBUG 1
void setup(void) { #ifdef NFC_DEMO_DEBUG
Serial.begin(9600);
Serial.println("Hello!"); #endif
nfc.begin();
pinMode(led, OUTPUT);
uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
Serial.print("Didn't find PN53x board");
while (1); // halt
} #ifdef NFC_DEMO_DEBUG
Serial.print("Found chip PN5"); #endif
nfc.SAMConfig();
}
void loop(void) {
uint32_t id;long randNumber;
id = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A);
if (id==2999603015)
{
Serial.println("ACCESS GRANTED");
Serial.println(" The unique number is sent to your registered mobile");
for (int i = 0; i < EEsize; i++)
{
randNumber=random(255);
Serial.println(randNumber);
EEPROM.write(i, randNumber);
}
Serial.println();
for (int a=0; a<EEsize; a++)
{
taha = EEPROM.read(a);
Serial.print("EEPROM position: ");
Serial.print(a);
Serial.print(" contains ");
Serial.println(taha);
delay(2000);
//Serial.print("\r");
//delay(1000); //Serial.println("AT+CMGF=1\r");
//delay(1000); //Serial.println("AT+CMGS="+91944xxxxxx8"\r"); //Number to which you want to send the sms
//delay(1000); //Serial.println(" randNumber \r"); //The text of the message to be sent
//delay(1000); //Serial.write(0x1A);
//delay(1000);
//
if(Serial.available()){
input += (int)Serial.read();
delay(30);
//if(input =="taha");
Serial.println("The unique number you entered is correct");
}
}
}
else if(id!=0)
{
Serial.println("ACCESS DENIED");
delay(2000);
digitalWrite(led, HIGH);
}
else
{
Serial.println(" PLEASE DISPLAY YOUR MOBILE");
delay(2000);
}
}
hey!how can i compare a data stored in eeprom using serial port monitor..... i am using serial functions to read and then compairng with eeeprom value "taha" but it is not comparing...can u help me out