Pages: [1] 2   Go Down
Author Topic: Please Need Help to combine two codes  (Read 835 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

HEllo eveyone, i am still a newbie in arduino programming, and i need your help. I m trying to merge two codes together, IDLE MODE CODE_FSR interrupt, and FingerScanner&Step motorCODE. My general idea for this code is, while holding a FSR sensor, the arduino will be awake , and then a finger will be scan with fingerprint scanner.If the finger is correspond with the finger image stored in the data sheet, it will move the stepmotor backward and continue waiting until FSR is release, But immediately the FSR sensor is release, the stepmotor will move back to its inital state and then arduino system will go back to idle mode to save battery. PLEASE PLEASE NEED YOUR HELP.

FYI....When my Arduino Uno is gone to IDLE mode for power save, i m using FSR sensor at pin 2 as means of interruping to wakeup the system.

FIRST CODE IS FOR SAVE POWER_IDLE MODE_CODE_FSR interrupt
Code:
#include <avr/interrupt.h>
#include <avr/power.h>
#include <avr/sleep.h>
#include <avr/io.h>
//
void setup(void)
{
DDRD &= B00000011; // set Arduino pins 2 to 7 as inputs, leaves 0 & 1 (RX & TX) as is
DDRB = B00000000; // set pins 8 to 13 as inputs
PORTD |= B11111100; // enable pullups on pins 2 to 7
PORTB |= B11111111; // enable pullups on pins 8 to 13
pinMode(13,OUTPUT); // set pin 13 as an output so we can use LED to monitor
pinMode(11,OUTPUT);
digitalWrite(13,HIGH); // turn pin 13 LED on
digitalWrite(11,HIGH);
}
//
void loop(void)
{
// Stay awake for 1 second, then sleep.
// LED turns off when sleeping, then back on upon wake.
delay(100);
sleepNow();
}
//
void sleepNow(void)
{
  while(digitalRead(2)==LOW);
    /* Now is the time to set the sleep mode. In the Atmega8 datasheet
     * http://www.atmel.com/dyn/resources/prod_documents/doc2486.pdf on page 35
     * there is a list of sleep modes which explains which clocks and
     * wake up sources are available in which sleep modus.
     *
     * In the avr/sleep.h file, the call names of these sleep modus are to be found:
     *
     * The 5 different modes are:
     *     SLEEP_MODE_IDLE         -the least power savings
     *     SLEEP_MODE_ADC
     *     SLEEP_MODE_PWR_SAVE
     *     SLEEP_MODE_STANDBY
     *     SLEEP_MODE_PWR_DOWN     -the most power savings
     *
     *  the power reduction management <avr/power.h>  is described in
     *  http://www.nongnu.org/avr-libc/user-manual/group__avr__power.html
     */
// Set pin 2 as interrupt and attach handler:
attachInterrupt(0, pinInterrupt, LOW);
delay(100);
//
// Choose our preferred sleep mode:
set_sleep_mode(SLEEP_MODE_IDLE);
//
// Set sleep enable (SE) bit:
sleep_enable();
  power_adc_disable();
  power_spi_disable();
  power_timer0_disable();
  power_timer1_disable();
  power_timer2_disable();
  power_twi_disable();
//
// Put the device to sleep:
digitalWrite(13,LOW); // turn LED off to indicate sleep
digitalWrite(11,HIGH);
sleep_mode();
//
// Upon waking up, sketch continues from this point.
sleep_disable();
digitalWrite(13,HIGH); // turn LED on to indicate awake
digitalWrite(11,LOW);
power_all_enable();

while(digitalRead(2)==LOW);

}
//
void pinInterrupt(void)
{
sleep_disable();
detachInterrupt(0);
}



The SECOND CODE is for FINGERPRINT SCANNER&STEPMOTOR

Code:
#include <Stepper.h>
#include <Adafruit_Fingerprint.h>
#if ARDUINO >= 100
#include <SoftwareSerial.h>
#else
#include <NewSoftSerial.h>
#endif

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
                                     // for your motor
boolean lock_state;
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8,9,10,11);          

