hi, i have a problem to handle data from my finger print sensor via serial.
i already test the sensor using serial port terminal and it received something like this:
F5 23 01 F1 00 00 D3 F5 F5 00 00 00 DD 02 10 FF 09 3B 0C 12 0C 36 08 1E 10 33 07 1C 14 2F 08 20 88 18 99
3B 08 0A 9B 1B 03 28 9D 26 04 20 9E 30 04 12 C0 CC 1E 47 05 8A 20 28 05 A2 A1 45 06 84 22 20 08 1B 05 48 A3 3B
02 04 A4 15 05 2A 31 2E 06 92 B5 38 03 08 08 81 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 98 BA BB B9 7B 9B AB BB 00 00 00 00 00 00 00 00 00 00 00 00 5C 00 7D 00 10 10 FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 0D 01 FF FF FF FF FF FF FF FF FF FF FF
FF FF 1E 11 01 75 FF FF FF FF FF FF FF FF FF FF FF 27 1E 12 02 76 72 FF FF FF FF FF FF FF FF FF 27 23 1F 0F
03 7B 77 FF FF FF FF FF FF FF FF 27 27 23 1B 0F 03 7F 7B FF FF FF FF FF FF FF 2B 2B 27 23 1B 0F 07 03 7F FF
FF FF FF FF FF FF 2F 2B 23 1F 17 0F 07 03 7F FF FF FF FF FF FF FF 2B 27 1F 17 13 0B 07 03 7F FF FF FF FF FF
FF 2F 2B 23 1F 17 13 0B 07 03 03 FF FF FF FF FF FF 2B 2B 23 1B 17 0F 0B 07 03 03 FF FF FF FF FF FF 2B 27 1F
1B 13 0F 0B 07 03 03 FF FF FF FF FF FF 27 27 1F 17 13 0B 0B 07 07 03 FF FF FF FF FF FF 23 23 1F 17 0F 0B 07 07
07 FF FF FF FF FF FF FF FF 1F 1F 17 0F 0B 07 07 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF 00 91 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 AE 00 00 00 00 00 00 00 00 00 00 00 F5
it's about 460 bytes
and my code :
#include <LiquidCrystal.h>
LiquidCrystal lcd(9,8,7,6,5,4);
byte get[] = {0xF5, 0x23, 0x00, 0x00, 0x00, 0x00, 0x23, 0xF5};
byte myArr[600];
void setup(){
Serial.begin(115200);
lcd.begin(16,2);
lcd.clear();
lcd.print("waiting init");
delay(2000);
int i=0;
lcd.clear();
lcd.print("Send...");
Serial.write(get, 8);
while(!Serial.available()){}
while(Serial.available() > 0){
myArr[i] = Serial.read();
i++;
}
for(int a=0;a <= i; a++){
lcd.clear();
lcd.print(myArr[a]);
lcd.setCursor(0,1);
lcd.print(a);
delay(200);
}
delay(4000);
lcd.clear();
lcd.print("total");
lcd.setCursor(0,1);
lcd.print(i);
while(1){}
}
void loop(){
}
i only receive 68 bytes.
What i have to do to receive all the data without overflow the data
thanks
check out Serial Input Basics .
It looks like you are emptying the buffer before you get all of the data. Once there is nothing in the buffer, Serial.available() becomes false...
system
February 23, 2017, 1:19pm
3
Once there is nothing in the buffer, Serial.available() becomes false...
No, it doesn't. It returns 0, meaning that there is not data.
BulldogLowell:
check out Serial Input Basics .
It looks like you are emptying the buffer before you get all of the data. Once there is nothing in the buffer, Serial.available() becomes false...
thanks for all of your reply.
i'll check it out
Guys i still got this problem,
From the result that i got from serial port terminal i should got 508 byte but i only got 488 bytes.
i already read this basic serial about serial data is slow in arduino.
That post said in 115200 baud rate, there's 86 microseconds gap for one character (CMIIW)
So first i add delay at this loop around 60 until 90 microseconds but the best i got are in 64, 65, 66, 68, 69, 71, 72, 73, 74 which got 488 bytes.
while(Serial.available() > 0){
myArr[i] = Serial.read();
i++;
delayMicroseconds(80);
}
is there something i have missed?
thanks
system
February 28, 2017, 11:23am
9
is there something i have missed?
Yes. The fact that you should NOT have ANY delay() in the loop that handles reading serial data.
You have to either KNOW how many bytes to expect, AND hope like hell that every one gets through, OR you have to have some way of recognizing what constitutes the start of a packet and what constitutes the end of a packet.
Either way, you start reading the data at the appropriate point, and stop at the appropriate point.
Anything else is not going to work.
Robin2
February 28, 2017, 2:01pm
10
samuelbles:
i already read this basic serial about serial data is slow in arduino.
That post said in 115200 baud rate, there's 86 microseconds gap for one character (CMIIW)
So first i add delay at this loop around 60 until 90 microseconds
You may have read it but you did not study it. If you had you would have noticed that it does not use delay().
...R
PaulS:
Yes. The fact that you should NOT have ANY delay() in the loop that handles reading serial data.
You have to either KNOW how many bytes to expect, AND hope like hell that every one gets through, OR you have to have some way of recognizing what constitutes the start of a packet and what constitutes the end of a packet.
Either way, you start reading the data at the appropriate point, and stop at the appropriate point.
Anything else is not going to work.
Thanks for your patience to me. I already figure it out what i have to do, i don't know why i don't think to use that way.
while(i < 508){
if(Serial.available() > 0){
myArr[i] = Serial.read();
i++;
}
}
Robin2:
You may have read it but you did not study it. If you had you would have noticed that it does not use delay().
...R
Thanks R for your thread about basic serial in arduino.
Robin2
February 28, 2017, 5:26pm
12
samuelbles:
while(i < 508){
if(Serial.available() > 0){
myArr[i] = Serial.read();
i++;
}
}
That is not very robust and it blocks the Arduino while it is doing it (which may or may not matter).
The reason I say it is not robust is because it cannot deal with the situation where fewer than 508 bytes arrive. When you use a serial connection you have no control over what arrives so you must plan for all sorts of behaviour.
And the reason it blocks is because you are using WHILE.
...R