i working on project using arduino uno . project has 1 finger print scanner , 1 bluetooth module .since both bluetooth module , finger scanner works on rx tx pins .so had used soft serial having 2 rx,tx pins
both finger scanner , bluetooth same work, both turn on led
i have separate code both(fp ,bt) both sketch working individually
but when joined both code both finger scanner , bluetooth not working
this finger print sketch : //working
this bluetooth module sketch : //working
and final code : //not working
both finger scanner , bluetooth same work, both turn on led
i have separate code both(fp ,bt) both sketch working individually
but when joined both code both finger scanner , bluetooth not working
this finger print sketch : //working
code: [select]
#include <adafruit_fingerprint.h>
#include <softwareserial.h>
int led1 = 12, led2 = 11;
int getfingerprintidez();
softwareserial myserial(2, 3);
adafruit_fingerprint finger = adafruit_fingerprint(&myserial);
void setup()
{
serial.begin(9600);
serial.println("fingertest");
pinmode(led1 ,output);
pinmode(led2 ,output);
finger.begin(57600);
if (finger.verifypassword()) {
serial.println("found fingerprint sensor!");
} else {
serial.println("did not find fingerprint sensor :(");
while (1);
}
serial.println("waiting valid finger...");
}
void loop()
{
getfingerprintidez();
delay(50);
}
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;
}
p = finger.image2tz();
switch (p) {
case fingerprint_ok:
serial.println("image converted");
break;
case fingerprint_imagemess:
serial.println("image 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 print match!");
} else if (p == fingerprint_packetrecieveerr) {
serial.println("communication error");
return p;
} else if (p == fingerprint_notfound) {
serial.println("did not find match");
return p;
} else {
serial.println("unknown error");
return p;
}
serial.print("found id #"); serial.print(finger.fingerid);
serial.print(" confidence of "); serial.println(finger.confidence);
}
// returns -1 if failed, otherwise returns id #
int getfingerprintidez() {
uint8_t p = finger.getimage();
if (p != fingerprint_ok) return -1;
p = finger.image2tz();
if (p != fingerprint_ok) return -1;
p = finger.fingerfastsearch();
if (p != fingerprint_ok) return -1;
// found match!
digitalwrite(12,high);
delay(200);
digitalwrite(11,high);
delay(500);
serial.print("found id #"); serial.print(finger.fingerid);
serial.print(" confidence of "); serial.println(finger.confidence);
return finger.fingerid;
}
this bluetooth module sketch : //working
code: [select]
#include <softwareserial.h>
int led1= 12, led2 = 11, led3 = 10, led4 = 9, led5 = 8, led6 = 7;
string readstring;
int input = 0;
softwareserial myserial(2, 3);
void setup()
{
myserial.begin(9600);
serial.begin(9600);
pinmode(led1,output);
pinmode(led2,output);
pinmode(led3,output);
pinmode(led4,output);
pinmode(led5,output);
pinmode(led6,output);
}
void loop()
{
if(myserial.available() > 0)
{
input = myserial.read();
}
switch (input)
{
case 1:
digitalwrite(12, high);
break;
case 2:
{
digitalwrite(12, low);
digitalwrite(10, low);
digitalwrite(9, low);
digitalwrite(7, low);
}
break;
case 3:
digitalwrite(11, high);
break;
case 4:
digitalwrite(10, high);
break;
case 5:
digitalwrite(10, low);
break;
case 6:
digitalwrite(9, high);
break;
case 7:
digitalwrite(9, low);
break;
case 8:
digitalwrite(7, high);
break;
case 9:
digitalwrite(7, low);
}
}
and final code : //not working
code: [select]
#include <adafruit_fingerprint.h>
#include <softwareserial.h>
int led1= 12, led2 = 11, led3 = 10, led4 = 9, led5 = 8, led6 = 7;
string readstring;
int input = 0;
int getfingerprintidez();
softwareserial fpserial(2, 3);
softwareserial myserial(4, 5);
adafruit_fingerprint finger = adafruit_fingerprint(&fpserial);
void setup()
{
myserial.begin(9600);
serial.println("fingertest");
serial.begin(9600);
pinmode(led1,output);
pinmode(led2,output);
pinmode(led3,output);
pinmode(led4,output);
pinmode(led5,output);
pinmode(led6,output);
finger.begin(57600);
if (finger.verifypassword()) {
serial.println("found fingerprint sensor!");
} else {
serial.println("did not find fingerprint sensor :(");
while (1);
}
serial.println("waiting valid finger...");
}
void loop()
{
getfingerprintidez();
delay(50);.
if(myserial.available() > 0)
{
input = myserial.read();
}
switch (input)
{
case 1:
digitalwrite(12, high);
break;
case 2:
{
digitalwrite(12, low);
digitalwrite(10, low);
digitalwrite(9, low);
digitalwrite(7, low);
}
break;
case 3:
digitalwrite(11, high);
break;
case 4:
digitalwrite(10, high);
break;
case 5:
digitalwrite(10, low);
break;
case 6:
digitalwrite(9, high);
break;
case 7:
digitalwrite(9, low);
break;
case 8:
digitalwrite(7, high);
break;
case 9:
digitalwrite(7, low);
}
}
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;
}
p = finger.image2tz();
switch (p) {
case fingerprint_ok:
serial.println("image converted");
break;
case fingerprint_imagemess:
serial.println("image 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 print match!");
} else if (p == fingerprint_packetrecieveerr) {
serial.println("communication error");
return p;
} else if (p == fingerprint_notfound) {
serial.println("did not find match");
return p;
} else {
serial.println("unknown error");
return p;
}
serial.print("found id #"); serial.print(finger.fingerid);
serial.print(" confidence of "); serial.println(finger.confidence);
}
nt getfingerprintidez() {
uint8_t p = finger.getimage();
if (p != fingerprint_ok) return -1;
p = finger.image2tz();
if (p != fingerprint_ok) return -1;
p = finger.fingerfastsearch();
if (p != fingerprint_ok) return -1;
// found match!
digitalwrite(12,high);
delay(200);
digitalwrite(11,high);
delay(500);
serial.print("found id #"); serial.print(finger.fingerid);
serial.print(" confidence of "); serial.println(finger.confidence);
return finger.fingerid;
}
https://www.arduino.cc/en/reference/softwareserial
the library has following known limitations:
if project requires simultaneous data flows, see paul stoffregen's altsoftserial library. |
Arduino Forum > Using Arduino > Programming Questions > Two port receive not working (soft serial)
arduino
Comments
Post a Comment