int getFingerprintIDez();
void lock_motor();

// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino  (WHITE wire)
#if ARDUINO >= 100
SoftwareSerial mySerial(2, 3);
#else
NewSoftSerial mySerial(2, 3);
#endif

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup()
{
  lock_state = HIGH;
    // set the speed at 60 rpm:
  myStepper.setSpeed(60);
  // initialize the serial port:
  //Serial.begin(9600);
 
 
  Serial.begin(9600);
  Serial.println("fingertest");

  // set the data rate for the sensor serial port
  finger.begin(57600);
 
  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1);
  }
  Serial.println("Waiting for valid finger...");
}

void loop()                     // run over and over again
{
  getFingerprintIDez();

 
//    // step one revolution  in one direction:
//   Serial.println("clockwise");
//  myStepper.step(stepsPerRevolution);
//  delay(500);
//
//   // step one revolution in the other direction:
//  Serial.println("counterclockwise");
//  myStepper.step(-stepsPerRevolution);
//  delay(500);
}

uint8_t getFingerprintID() {
  uint8_t p = finger.getImage();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println("No finger detected");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK success!

  p = finger.image2Tz();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }
 
  // OK converted!
  p = finger.fingerFastSearch();
  if (p == FINGERPRINT_OK) {
 

  
    Serial.println("Found a print match!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_NOTFOUND) {
  

  
    Serial.println("Did not find a match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }  
 
  // found a match!
  Serial.print("Found ID #"); Serial.print(finger.fingerID);
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
}

// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez() {
  uint8_t p = finger.getImage();
  if (p != FINGERPRINT_OK)  {
    lock_motor();
    return -1;
  }
  p = finger.image2Tz();
  if (p != FINGERPRINT_OK) {
    lock_motor();
    return -1;
  }

  p = finger.fingerFastSearch();
  if (p != FINGERPRINT_OK)  {
    lock_motor();
    return -1;
  }
 
  // found a match!

  Serial.print("Found ID #"); Serial.print(finger.fingerID);
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
  if (lock_state == HIGH){
      //This is for the motor
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  delay(500);
  lock_state = LOW;
  }
  return finger.fingerID;

}

void lock_motor(){
  if (lock_state == LOW){
    // Is for the motor step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  delay(500);
  lock_state = HIGH;
  }
}



Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46091
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How are you powering the stepper motor? Those thing require a LOT of current. No dinky battery is going to power a stepper motor for any useful period of time.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How are you powering the stepper motor? Those thing require a LOT of current. No dinky battery is going to power a stepper motor for any useful period of time.

Thanks for your quick reply. Yes i am going to use 9V battery for stepper motor, and it is really a small stepper motor....
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 65
Posts: 2931
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
9V battery
Do you mean a regular store bought 9V? If so, dont bother, that battery will last you maybe 20 - 30 minutes of continious use, maybe. Unless you plan on getting 4 or 5 of them and putting them in parallel. Get a 9V rechargeable battery pack, like the ones used in Hobby RC cars. Those have a LOT of current, and can be reused.
Time wise, depends on the battery's mAh's.
« Last Edit: January 31, 2013, 11:51:59 am by HazardsMind » Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
9V battery
Do you mean a regular store bought 9V? If so, dont bother, that battery will last you maybe 20 - 30 minutes of continious use, maybe. Unless you plan on getting 4 or 5 of them and putting them in parallel. Get a 9V rechargeable battery pack, like the ones used in Hobby RC cars. Those have a LOT of current, and can be reused.
Time wise, depends on the battery's mAh's.

thanks for your help
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Please i still need help to combine my two codes...thanks
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 65
Posts: 2931
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It should just a simple drag and drop, but you have both codes using pins 11 and 2, so those will have to be changed. Another thing to watch out for is delays. The first one has two active delays but they are only 200 ms, which is not bad, but the second code also has two active delays that add up to 1 second, that might be bad. I dont know if time is an issue for you, but in total you have 1.2 seconds of delay. That 1.2 seconds it what it will take until the code is looped again.

Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It should just a simple drag and drop, but you have both codes using pins 11 and 2, so those will have to be changed. Another thing to watch out for is delays. The first one has two active delays but they are only 200 ms, which is not bad, but the second code also has two active delays that add up to 1 second, that might be bad. I dont know if time is an issue for you, but in total you have 1.2 seconds of delay. That 1.2 seconds it what it will take until the code is looped again.



Thanks for your help, please can you help me put them together. I do not mind if you assign the pins 11 and 2 to different pins number so they would not interfere with other, but it would be good if pin 2 still be the interrupt pin for wakeup (FSR).For the time, it matters a lot, because the whole idea for the system work faster, which ever time you think will be the best, i m willing to work with it...please help me.
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 65
Posts: 2931
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try to do it on your own first, that way you get an idea of what is happening with the codes. Try to combine them then, come back and post the combined code along with any and all errors. Now if you have no idea of even where to start and are willing to pay someone to do it for you, then check out the Gigs and Collaboration page.

  http://arduino.cc/forum/index.php/board,26.0.html
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I combined these codes but it is not working for me..Please help me look into this code.

Code:
#include <Stepper.h>
#include <Adafruit_Fingerprint.h>
#if ARDUINO >= 100
#include <SoftwareSerial.h>
#else
#include <NewSoftSerial.h>
#endif
#include <avr/interrupt.h>
#include <avr/power.h>
#include <avr/sleep.h>
#include <avr/io.h>
//
const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
                                     // for your motor
boolean lock_state;
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8,9,10,11);         

