Go Down

Topic: fingerprint scanner communication through uart (Read 14205 times) previous topic - next topic

drab

Code: [Select]
ok i whent back to post 26 and and added the i declaration.
i can get the input to come in and i see it in monitor whith the serial.print command. so i take it that its making it into my array correct.

here is the code
[code#include <NewSoftSerial.h>
#include <string.h>
NewSoftSerial fdk(2, 3);
int ledPin = 13;
int i = 0;
byte incomingByte[10];
byte array1[]={
  0xFF, 0xFF, 0xFF, 0xF5, 0xC0, 0x13, 0x0E, 0xFF, 0xFF, 0xFF, 0xF5};
byte array2[]={
  0xFF, 0xFF, 0xFF, 0xF5, 0xC0, 0x10, 0x0E, 0xFF, 0xFF, 0xFF, 0xF5};
byte array3[]={
  0xFF, 0xFF, 0xFF, 0xF5, 0xC0, 0x12, 0x0E, 0xFF, 0xFF, 0xFF, 0xF5};
byte array4[]={
  0xFF, 0xFF, 0xFF, 0xF5, 0xC0, 0x11, 0x0E, 0xFF, 0xFF, 0xFF, 0xF5};


void setup() 
{
  Serial.begin(9600);
  fdk.begin(9600);
  pinMode(13,OUTPUT);
  pinMode(12,OUTPUT);
}

void loop()
{

  if (fdk.available() >0 )
  {

    for(i=0; i<10;i++)
    {
      incomingByte[i] = fdk.read();
      Serial.print(incomingByte[i],HEX);
    }   
  }
  if(incomingByte[i]==array1[0])
  {
    digitalWrite(13,HIGH);
  }
  else
  {
    digitalWrite(12,HIGH);
  }
}



how do i now compare that input to the array i am using as a refrence...because this def didnt light an led lol
and do i still need to reset my index?and if so where do i do that at at the begginig of the void loop?

AWOL

Now you check to see if there is at least one character available, then you read all ten of them.
That's not sensible.
Either check in advance yyou've got ten available, or loop before you read each character until there's something to read.

drab

ok so i changed the if statement to this

if (fdk.available() <= 10 )

is this correct....i feel real stupid anymore it cant be this hard to do this i have done plenty of serial reads with other chips.....i just dont get why it wont work like i want it too

AWOL

No, look at the comparison.
Does that look correct ?

drab

this one? if(incomingByte==array1[0])

i dont think it does but when i try it with any other valeus in the index it dont work either and when i leave the index empty it says it expects a primary expression before ]

AWOL

Code: [Select]
if (fdk.available() <= 10 )
No, that one.

AWOL

Re. The leading/trailing FFs.
Have you read what "read" returns if there's nothing there to read?

drab

#67
May 26, 2012, 07:22 pm Last Edit: May 26, 2012, 07:28 pm by drab Reason: 1
yes it returns a -1 according to the refrence page...so i guess the leading and trailing Fs are not of intrest anyway..i can serial.print any value from the array to the monitor as well with the corrosponding index value in the[] and also with changing the index value in the serial.print incoming byte line i can pick out individual index values also and ive noticed through doing this that the Fs are nothing as far as the index is concerned so im wondering if the pre set array is set up wrong and thats where the problem lies

drab

the preset array was the issue i just lit my board led :) i guess here soon there will be working code for this thing floating around because i ams def goin to share it and here is what it looks like thanks awol and paul for all the help you have givin me

Code: [Select]
#include <NewSoftSerial.h>
#include <string.h>
NewSoftSerial fdk(2, 3);
int ledPin = 13;
int i = 0;
byte incomingByte[10];
byte array1[]={
   0xF5, 0xC,0x0, 0x1, 0x3, 0x0E, 0xFF, 0xFF, 0xFF, 0xF5};
byte array2[]={
  0xFF, 0xFF, 0xFF, 0xF5, 0xC0, 0x10, 0x0E, 0xFF, 0xFF, 0xFF, 0xF5};
byte array3[]={
  0xFF, 0xFF, 0xFF, 0xF5, 0xC0, 0x12, 0x0E, 0xFF, 0xFF, 0xFF, 0xF5};
byte array4[]={
  0xFF, 0xFF, 0xFF, 0xF5, 0xC0, 0x11, 0x0E, 0xFF, 0xFF, 0xFF, 0xF5};


void setup() 
{
  Serial.begin(9600);
  fdk.begin(9600);
  pinMode(13,OUTPUT);
  pinMode(12,OUTPUT);
}

void loop()
{

  if (fdk.available()> 0 )
  {
    for(i=0; i<10;i++)
    {
      incomingByte[i] = fdk.read();
      Serial.print(incomingByte[i],HEX);
    } 
   if(incomingByte[4]==array1[4])
  {
    digitalWrite(13,HIGH);
    Serial.print(array1[5],HEX);
  }
  else
  {
    digitalWrite(12,HIGH);
  }
  }
 
}

AWOL

Now you're back to "if there's at least one character available,  go ahead and read all ten of them"

drab

thx awol i apreciate the help... the reset array i was comparing the incoming data to was set up wrong once i got it set up properly it lit the match led right up for me

Go Up