Go Down

Topic: Need advice to combine EEPROM storage with a password/keypad system (Read 1 time) previous topic - next topic

lordzeppo

Hi to everyone!
Nice new forum here,eh?

So here's the thing i'm trying to accomplish.

I have a software I made using the keypad and password library and all I need is a way to change the password without the use of a computer and to keep it after reset. So EEPROM was the obvious solution.
Since I'm a completly new guy to this EEPROM wizzardry I'm asking for a bit of help in the form of 2 subroutines to be added in my code:

1-to read the stored password and apply it to an "active" variable (normal ram one) when powering up
2-If called,set a new password into the EEPROM to be kept as the new one. The lenght can be of say,1 to 20 characters long.

Here's my project's page:
http://badwolf.hackhut.com/2011/11/17/car-anti-theft-system/

and here's the code:
Code: [Select]
/*
**************************************************************************
**************************Software Version 1.1****************************
**************************************************************************
******************************BadWolf Corp********************************
**************************************************************************


This locking system works this way:
1-Plug your keypad according to instructions below
2-Plug Output LED Relay and Relay_Aux (Pin 4,12,13)
3-Plug Keypress LED on 2 and a Piezo speaker on 3
4-Modify the password below to the one you desire
ONCE RUNNING
-Compose password and press * to unlock
-At anytime,press # to reset the password buffer
-If music and led/Relay comes up,it's good
-If short music comes up and no Relay,start again
NOTES
For debug purposes,the serial lines will output key pressed and messages to help you troubleshoot any problems
specific to your setup like debounce and timings.

Enjoy
Th3BadWolf

*/

#include <Password.h> //http://www.arduino.cc/playground/uploads/Code/Password.zip
#include <Keypad.h> //http://www.arduino.cc/playground/uploads/Code/Keypad.zip

//**************************************************************************
//**************************************************************************
//SET PASSWORD HERE
Password password = Password( "26789" );
//**************************************************************************
//**************************************************************************

// Define Keypad
const byte ROWS = 4; // Four rows
const byte COLS = 3; // columns

// Define the Keymap
char keys[ROWS][COLS] = {
  {
    '1','2','3'    }
  ,
  {
    '4','5','6'    }
  ,
  {
    '7','8','9'    }
  ,
  {
    '*','0','#'    }
};

// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = {
  6, 11, 10, 8 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = {
  7, 5, 9 };

//Musical Declaration for Chiptune
#define C   1911
#define C1  1804
#define D   1703
#define Eb  1607
#define E   1517
#define F   1432
#define F1  1352
#define G   1276
#define Ab  1204
#define A   1136
#define Bb  1073
#define B   1012
#define c       955
#define c1      902
#define d       851
#define eb      803
#define e       758
#define f       716
#define f1      676
#define g       638
#define ab      602
#define a       568
#define bb      536
#define b       506
#define p       0  //pausa
//Var used for Chiptone tempo
long vel = 20000;


// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );


//******************************************Program Variables***********************************************
//1.1* Added Auxiliary relay to enable multiple outputs
int Keyled = 2;
int Piezo=3;
int Valid =4;
int Relay_Aux =12;
int Relay = 13;
//Super Mario Complete Melody declaration
int melod[] = {
  e, e, e, c, e, g, G, c, G, E, A, B, Bb, A, G, e, g, a, f, g, e, c, d, B, c};
int ritmo[] = {
  6, 12, 12, 6, 12, 24, 24, 18, 18, 18, 12, 12, 6, 12, 8, 8, 8, 12, 6, 12, 12, 6, 6, 6, 12};


void setup(){
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  //1.1* Added Auxiliary relay to enable multiple outputs
  pinMode(12, OUTPUT);
  //1.1* To stop the relay from flicking on power up.
  pinMode(13, OUTPUT);

  Serial.begin(9600);
  //**************************Data Output of ID********************************
  Serial.println("Vehicule Anti_Start_Engine Device");
  Serial.println("Designed by BadWolf Corp.");
  Serial.println("15 November 2011 V1.0");
  Serial.println("Revised on 17 November 2011 to V1.1");
  //Keypad Handler
  keypad.addEventListener(keypadEvent); //add an event listener for this keypad
}


void loop(){
  keypad.getKey();
}

//take care of some special events
void keypadEvent(KeypadEvent eKey){
  switch (keypad.getState()){
  case PRESSED:
    digitalWrite(Keyled,HIGH);
    beep(80,200);
    delay(50);
    digitalWrite(Keyled,LOW);
    Serial.print("Pressed: ");
    Serial.println(eKey);
    switch (eKey){
    case '*':
      checkPassword(); //Push * to validate your password
      break;
    case '#': //Push # to clear the password you've entered.
      password.reset();
      break;
    default:
      password.append(eKey);
    }
  }
}


//Music Song SubRoutine*******************************************
void music(){
  for (int u=0; u<26; u++) {     
    int tom = melod[u];

    int tempo = ritmo[u];

    long tvalue = tempo * vel;

    tocar(tom, tvalue);

    delayMicroseconds(1000); //pausa entre notas!
  }
}


void tocar(int tom, long tempo_value) {
  long tempo_gasto = 0;
  while (tempo_gasto < tempo_value) {
    digitalWrite(Piezo, HIGH);
    delayMicroseconds(tom / 2);

    digitalWrite(Piezo, LOW);
    delayMicroseconds(tom/2);

    tempo_gasto += tom;
  }
}
//End of music subroutine ****************************************
//Thanks to that italian guy for making the rough version available =P


//Beeping subroutine,note freq is the first var,scnd var is the duration
void beep(unsigned char delayms,unsigned char t){

  for (int i=0; i<t; i++) {  // generate a 1KHz tone for 1/2 second

    digitalWrite(Piezo, HIGH);
    delayMicroseconds(delayms);
    digitalWrite(Piezo, LOW);
    delayMicroseconds(delayms);
  }
}

//Auth subroutine with double output
//run the unlock or error code below
//1.1* Added Auxiliary relay
void checkPassword(){
  if (password.evaluate()){
    Serial.println("Acces Authorized,Activating Pin 12 and 13 outputs.");
    password.reset(); //ready for next activation
    digitalWrite(Valid,HIGH);
    digitalWrite(Relay,HIGH);
    digitalWrite(Relay_Aux,HIGH);
    music(); // You're a champion,here's your unlocking music ;p
    delay(5000); //more time to start the car
    digitalWrite(Valid,LOW);
    digitalWrite(Relay,LOW);
    digitalWrite(Relay_Aux,LOW);
    Serial.println("Acces Ended,DE-Activating Pin 12 and 13 outputs.");
    //Add code here for more actions when the password is GOOD
  }
  else{
    Serial.println("Acces Refused,Please Try Again");
    password.reset();//ready for next activation
    //Wrong Password audio signal is some sort of music...
    beep(50,200);
    beep(150,200);
    beep(250,200);
    beep(500,200);
    //Add code here for more actions when the password is WRONG
  }
}





To whoever wish to provide those 2 functions complete I offer his name as contributor on the project page and in the software remarks.

It's a non-commercial thing btw,

Thanks for your time!

AWOL

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

lordzeppo

Seriously....
don't you think I already checked it?

The problematic part in my opinion is the declaration,and for this the EEPROM reference is completly useless.

thanks anyway.

AWOL

Quote
The problematic part in my opinion is the declaration

The declaration of what?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

lordzeppo

The way to store unfixed lenght variable into the eeprom and getting them back.

AWOL

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

lordzeppo

I thought it belonged in the sotrage section, but if you think it'd fit more there,sure thing!

thanks for the last link,did't find that one in my search.

Go Up