int getFingerprintIDez();
void lock_motor();

// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino  (WHITE wire)
#if ARDUINO >= 100
SoftwareSerial mySerial(2, 3);
#else
NewSoftSerial mySerial(2, 3);
#endif

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

//bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
void setup()
{

DDRD &= B00000011; // set Arduino pins 2 to 7 as inputs, leaves 0 & 1 (RX & TX) as is
DDRB = B00000000; // set pins 8 to 13 as inputs
PORTD |= B11111100; // enable pullups on pins 2 to 7
PORTB |= B11111111; // enable pullups on pins 8 to 13
pinMode(13,OUTPUT); // set pin 13 as an output so we can use LED to monitor
pinMode(11,OUTPUT);
digitalWrite(13,HIGH); // turn pin 13 LED on
digitalWrite(11,HIGH);

  lock_state = HIGH;
    // set the speed at 60 rpm:
  myStepper.setSpeed(60);
  // initialize the serial port:
  //Serial.begin(9600);
 
 
  Serial.begin(9600);
  Serial.println("fingertest");

  // set the data rate for the sensor serial port
  finger.begin(57600);
 
  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1);
  }
  Serial.println("Waiting for valid finger...");
}

//bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
void loop()                     // run over and over again
{
// Stay awake for 1 second, then sleep.
// LED turns off when sleeping, then back on upon wake.
delay(100);
sleepNow();

  getFingerprintIDez();

}
//bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
void sleepNow(void)
{
  while(digitalRead(2)==LOW);
 
// Set pin 2 as interrupt and attach handler:
attachInterrupt(0, pinInterrupt, LOW);
delay(100);
//
// Choose our preferred sleep mode:
set_sleep_mode(SLEEP_MODE_IDLE);
//
// Set sleep enable (SE) bit:
sleep_enable();
  power_adc_disable();
  power_spi_disable();
  power_timer0_disable();
  power_timer1_disable();
  power_timer2_disable();
  power_twi_disable();

// Put the device to sleep:
digitalWrite(13,LOW); // turn LED off to indicate sleep
digitalWrite(11,HIGH);
sleep_mode();
//
// Upon waking up, sketch continues from this point.
sleep_disable();
digitalWrite(13,HIGH); // turn LED on to indicate awake
digitalWrite(11,LOW);
power_all_enable();

while(digitalRead(2)==LOW);

}
//bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb

