Show Posts
Pages: [1] 2
1  Community / Gigs and Collaborations / Re: Please help me merge my codes (will PAY) on: February 09, 2013, 09:03:28 pm
HEllo Gigs, i am still a newbie in arduino programming, and i need your help. I m trying to merge three codes to work together, IDLE MODE CODE_FSR interrupt (which will put arduino to sleep), RECEIVER CODE (which communicate with transmitter), and FingerScanner&Step motorCODE(it identify correct finger print image and move stepmotor forward and back). I was able to get each code work separately, but i can not figure out how to make it work together. I was suggested to put all the codes in sequential, but i have no idea on how to put them. My general idea for the code is, while holding a FSR sensor,it will interrupt the arduino and wake it up from sleep, and stays awake, and then the finger can be scan at the fingerprint scanner and if the finger image 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 go back to its inital state and then arduino system will go back to an idle mode to save battery. And while these steps are happening, reciever will be receiving something form the transmitter, but if there is no signal from transmitter,reciever will block(disconnet / stop) all the code from working. if there is signal from transmitter it will make the code to work again. I NEED HELP. If any of you gigs willing to help me, please email me...thanks
2  Using Arduino / Programming Questions / Re: Please Need Help to combine two codes on: February 06, 2013, 12:12:15 pm
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..
3  Using Arduino / Programming Questions / Re: Please Need Help to combine two codes on: February 05, 2013, 08:54:58 pm
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);
}
4  Community / Gigs and Collaborations / Please help me merge my codes (will PAY) on: February 04, 2013, 06:28:02 pm
HEllo Gigs, i am still a newbie in arduino programming, and i need your help. I m trying to merge three codes to work together, IDLE MODE CODE_FSR interrupt (which will put arduino to sleep), RECEIVER CODE (which communicate with transmitter), and FingerScanner&Step motorCODE(it identify correct finger print image and move stepmotor forward and back). I was able to get each code work separately, but i can not figure out how to make it work together. I was suggested to put all the codes in sequential, but i have no idea on how to put them. My general idea for the code is, while holding a FSR sensor,it will interrupt the arduino and wake it up from sleep, and stays awake, and then the finger can be scan at the fingerprint scanner and if the finger image 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 go back to its inital state and then arduino system will go back to an idle mode to save battery. And while these steps are happing, reciever will be receiving something form the transmitter, but if there is no signal from transmitter,reciever will call block(disconnet) all the code. I NEED HELP. If you are willing to help me please email me...thanks
5  Using Arduino / Programming Questions / Re: Please Need Help to combine two codes on: February 02, 2013, 01:55:00 pm
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);
}
6  Using Arduino / Programming Questions / Re: Please Need Help to combine two codes on: February 02, 2013, 01:14:27 pm
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);
}
7  Using Arduino / Programming Questions / Re: Please Need Help to combine two codes on: January 31, 2013, 01:00:35 pm
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.
8  Using Arduino / Programming Questions / Re: Please Need Help to combine two codes on: January 31, 2013, 12:11:18 pm
Please i still need help to combine my two codes...thanks
9  Using Arduino / Programming Questions / Re: Please Need Help to combine two codes on: January 31, 2013, 12:02:55 pm
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
10  Using Arduino / Programming Questions / Re: Please Need Help to combine two codes on: January 31, 2013, 11:37:50 am
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....
11  Using Arduino / Programming Questions / Please Need Help to combine two codes on: January 31, 2013, 11:28:29 am
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;
  }
}



12  Using Arduino / Programming Questions / Re: Help with Programming Arduino Uno to sleep and wakeup with FSR sensor on: December 20, 2012, 06:40:01 pm
Thanks, Jack. I'm not totally surprised. If the voltage from the FSR when not pressed is quite high (eg. 4V) and when pressed is quite low (eg. 2V) then that effectively could be treated as a digital signal, because the digital inputs would have a "transition" zone (around 2.5V) where above that is considered high, and below is considered low.

Thanks for your help. I have one more question , how do i test to see if the arduino is at sleep or not. ?
13  Using Arduino / Programming Questions / Re: Help with Programming Arduino Uno to sleep and wakeup with FSR sensor on: December 15, 2012, 04:39:07 pm
Isn't an FSR a force sensitive resistor? Which is an analog device? Interrupts only work on digital changes (eg. high to low) so I wouldn't think an FSR is suitable, unless you hook it up to a comparator before the interrupt pin.

Quote
Please could you take a look at the code and see if i m doing it correct way.

Try it and see ...

Thanks Nick Gammon for your quick reply. Yes FSR is a force sensitve resistor. Please Nick Gammon, do you know or have a direction on how to connect FSR to comarator and then before connecting it to interrupt pin?
14  Using Arduino / Programming Questions / Re: Help with Programming Arduino Uno to sleep and wakeup with FSR sensor on: December 15, 2012, 01:35:30 am
Stuff about sleep:

http://gammon.com.au/power


And interrupts:

http://gammon.com.au/interrupts

Quote
... could you take a look at it ...

Can you use the auto-format tool to indent things please?

Next time please post your code inside code tags. Select the code and hit the # button above the posting area.

Thank you very much for the site. Based on the example code from that site, i put together a code that will work for my small project, but i m not sure if i m on the right track. Please could you take a look at the code and see if i m doing it correct way. I m planning to use FSR sensor to interrupt from pin2 and it will stays on while someone is holding the sensor, and then arduino will go back to idle as soon as the FSR sensor is realeas.

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

const byte LED = 9;
  
void wake ()
{
  // cancel sleep as a precaution
  sleep_disable();
}  // end of wake

void setup ()
  {
  digitalWrite (2, HIGH);  // enable pull-up
  }  // end of setup

void loop ()
{
 
  pinMode (LED, OUTPUT);
  digitalWrite (LED, HIGH);
  delay (50);
  digitalWrite (LED, LOW);
  delay (50);
  pinMode (LED, INPUT);
  
  // disable ADC
  ADCSRA = 0;  

  // turn off various modules
  PRR = 0xFF;
  
  set_sleep_mode (SLEEP_MODE_IDLE);  
  sleep_enable();

  // will be called when pin D2 goes low  
  attachInterrupt (0, wake, LOW);
 
  // turn off brown-out enable in software
  MCUCR = _BV (BODS) | _BV (BODSE);
  MCUCR = _BV (BODS);
  sleep_cpu ();  
  
  // must do this as the pin will probably stay low for a while
  detachInterrupt (0);
  
  } // end of loop

15  Using Arduino / Programming Questions / Re: Help with Programming Arduino Uno to sleep and wakeup with FSR sensor on: December 14, 2012, 09:48:57 am
Code:
// Stay awake for 1 second, then sleep.
// LED turns off when sleeping, then back on upon wake.
delay(100);

One second is 1000 mS not 100.

Thanks very much for the correction. I posted my code as you said. So, please can you or another person take look and see if i m on right track with the code at the below...thanks.

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
digitalWrite(13,HIGH); // turn pin 13 LED on

}
//
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)
{

/* Now is the time to set the sleep mode. In the Atmega8 datasheet
* http://www.atmel.com/dyn/resources/prod ... oc2486.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-man ... 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

sleep_mode();
//
// Upon waking up, sketch continues from this point.
sleep_disable();
digitalWrite(13,HIGH); // turn LED on to indicate awake

}
//
void pinInterrupt(void)
{
detachInterrupt(0);
}
Pages: [1] 2