uint8_t getFingerprintID() {
  uint8_t p = finger.getImage();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println("No finger detected");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK success!

  p = finger.image2Tz();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }
 
  // OK converted!
  p = finger.fingerFastSearch();
  if (p == FINGERPRINT_OK) {
 

 
    Serial.println("Found a print match!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_NOTFOUND) {
 

 
    Serial.println("Did not find a match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  } 
 
  // found a match!
  Serial.print("Found ID #"); Serial.print(finger.fingerID);
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
}

// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez() {
  uint8_t p = finger.getImage();
  if (p != FINGERPRINT_OK)  {
    lock_motor();
    return -1;
  }
  p = finger.image2Tz();
  if (p != FINGERPRINT_OK) {
    lock_motor();
    return -1;
  }

  p = finger.fingerFastSearch();
  if (p != FINGERPRINT_OK)  {
    lock_motor();
    return -1;
  }
 
  // found a match!

  Serial.print("Found ID #"); Serial.print(finger.fingerID);
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
  if (lock_state == HIGH){
      //This is for the motor
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  delay(500);
  lock_state = LOW;
  }
  return finger.fingerID;

}

void lock_motor(){
  if (lock_state == LOW){
    // Is for the motor step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  delay(500);
  lock_state = HIGH;
  }
}



//bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
void pinInterrupt(void)
{
sleep_disable();
detachInterrupt(0);
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I merged two codes but not sure i m doing it correct. Please can someone looking into my program and see i m doing it correct because i am not good in programming...thanks

Code:
#include <Stepper.h>
#include <Adafruit_Fingerprint.h>
#if ARDUINO >= 100
#include <SoftwareSerial.h>
#else
#include <NewSoftSerial.h>
#endif
#include <avr/interrupt.h>
#include <avr/power.h>
#include <avr/sleep.h>
#include <avr/io.h>
//
const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
                                     // for your motor
boolean lock_state;
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8,9,10,11);         

int getFingerprintIDez();
void lock_motor();

// pin #4 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino  (WHITE wire)
#if ARDUINO >= 100
SoftwareSerial mySerial(4, 3);
#else
NewSoftSerial mySerial(4, 3);
#endif

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

//bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
void setup()
{

DDRD &= B00000011; // set Arduino pins 2 to 7 as inputs, leaves 0 & 1 (RX & TX) as is
DDRB = B00000000; // set pins 8 to 13 as inputs
PORTD |= B11111100; // enable pullups on pins 2 to 7
PORTB |= B11111111; // enable pullups on pins 8 to 13
pinMode(13,OUTPUT); // set pin 13 as an output so we can use LED to monitor
pinMode(11,OUTPUT);
digitalWrite(13,HIGH); // turn pin 13 LED on
digitalWrite(11,HIGH);

  lock_state = HIGH;
    // set the speed at 60 rpm:
  myStepper.setSpeed(60);
  // initialize the serial port:
  //Serial.begin(9600);
 
 
  Serial.begin(9600);
  Serial.println("fingertest");

  // set the data rate for the sensor serial port
  finger.begin(57600);
 
  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1);
  }
  Serial.println("Waiting for valid finger...");
}

//bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
void loop()                     // run over and over again
{
// Stay awake for 1 second, then sleep.
// LED turns off when sleeping, then back on upon wake.
delay(100);
sleepNow();

  getFingerprintIDez();

}
//bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
void sleepNow(void)
{
  while(digitalRead(2)==LOW);
 
// Set pin 2 as interrupt and attach handler:
attachInterrupt(0, pinInterrupt, LOW);
delay(100);
//
// Choose our preferred sleep mode:
set_sleep_mode(SLEEP_MODE_IDLE);
//
// Set sleep enable (SE) bit:
sleep_enable();
  power_adc_disable();
  power_spi_disable();
  power_timer0_disable();
  power_timer1_disable();
  power_timer2_disable();
  power_twi_disable();

// Put the device to sleep:
digitalWrite(13,LOW); // turn LED off to indicate sleep
digitalWrite(6,HIGH);
sleep_mode();
//
// Upon waking up, sketch continues from this point.
sleep_disable();
digitalWrite(13,HIGH); // turn LED on to indicate awake
digitalWrite(6,LOW);
power_all_enable();

while(digitalRead(2)==LOW);

}
//bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb

uint8_t getFingerprintID() {
  uint8_t p = finger.getImage();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println("No finger detected");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK success!

  p = finger.image2Tz();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }
 
  // OK converted!
  p = finger.fingerFastSearch();
  if (p == FINGERPRINT_OK) {
 

 
    Serial.println("Found a print match!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_NOTFOUND) {
 

 
    Serial.println("Did not find a match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  } 
 
  // found a match!
  Serial.print("Found ID #"); Serial.print(finger.fingerID);
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
}

// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez() {
  uint8_t p = finger.getImage();
  if (p != FINGERPRINT_OK)  {
    lock_motor();
    return -1;
  }
  p = finger.image2Tz();
  if (p != FINGERPRINT_OK) {
    lock_motor();
    return -1;
  }

  p = finger.fingerFastSearch();
  if (p != FINGERPRINT_OK)  {
    lock_motor();
    return -1;
  }
 
  // found a match!

  Serial.print("Found ID #"); Serial.print(finger.fingerID);
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
  if (lock_state == HIGH){
      //This is for the motor
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  delay(500);
  lock_state = LOW;
  }
  return finger.fingerID;

}

void lock_motor(){
  if (lock_state == LOW){
    // Is for the motor step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  delay(500);
  lock_state = HIGH;
  }
}



//bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
void pinInterrupt(void)
{
sleep_disable();
detachInterrupt(0);
}
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 65
Posts: 2931
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What are you getting as opposed to what your not getting?

From what I see, your getting some confliction here.
DDRB = B00000000; // set pins 8 to 13 as inputs
pinMode(13,OUTPUT);
pinMode(11,OUTPUT);

I can't look at all of if right now, myself, but just skimming through it, there are a few mistakes.

You know both codes work indepently, so try some debugging with the serial monitor.

Post any and all errors.
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What are you getting as opposed to what your not getting?

From what I see, your getting some confliction here.
DDRB = B00000000; // set pins 8 to 13 as inputs
pinMode(13,OUTPUT);
pinMode(11,OUTPUT);

I can't look at all of if right now, myself, but just skimming through it, there are a few mistakes.

You know both codes work indepently, so try some debugging with the serial monitor.

Post any and all errors.


I tried to combine it, there was a problem saying UNDIFINED REFRENCE TO 'SETUP'

Code:
#include <avr/interrupt.h>
#include <avr/power.h>
#include <avr/sleep.h>
#include <avr/io.h>

#include <VirtualWire.h>

#include <Stepper.h>
#include <Adafruit_Fingerprint.h>
#if ARDUINO >= 100
 #include <SoftwareSerial.h>
#else
 #include <NewSoftSerial.h>
#endif
const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
                                     // for your motor
boolean lock_state;
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8,9,10,11);            

int getFingerprintIDez();
void lock_motor();

// pin #6 is IN from sensor (GREEN wire)
// pin #7 is OUT from arduino  (WHITE wire)
#if ARDUINO >= 100
SoftwareSerial mySerial(6, 7);
#else
NewSoftSerial mySerial(6, 7);
#endif

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void sleepsetup(void)
{
DDRD &= B00000011; // set Arduino pins 2 to 7 as inputs, leaves 0 & 1 (RX & TX) as is
DDRB = B00000000; // set pins 8 to 13 as inputs
PORTD |= B11111100; // enable pullups on pins 2 to 7
PORTB |= B11111111; // enable pullups on pins 8 to 13
pinMode(5,OUTPUT); // set pin 13 as an output so we can use LED to monitor
pinMode(12,OUTPUT);
digitalWrite(5,HIGH); // turn pin 13 LED on
digitalWrite(12,HIGH);

}

void fingersetup()  
{
  lock_state = HIGH;
    // set the speed at 60 rpm:
  myStepper.setSpeed(60);
  // initialize the serial port:
  //Serial.begin(9600);
  
  
  Serial.begin(9600);
  Serial.println("fingertest");

  // set the data rate for the sensor serial port
  finger.begin(57600);
  
  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1);
  }
  Serial.println("Waiting for valid finger...");
}


void Recieversetup()
{
    Serial.begin(9600); // Debugging only
    Serial.println("RECEIVER");

    // Initialise the IO and ISR
    vw_set_ptt_inverted(true); // Required for DR3100
    vw_setup(2000); // Bits per sec
    vw_set_rx_pin(4);
    vw_rx_start();      
    pinMode(13, OUTPUT);
}

void loop(void)
{
  delay(100);               //execute loop 10 times/second
  if (HIGH == digitalRead(2))      // if the FSR is not pressed
  {
    sleepNow();               // then go to sleep.  Stays asleep until FSR is pressed.
  }
delay(100);
   int msg_status = vw_have_message();
   uint8_t buf[VW_MAX_MESSAGE_LEN];
   uint8_t buflen = VW_MAX_MESSAGE_LEN;
  
   if (vw_get_message(buf, &buflen)); // Non-blocking [to reset the vw_rx_done flag]
   if(msg_status==1)
    {
        Serial.println("Something");
        getFingerprintIDez();
        digitalWrite(13, HIGH);
        delay(100);

     }
   else
   {
     Serial.println("Nothing");
     delay(100);
   }
   digitalWrite(13, LOW);
}

void fingerloop()                     // run over and over again
{
  getFingerprintIDez();
}

uint8_t getFingerprintID() {
  uint8_t p = finger.getImage();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println("No finger detected");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK success!

  p = finger.image2Tz();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }
  
  // OK converted!
  p = finger.fingerFastSearch();
  if (p == FINGERPRINT_OK) {
  

  
    Serial.println("Found a print match!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_NOTFOUND) {
    

  
    Serial.println("Did not find a match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }  
  
  // found a match!
  Serial.print("Found ID #"); Serial.print(finger.fingerID);
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
}

// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez() {
  uint8_t p = finger.getImage();
  if (p != FINGERPRINT_OK)  {
    lock_motor();
    return -1;
  }
  p = finger.image2Tz();
  if (p != FINGERPRINT_OK) {
    lock_motor();
    return -1;
  }

  p = finger.fingerFastSearch();
  if (p != FINGERPRINT_OK)  {
    lock_motor();
    return -1;
  }
  
  // found a match!

  Serial.print("Found ID #"); Serial.print(finger.fingerID);
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
  if (lock_state == HIGH){
      //This is for the motor  
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  delay(500);
  lock_state = LOW;
  }
  return finger.fingerID;

}

void lock_motor(){
  if (lock_state == LOW){
    // Is for the motor step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  delay(500);
  lock_state = HIGH;
  }
}

void sleeploop(void)
{
  delay(100);               //execute loop 10 times/second
  if (HIGH == digitalRead(2))      // if the FSR is not pressed
  {
    sleepNow();               // then go to sleep.  Stays asleep until FSR is pressed.
  }
}
void sleepNow(void) {
  sleep_enable();
  attachInterrupt(0, pinInterrupt, LOW);
  delay(100);
  set_sleep_mode(SLEEP_MODE_IDLE);
  power_adc_disable();
  power_spi_disable();
  power_timer0_disable();
  power_timer1_disable();
  power_timer2_disable();
  power_twi_disable();

  digitalWrite(5,LOW); // turn LED off to indicate sleep
  sleep_mode();
  digitalWrite(5,HIGH); // turn LED on to indicate awake
power_all_enable();

}

void pinInterrupt(void) {
  sleep_disable();
  detachInterrupt(0);
}
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 65
Posts: 2931
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You don't have a setup() function.
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You don't have a setup() function.


I thought if i rename my setup() fuctions, that will prevent it from interfering with other functions... Please can you take a look at my code..
Logged

Pages: [1] 2   Go Up
Jump to: