hi everyone. i have a question here. i need to sent 8 bytes command code to a fingerprint reader. and then, read the 6 bytes respond code of the reader. sending & reading the code is via serial (RX & TX). i already made the code. but, it is not working. i just want to ask your opinion what's wrong with my code here. seems that the TX & RX LED even not light up when i start the program. thank you.
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8,9,4,5,6,7);
byte addFingerPrint[] = {0x4D, 0x58, 0x10, 0x03, 0x40, 0x00, 0x00, 0xF8};
byte respond = 0;
void setup() {
// initialize serial:
Serial.begin(57600);
// set up the LCD's number of columns and rows:
lcd.begin(8, 2);
displayLCD();
addFinger();
correctRespond();
}
void displayLCD(){
// set the cursor to column 0, line 1
lcd.setCursor(0, 0);
// Print a message to the LCD.
lcd.print("Reader");
}
void addFinger(){
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print("Add");
// print the string when a newline arrives:
Serial.write(addFingerPrint, sizeof(addFingerPrint));
delay(1000);
}
void correctRespond() {
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print("Cor");
if (Serial.available()) {
// read the most recent byte
respond = Serial.read();
}
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// print the correct respond code of the reader (0x4D, 0x58, 0x30, 0x01, 0x01, 0xD7)
lcd.print("Cor=");
lcd.print(respond, HEX);
delay(1000);
}
void loop() {
}
How many characters of the reply are you reading? How long are you waiting for the reply?
Hi,
First thing in your code, in correctRespond function you should poll until the fingerprint reader sent back a response, just in case correctRespond is called too early, before the fingerprint reader had enough time to respond. You can do something like this:
void correctRespond() {
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print("Cor");
while(Serial.available() == 0){
delay(10);
}
// read the most recent byte
respond = Serial.read();
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// print the correct respond code of the reader (0x4D, 0x58, 0x30, 0x01, 0x01, 0xD7)
lcd.print("Cor=");
lcd.print(respond, HEX);
delay(1000);
}
while(Serial.available() == 0){
delay(10);
}
Can you describe the exact purpose for the delay()? Does it matter whether the while loop iterates 10 times in 100 milliseconds, or 10,000,000?
If you know (or think/hope) that the response is going to be 6 bytes, wait for 6,
Then, of course, you still need to read all 6 of them.
respond = Serial.read();
this command i believe just read a byte / char. if i want to put a loop, which read 6 bytes. how i'm gonna make it. of course it need a for loop. but, how i gonna integrate the counter with the serial read.
for (int n=0; n<7; n++) {
{
this command i believe just read a byte / char. if i want to put a loop, which read 6 bytes. how i'm gonna make it. of course it need a for loop. but, how i gonna integrate the counter with the serial read.
That for loop will iterate while n = 0, 1, 2, 3, 4, 5, and 6. That's 7 iterations, not 6.
byte reply[6];
for(byte n=0; n<6; n++)
{
while(Serial.available() == 0) {}; // Wait for a byte
reply[n] = Serial.read();
}
// Now, reply contains all 6 bytes
understand. now i'm using x-ctu serial terminal.
You've removed the fingerprint reader?
but the x-ctu hyperterminal shows FF
Also known as -1 (no data).
X-CTU is fine for talking to XBees. Other than that, I find it useless.
nono.. it's correct. i'm mistaken configure the baud. is shows all the 8 bytes. correctly. i just want to check whether it's write the 8 bytes. this tips is being told by my lecturer. to check the bytes of the TX pin.
the uno transmit 8 bytes. if it managed to receive respond code, how i'm gonna compare it either right or wrong? can i just make it like this? correct respond is 6 bytes while wrong respond is 7 bytes.
for(byte n=0; n<7; n++)
{
while(Serial.available() == 0) {}; // Wait for a byte
respond[n] = Serial.read();
}
// Now, reply contains all 6 bytes
if (respond== "0x4D + 0x58 + 0x30 + 0x01 + 0x01 + 0xD7"){
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// print the correct respond
lcd.print("Correct Respond");
}
else if(respond== "0x4D + 0x58 + 0x30 + 0x02 + 0x40 + 0x35 + 0x4C"){
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// print the wrong respond
lcd.print("Wrong Resp");
}
Hello? Are you listening?
for(byte n=0; n<7; n++)
will iterate SEVEN times, not 6.
if (respond== "0x4D + 0x58 + 0x30 + 0x01 + 0x01 + 0xD7"){
The address of an array of bytes will NEVER equal the address of a literal string.
You can have another array,
byte correct[] = {0x4D, 0x58, 0x30, 0x01, 0x01, 0xD7};
Then, you can use memcmp() to compare the arrays. But, you can't just make up stuff.
memcmp()? by the way, it is quite confusing. because the correct command respond is 6 bytes but wrong command respond is 7 bytes. that is the reason why i put 7 sir.
byte correctRespond[] = {0x4D, 0x58, 0x30, 0x01, 0x01, 0xD7};
byte wrongrespond[] = {0x4D, 0x58, 0x30, 0x02, 0x40, 0x35, 0x4C);
the fingerprint reader respond correct or wrong not in same byte length.
by the way, it is quite confusing. because the correct command respond is 6 bytes but wrong command respond is 7 bytes.
Perhaps you need to post a link to the fingerprint reader. It does not make sense to return two different length arrays when the finger print is valid and is not valid.
Perhaps you need to post a link to the fingerprint reader. It does not make sense to return two different length arrays when the finger print is valid and is not valid.
if u think that way, i also think the same. nevermind. but how i'm gonna post the link to the reader. i need to compare lots of byte array. memcmp()
but how i'm gonna post the link to the reader.
Use the 3rd icon on the bottom row. Paste the URL after clicking the icon.
but how i'm gonna post the link to the reader.
Use the 3rd icon on the bottom row. Paste the URL after clicking the icon.
i'm sorry. i don't understand sir.
Where did you get the fingerprint reader you are trying to talk to? We have to know something about it in order to help you.
my fingerprint? this is my fingerprint that i bought. at first i juz thought simple RX & TX. i never thought that it quite difficult to a beginner like me. SN-FPR-SM630. thank you mr pauls.
http://www.cytron.com.my/viewProduct.php?pcode=SN-FPR-SM630&name=Fingerprint%20Reader%20Integrated%20SM630
i've studied a little bit. thank you to u sir. finally understand it a little bit. but, too bad. i don't bring the reader to my house. i left it at my hostel. at least i know the basic function. but, i'm not sure either this is the correct way to compare it. but, i know the basic operation by the way. i just not sure about the
m = memcmp(operationSuccess, operation, sizeof(operationSuccess));
by the way, thank you so much sir. at least from zero. i got half of it on what you told me. i wish i could got all of it. but i know, i need to study more. thank you coz taught me.
byte operationSuccess[] = {0x4D, 0x58, 0x30, 0x02, 0x40, 0x31, 0x48};
byte operation[7],m;
void operationSuccesful() {
// Now, reply contains all 7 bytes
for(byte n=0; n<7; n++)
{
while(Serial.available() == 0) {}; // Wait for a byte
operation[n] = Serial.read();
m = memcmp(operationSuccess, operation, sizeof(operationSuccess));
if (m>0) {
// set the cursor to column 0, line 1
lcd.setCursor(0, 0);
// print the number of seconds since reset:
lcd.print("Operation Failed");
}
else if (m<0) {
// set the cursor to column 0, line 1
lcd.setCursor(0, 0);
// print the number of seconds since reset:
lcd.print("Operation Failed");
}
else {
// set the cursor to column 0, line 1
lcd.setCursor(0, 0);
// print the number of seconds since reset:
lcd.print("Operation Success");
}
}
}
hello everyone. i currently make try to make a simple project. uno with fingerprint reader. as startup i try to add fingerprint.
at first. i try run the fingerprint reader + uno with X-CTU only. i use the terminal of the X-CTU. i sent the command code of the reader. and the reader reply with correct respond code & success operation code.
as u can see in the picture, the first 8 bytes {0x4D, 0x58, 0x10, 0x03, 0x40, 0x00, 0x00, 0xF8} is the command code for add fingerprint. then the reader reply 6 bytes correct respond code, {0x4D, 0x58, 0x30, 0x01, 0x01, 0xD7}. later the reader reply 7 bytes success operation code, {0x4D, 0x58, 0x30, 0x02, 0x40, 0x31, 0x48}.
then, i try make the program. so that it follow exactly what the reader respond as i tested above. i manage to make the code. by using X-CTU. i key the respond code, the arduino program able to detect the 6 bytes of the correct respond code & 7 bytes of success operation.
however, when i try to combine them both, it doesn't being to be happen. the arduino uno transmit the command code. but, the reader doesn't respond to that code. i believe there is a problem with my code. but, i don't have any idea where's the problem. with all, regards.
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8,9,4,5,6,7);
byte addFingerPrint[] = {0x4D, 0x58, 0x10, 0x03, 0x40, 0x00, 0x00, 0xF8}; // 8 bytes
byte respondCorrect[] = {0x4D, 0x58, 0x30, 0x01, 0x01, 0xD7}; // 6 bytes
byte operationSuccess[] = {0x4D, 0x58, 0x30, 0x02, 0x40, 0x31, 0x48}; // 7 bytes
byte timeOut[] = {0x4D, 0x58, 0x30, 0x02, 0x40, 0x33, 0x4A}; // 7 bytes
byte processFailure[] = {0x4D, 0x58, 0x30, 0x02, 0x40, 0x34, 0x4B}; // 7 bytes
byte parameterError [] = {0x4D, 0x58, 0x30, 0x02, 0x40, 0x35, 0x4C}; // 7 bytes
byte respond[6],operation[7],a,b,c,d;
void setup() {
// initialize serial:
Serial.begin(57600);
// set up the LCD's number of columns and rows:
lcd.begin(8, 2);
displayLCD();
addFinger();
correctRespond();
operationSuccesful();
}
void displayLCD(){
// set the cursor to column 0, line 0
lcd.setCursor(0, 0);
// Print a message to the LCD.
lcd.print("Fingerprint Reader");
}
void addFinger(){
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// Print a message to the LCD.
lcd.print("Add Fingerprint");
// write the 8bytes array of the command code
Serial.write(addFingerPrint, sizeof(addFingerPrint));
//delay(2000);
}
void correctRespond() {
// Now, reply contains all 6 bytes
for(byte n=0; n<6; n++)
{
while(Serial.available() == 0) {}; // Wait for a byte
respond[n] = Serial.read();
a = memcmp(respondCorrect, respond, sizeof(respondCorrect));
if (a>0) {
// set the cursor to column 0, line 0
lcd.setCursor(0, 0);
// Print a message to the LCD.
lcd.print("Wrong ");
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// Print a message to the LCD.
lcd.print("Respond ");
}
else if (a<0) {
// set the cursor to column 0, line 0
lcd.setCursor(0, 0);
// Print a message to the LCD.
lcd.print("Wrong ");
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// Print a message to the LCD.
lcd.print("Respond ");
}
else {
// set the cursor to column 0, line 0
lcd.setCursor(0, 0);
// Print a message to the LCD.
lcd.print("Correct ");
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// Print a message to the LCD.
lcd.print("Respond ");
}
}
delay(2000);
}
void operationSuccesful() {
// Now, reply contains all 7 bytes
for(byte n=0; n<7; n++)
{
while(Serial.available() == 0) {}; // Wait for a byte
operation[n] = Serial.read();
b = memcmp(operationSuccess, operation, sizeof(operationSuccess));
if (b==0) {
// set the cursor to column 0, line 0
lcd.setCursor(0, 0);
// Print a message to the LCD.
lcd.print("Operation");
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// Print a message to the LCD.
lcd.print("Success ");
}
else {
c = memcmp(processFailure, operation, sizeof(processFailure));
if (c==0) {
// set the cursor to column 0, line 0
lcd.setCursor(0, 0);
// Print a message to the LCD.
lcd.print("Process ");
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// Print a message to the LCD.
lcd.print("Failure ");
}
else {
d = memcmp(parameterError, operation, sizeof(parameterError));
if (d==0) {
// set the cursor to column 0, line 0
lcd.setCursor(0, 0);
// Print a message to the LCD.
lcd.print("Parameter");
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// Print a message to the LCD.
lcd.print("Error ");
}
else {
// set the cursor to column 0, line 0
lcd.setCursor(0, 0);
// Print a message to the LCD.
lcd.print("Time ");
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// Print a message to the LCD.
lcd.print("Out ");
}
}
}
}
delay(2000);
}
void loop() {
}
Why are you starting a new thread on the same topic?
And, by the magic of Moderation, back to a single topic.
i have a question here. is it possible for me to make a counter for the command code. for the add fingerprint add. by the way, it works. just the matter wrong connection for the RX & TX. not the programming.
is it possible for me to make a counter for the command code. for the add fingerprint add.
If you explain what you mean by that, probably, yes.
what i mean is this byte.
byte deleteFingerPrint[] = {0x4D, 0x58, 0x10, 0x03, 0x42, 0x00, 0x00, 0xF8}; // 8 bytes
above is for fingerprint address 0. for finger print address 1, the only bytes those are changing are last 3 bytes. 00 01 F9. and for address 2, 00 02 FA. 3rd last bytes is for high byte 2nd last byte is for low byte & last byte is for check some. is the any mathematical expression that i can use in order it can change automatically according to the address?
what i mean is this byte.
Which one?
There are eight.
If you're saying "Can I save the fixed first five bytes in one array, and have another 2D array holding the variable final three bytes, indexed by a counter?" then the answer is yes.
const byte fixedPart [5] = {0x4D, 0x58, 0x10, 0x03, 0x42};
byte variableParts [SOME_NUMBER][3];
yup. like that. but how i want to integrate it with a counter? address 0, 0x00 0x00 0xF8. address 1, 0x00 0x01 0xF9. address 2, 0x00 0x02 FA. and so on.
You just use the first subscript of "variableParts".
Or maybe I don't understand what you mean by "counter".
lets say later i want to key in the fingerprint address that i wanted to add / delete. i will key in it in the serial monitor. so, how i'm gonna link it with the variable byte? if i want to add address 0, i key in 0 in the serial monitor. then, it will look for byte address 0. and so on. on the linking part between the key in of the address in the serial monitor & variable byte. for the structure to accept input from serial monitor, that one i know how to do it.
so, how i'm gonna link it with the variable byte?
Say you key in '1'.
So, '1' - '0' = 1. (or use "atoi" or whatever if you've captured a string)
Use that 1 as a subscript for the "variablePart" array.
Say you key in '1'.
So, '1' - '0' = 1. (or use "atoi" or whatever if you've captured a string)
Use that 1 as a subscript for the "variablePart" array.
i'm sorry sir. i don't get that.
Which bit?
Subtraction (http://arduino.cc/en/Reference/Arithmetic) or subscripting (http://arduino.cc/en/Reference/Array)?
byte variableParts [SOME_NUMBER][3];
when i want try to compile, it shows an error. not declare in this scope. how i want to declare it. may i have an example? so that i know how it works.
const int SOME_NUMBER = 10;
Which bit?
Subtraction (http://arduino.cc/en/Reference/Arithmetic) or subscripting (http://arduino.cc/en/Reference/Array)?
perhaps all i think. perhaps i can get an example on both of them. it might help to get me understand on it.
const int SOME_NUMBER = 10;
with that, can i modification on byte right? put mathematical operation on it.
byte or int, they're both capable of arithmetic operations
with const int SOME_NUMBER = 10; how it could link with other 2 bytes?
byte variableParts [SOME_NUMBER][3]; how it would link between the [3]?
while(Serial.available() == 0){
delay(10);
}
Can you describe the exact purpose for the delay()? Does it matter whether the while loop iterates 10 times in 100 milliseconds, or 10,000,000?
If you know (or think/hope) that the response is going to be 6 bytes, wait for 6,
Then, of course, you still need to read all 6 of them.
You're right the delay doesn't really matter, I put it just to understand the need to wait.
About the wait of 6 bytes, keep in mind, for later use, the size of the buffer used by Serial library to store the received bytes, 16bytes if I remember well. Typicaly don't expect to be able to do a
while(Serial.available() < 32);
keep in mind, for later use, the size of the buffer used by Serial library to store the received bytes, 16bytes if I remember well.
You don't ;) (unless you've got very restricted RAM, like on a Tiny)
You're right the delay doesn't really matter, I put it just to understand the need to wait.
About the wait of 6 bytes, keep in mind, for later use, the size of the buffer used by Serial library to store the received bytes, 16bytes if I remember well. Typicaly don't expect to be able to do a while(Serial.available() < 32);
with my current code now, it is working. able to add, delete, search empty the fingerprint. i made separate file coding. right now, i'm studying how i'm gonna adjust the fingerprint address according to the address i want to store the fingerprint. for add fingerprint, the last 3 bytes of the command code should be adjustable & depend on the input in the serial monitor. i'm stuck here. still trying.
with const int SOME_NUMBER = 10; how it could link with other 2 bytes?
byte variableParts [SOME_NUMBER][3]; how it would link between the [3]?
I don't understand what you're asking here.
What do you mean by "link"?
If you've got three bytes, let's say a, b, c, and you want to store them in the second instance of "variableParts", then
variableParts [1][0] = a;
variableParts [1][1] = b;
variableParts [1][2] = c;
what i mean is link to here
byte addFingerPrint[5] = {0x4D, 0x58, 0x10, 0x03, 0x40}; // 8 bytes
byte variableParts [SOME_NUMBER][3];
Serial.write(addFingerPrint, sizeof(addFingerPrint));
how to integrate & link it with Serial.write?
byte addFingerPrint[5] = {0x4D, 0x58, 0x10, 0x03, 0x40}; // 8 bytes
byte variableParts [SOME_NUMBER][3];
Serial.write(addFingerPrint, sizeof(addFingerPrint));
Serial.write(variableParts [someIndex], 3);
understand. should be like this. the output bytes still 8 bytes as i wanted. now, i need to do is made the variable byte become something that can be manipulate. how ya?
byte addFingerPrint[] = {0x4D, 0x58, 0x10, 0x03, 0x40}; // 5 bytes
byte variableParts [] = {0x00, 0x00, 0xF8}; // 3 bytes
Serial.write(addFingerPrint, sizeof(addFingerPrint));
Serial.write(variableParts, sizeof(variableParts));
i need to do is made the variable byte become something that can be manipulate.
It's in RAM. You can do whatever you like with it (within the Laws of Thermodynamics)
I'm sorry, I really can't see what the problem is here. You seem to be overthinking it.
how ya?
I'm very well, thank you for asking.
how ya?
I'm very well, thank you for asking.
haha.. i'm sorry. it is not that i want to ask how about u. just the meaning "ya" at my place is same like "erh" something like that. a tone asking question actually. sorry for the misunderstanding. haha.
yup. i'm overthinking. coz i dont know how to put a variable in order to change the byte accordingly to the fingerprint address.
i don't know how to make the increment formula actually i think. increment formula for the byte. increment by one byte. how many the increment in depend on the user input the fingerprint address. i think so. like that. that's the one that i stuck.
byte high = {0x00};
byte low = {0x00};
byte checksum = {0xF8};
for (int n=0; n<798; n++)
I'm sorry, this is beyond me now.
Where did the value 798 magic itself from?
What are the variables "high" and "low" meant to be?
keep in mind, for later use, the size of the buffer used by Serial library to store the received bytes, 16bytes if I remember well.
You don't ;) (unless you've got very restricted RAM, like on a Tiny)
I was not so wrong ]:D, took this in HardwareSerial.cpp:
// Define constants and variables for buffering incoming serial data. We're
// using a ring buffer (I think), in which head is the index of the location
// to which to write the next incoming character and tail is the index of the
// location from which to read.
#if (RAMEND < 1000)
#define SERIAL_BUFFER_SIZE 16
#else
#define SERIAL_BUFFER_SIZE 64
#endif
In your case it's working because you are in the case where buffer size is 64.
I'm sorry, this is beyond me now.
Where did the value 798 magic itself from?
What are the variables "high" and "low" meant to be?
the last 3 bytes. 3rd last byte is for highbyte of the fingerprint reader address. 2nd last byte is for lowbyte of the fingerprint address. while the last byte is the checksum. 798 is the total fingerprint address that the reader can store.
byte high = {0x00}; // high byte of the fingerprint address
byte low = {0x00}; // low byte of the fingerprint address
byte checksum = {0xF8}; // checksum
the address 0, is above. but, for address 1.
byte high = {0x00}; // high byte of the fingerprint address
byte low = {0x01}; // low byte of the fingerprint address
byte checksum = {0xF9}; // checksum
while for address 2,
byte high = {0x00}; // high byte of the fingerprint address
byte low = {0x02}; // low byte of the fingerprint address
byte checksum = {0xFA}; // checksum
continously until 768 address. sorry. not 798. 768 fingerprint address. total fingerprint address that the fingerprint reader can store. i believe it is related to the Serial.available as i will key in the fingerprint address.
Serial.print("Please choose fingerprint address number to store");
while(Serial.available()){
input = Serial.read;
high = high + input;
low= low + input;
checksum = checksum + input;
}
// write the 8bytes array of the command code
Serial.write(addFingerPrint, sizeof(addFingerPrint));
Serial.write(high);
Serial.write(low);
Serial.write(checksum);
}
until here. then i stuck a little bit. coz the input from serial monitor is ASCII. while i'm using bytes. how i'm gonna convert the ascii into byte in arduino?
I was not so wrong smiley-twist, took this in HardwareSerial.cpp:
Yes, and how many
Arduinos does that apply to?
I was not so wrong smiley-twist, took this in HardwareSerial.cpp:
Yes, and how many Arduinos does that apply to?
I don't know. But I think it's better to be aware of the under layer limitation even if it's seems large.
until here. then i stuck a little bit. coz the input from serial monitor is ASCII. while i'm using bytes. how i'm gonna convert the ascii into byte in arduino?
That depends. What format are you trying to key it in as (Decimal, Binary, Hex, etc.) and how many characters are being sent? Are you always sending the same amount of characters for each value, or does the number of characters sent vary?
as i key in from serial monitor arduino. i key in ASCII. then, when i want to make an increment, supposed to be that the key in value is converted into byte. to add with my formula for the byte.
as i key in from serial monitor arduino. i key in ASCII.
Yes, you can't key it in any other way with the Serial Monitor, but you have to define what the ascii characters mean. Does "10" mean 10 or 2? Does "30" mean 30 or 48? Does "fruit cup" mean 0 or 666?
why can't? by the way, is it need to define? can just arduino program automatically convert the input ascii code to byte?
If you're not going to bother answering my question, I'm not going to bother to respond.
as i key in from serial monitor arduino. i key in ASCII.
Yes, you can't key it in any other way with the Serial Monitor, but you have to define what the ascii characters mean. Does "10" mean 10 or 2? Does "30" mean 30 or 48? Does "fruit cup" mean 0 or 666?
actually, i only get half. don't understand the other half actually. it is not that i'm don't want to answer your question.
You are putting characters into the Serial Monitor and expecting the Arduino to understand how to convert them to a number. You have to define whether the Arduino interprets those stream of characters as binary, hex, decimal, or some crazy custom encoding scheme.
You are putting characters into the Serial Monitor and expecting the Arduino to understand how to convert them to a number. You have to define whether the Arduino interprets those stream of characters as binary, hex, decimal, or some crazy custom encoding scheme.
understand little bit. is true that like this?
byte input = 0; // for incoming serial data
byte addFingerPrint[] = {0x4D, 0x58, 0x10, 0x03, 0x40}; // 5 bytes
byte high = {0x00}; // 1 high byte
byte low = {0x00}; // 1 low byte
byte checksum = {0xF8}; // checksum
void setup() {
Serial.begin(57600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
input = Serial.read();
// say what you got:
//Serial.print("I received: ");
//Serial.println(input, DEC);
high = high + input;
low= low + input;
checksum = checksum + input;
Serial.write(high);
Serial.write(low);
Serial.write(checksum);
}
}
by the input still yet ASCII although i already defined the input as byte.
high = high + input;
This will sum the ASCII value of whatever you enter - is that what you intended?
BTW, you can abbreviate it to
high += input;
by the input still yet ASCII although i already defined the input as byte.
Again, I don't understand what you mean by this.
i connected usb serial devices & check the input from arduino serial monitor by using X-CTU terminal. when i key in "10" the x-ctu terminal shows than the number is in ASCII.
by the way, how i'm gonna modify this program. the current program only one menu push button. but, i want to adjust it so that it can runs 2 menu push button. what i mean is, one main menu, and one sub menu.
//==========================================================================
// Author : CYTRON TECHNOLOGIES SDN BHD
// Project : Arduino Duemilanove
// Project description : Project_1: "Hello World" and utilize switch
//==========================================================================
#include <LiquidCrystal.h>
/*
The circuit:
* LCD RS pin to digital pin 8
* LCD Enable pin to digital pin 9
* LCD D4 pin to digital pin 4
* LCD D5 pin to digital pin 5
* LCD D6 pin to digital pin 6
* LCD D7 pin to digital pin 7
* LCD R/W pin to ground
*/
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int analogPin = A0;
int adc_key_old;
int adc_key_in;
int NUM_KEYS = 5;
int key=-1;
int adc_key_val[5] ={30, 150, 360, 535, 760};
/*******************************************************************************
* PRIVATE FUNCTION: setup()
*
* PARAMETERS:
* ~ void
*
* RETURN:
* ~ void
*
* DESCRIPTIONS:
* Define of I/O pin as Input or Output
*
*******************************************************************************/
// The setup() method runs once, when the sketch starts
void setup ()
{
// initialize serial:
Serial.begin(57600);
lcd.begin(16, 2); // set the lcd dimension
lcd.clear(); // LCD screen clear
lcd.print(" CYTRON TECH."); // display the text
lcd.setCursor(0,1); // set lcd.setCursor (column,row)
lcd.print(" Eg. LCD Shield");
delay(1500); // delay for 3000ms
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Fingerprint Reader");
lcd.setCursor(0,1);
lcd.print("Select Address");
adc_key_old = analogRead(analogPin); // store the unpress key value
}
/*******************************************************************************
* PRIVATE FUNCTION: loop()
*
* PARAMETERS:
* ~ void
*
* RETURN:
* ~ void
*
* DESCRIPTIONS:
* Non-Stop looping
*
*******************************************************************************/
void loop()
{
adc_key_in = analogRead(analogPin); // read ADC value
adc_key_in = get_key(adc_key_in);
if (adc_key_in==0)
{
lcd.setCursor(0,1); // set lcd.setCursor (column,row)
lcd.print("Menu 1");
}
else if (adc_key_in==1)
{
lcd.setCursor(0,1); // set lcd.setCursor (column,row)
lcd.print("Menu 2");
}
else if (adc_key_in==2)
{
lcd.setCursor(0,1); // set lcd.setCursor (column,row)
lcd.print("Menu 3");
}
else if (adc_key_in==3)
{
lcd.setCursor(0,1); // set lcd.setCursor (column,row)
lcd.print("Menu 4");
}
else if (adc_key_in==4)
{
lcd.setCursor(0,1); // set lcd.setCursor (column,row)
lcd.print("Menu 5");
}
}
/*******************************************************************************
* PRIVATE FUNCTION: get_key
*
* PARAMETERS:
* ~ integer
*
* RETURN:
* ~ unsigned int input
*
* DESCRIPTIONS:
* convert the ADC value to number between 0 to 4
*
*******************************************************************************/
int get_key(unsigned int input)
{
int k;
for (k = 0; k < NUM_KEYS; k++)
{
if (input < adc_key_val[k])
{
return k;
}
}
if (k >= NUM_KEYS)
k = -1; // No valid key pressed
return k;
}
Yes, ASCII is what I would expect them to be in.
Having them in EBCDIC would make things very difficult.
Yes, ASCII is what I would expect them to be in.
Having them in EBCDIC would make things very difficult.
it is quite difficult to make the input become byte although the input variable i had defined as byte. plus with the reader itself connected with uno via serial. seems like quite not possible unless i use another serial terminal devices. thus, i decided to use switch instead of the serial monitor. i have a LCD shield embedded together with 5 switches. the manufacturer included together simple program how to use the switch. but, it is only one menu. i want to adjust it so that it can become 2 menu. 1 main menu & 1 sub menu.
let say I want to have two menu on my LCD, when power on, it shows the main menu
1. XXX
2.YYY
3.ZZZ
so if I press SW1, then it will go to menu 1
then in menu 1, it will have another option :
1. AAA
2.BBB
3.CCC
so how can I program so that I can press the sw 1 again to go to the option AAA ? based with the arduino program code that i attached in previous post.
below code is already functioning. but, may i ask. is there any other way that i can make the code become less line. i think there is another way. but, i don't have any idea how to do it. i think the value of adc_key_in can be made into for loop so that if counter 0, it will call function deleteFinger0();
but i don't have any clue on how to do it. i would be glad if someone could give me a hint on how to do it. thank you.
//==========================================================================
// Author : CYTRON TECHNOLOGIES SDN BHD
// Project : Arduino Duemilanove
// Project description : Project_1: "Hello World" and utilize switch
//==========================================================================
#include <LiquidCrystal.h>
/*
The circuit:
* LCD RS pin to digital pin 8
* LCD Enable pin to digital pin 9
* LCD D4 pin to digital pin 4
* LCD D5 pin to digital pin 5
* LCD D6 pin to digital pin 6
* LCD D7 pin to digital pin 7
* LCD R/W pin to ground
*/
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int analogPin = A0;
int adc_key_old;
int adc_key_in;
int NUM_KEYS = 5;
int key=-1;
int adc_key_val[5] ={30, 150, 360, 535, 760 };
byte deleteFingerPrint0[] = {0x4D, 0x58, 0x10, 0x03, 0x42, 0x00, 0x00, 0xFA}; // 8 bytes
byte deleteFingerPrint1[] = {0x4D, 0x58, 0x10, 0x03, 0x42, 0x00, 0x01, 0xFB}; // 8 bytes
byte deleteFingerPrint2[] = {0x4D, 0x58, 0x10, 0x03, 0x42, 0x00, 0x02, 0xFC}; // 8 bytes
byte deleteFingerPrint3[] = {0x4D, 0x58, 0x10, 0x03, 0x42, 0x00, 0x03, 0xFD}; // 8 bytes
byte deleteFingerPrint4[] = {0x4D, 0x58, 0x10, 0x03, 0x42, 0x00, 0x04, 0xFE}; // 8 bytes
byte respondCorrect[] = {0x4D, 0x58, 0x30, 0x01, 0x01, 0xD7}; // 6 bytes
byte operationSuccessDelete[] = {0x4D, 0x58, 0x30, 0x02, 0x42, 0x31, 0x4A}; // 7 bytes
byte parameterErrorDelete [] = {0x4D, 0x58, 0x30, 0x02, 0x42, 0x35, 0x4E}; // 7 bytes
byte respond[6],operation[7],a,f,g;
/*******************************************************************************
* PRIVATE FUNCTION: setup()
*
* PARAMETERS:
* ~ void
*
* RETURN:
* ~ void
*
* DESCRIPTIONS:
* Define of I/O pin as Input or Output
*
*******************************************************************************/
// The setup() method runs once, when the sketch starts
void setup ()
{
// initialize serial:
Serial.begin(57600);
lcd.begin(16, 2); // set the lcd dimension
lcd.print(" CYTRON TECH."); // display the text
lcd.setCursor(0,1); // set lcd.setCursor (column,row)
lcd.print(" Eg. LCD Shield");
delay(1500); // delay for 3000ms
lcd.clear();
adc_key_old = analogRead(analogPin); // store the unpress key value
}
/*******************************************************************************
* PRIVATE FUNCTION: loop()
*
* PARAMETERS:
* ~ void
*
* RETURN:
* ~ void
*
* DESCRIPTIONS:
* Non-Stop looping
*
*******************************************************************************/
void loop()
{
lcd.setCursor(0,0);
lcd.print("Fingerprint Reader");
lcd.setCursor(0,1);
lcd.print("Select Address");
adc_key_in = analogRead(analogPin); // read ADC value
adc_key_in = get_key(adc_key_in);
if (adc_key_in==0)
{
deleteFinger0();
correctRespond();
operationSuccesful();
}
else if (adc_key_in==1)
{
deleteFinger1();
correctRespond();
operationSuccesful();
}
else if (adc_key_in==2)
{
deleteFinger2();
correctRespond();
operationSuccesful();
}
else if (adc_key_in==3)
{
deleteFinger3();
correctRespond();
operationSuccesful();
}
else if (adc_key_in==4)
{
deleteFinger4();
correctRespond();
operationSuccesful();
}
}
/*******************************************************************************
* PRIVATE FUNCTION: get_key
*
* PARAMETERS:
* ~ integer
*
* RETURN:
* ~ unsigned int input
*
* DESCRIPTIONS:
* convert the ADC value to number between 0 to 4
*
*******************************************************************************/
int get_key(unsigned int input)
{
int k;
for (k = 0; k < NUM_KEYS; k++)
{
if (input < adc_key_val[k])
{
return k;
}
}
if (k >= NUM_KEYS)
k = -1; // No valid key pressed
return k;
}
void deleteFinger0(){
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// Print a message to the LCD.
lcd.print("Del Fingerprint1");
// write the 8bytes array of the command code
Serial.write(deleteFingerPrint0, sizeof(deleteFingerPrint0));
delay(1500);
}
void deleteFinger1(){
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// Print a message to the LCD.
lcd.print("Del Fingerprint2");
// write the 8bytes array of the command code
Serial.write(deleteFingerPrint1, sizeof(deleteFingerPrint1));
delay(1500);
}
void deleteFinger2(){
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// Print a message to the LCD.
lcd.print("Del Fingerprint3");
// write the 8bytes array of the command code
Serial.write(deleteFingerPrint2, sizeof(deleteFingerPrint2));
delay(1500);
}
void deleteFinger3(){
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// Print a message to the LCD.
lcd.print("Del Fingerprint4");
// write the 8bytes array of the command code
Serial.write(deleteFingerPrint3, sizeof(deleteFingerPrint3));
delay(1500);
}
void deleteFinger4(){
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// Print a message to the LCD.
lcd.print("Del Fingerprint5");
// write the 8bytes array of the command code
Serial.write(deleteFingerPrint4, sizeof(deleteFingerPrint4));
delay(1500);
}
void correctRespond() {
// Now, reply contains all 6 bytes
for(byte x=0; x<6; x++)
{
while(Serial.available() == 0) {}; // Wait for a byte
respond[x] = Serial.read();
a = memcmp(respondCorrect, respond, sizeof(respondCorrect));
if (a==0) {
lcd.clear();
// set the cursor to column 0, line 0
lcd.setCursor(0, 0);
// Print a message to the LCD.
lcd.print("Correct Respond");
}
else {
lcd.clear();
// set the cursor to column 0, line 0
lcd.setCursor(0, 0);
// Print a message to the LCD.
lcd.print("Wrong Respond");
}
}
delay(1500);
}
void operationSuccesful () {
// Now, reply contains all 7 bytes
for(byte x=0; x<7; x++)
{
while(Serial.available() == 0) {}; // Wait for a byte
operation[x] = Serial.read();
f = memcmp(operationSuccessDelete, operation, sizeof(operationSuccessDelete));
g = memcmp(parameterErrorDelete, operation, sizeof(parameterErrorDelete));
if (f==0) {
lcd.clear();
// set the cursor to column 0, line 0
lcd.setCursor(0, 0);
// Print a message to the LCD.
lcd.print("Operation Success");
}
else if (g==0) {
lcd.clear();
// set the cursor to column 0, line 0
lcd.setCursor(0, 0);
// Print a message to the LCD.
lcd.print("Parameter Error");
}
else {
lcd.clear();
// set the cursor to column 0, line 0
lcd.setCursor(0, 0);
// Print a message to the LCD.
lcd.print("Please Restart");
}
}
delay(1500);
}
i think the value of adc_key_in can be made into for loop so that if counter 0, it will call function deleteFinger0();
Why do you have 5 nearly identical functions? One would suffice. Pass it arguments.
Perhaps you've observed that functions like digitalRead() don't have numeric suffixes.
Why do you have 5 nearly identical functions? One would suffice. Pass it arguments.
Perhaps you've observed that functions like digitalRead() don't have numeric suffixes.
in each deletefinger() function, it has it own command code need be transmitted via serial.write. perhaps if has other way, i could learn a new thing too.
in each deletefinger() function, it has it own command code need be transmitted via serial.write. perhaps if has other way, i could learn a new thing too.
You could make that a 2D array, instead. Then, one argument would be an index that would define which row to use.
Or. use a switch statement to select which array to send. But, don't write 5 functions.
You could make that a 2D array, instead. Then, one argument would be an index that would define which row to use.
Or. use a switch statement to select which array to send. But, don't write 5 functions.
2D array? i think my experience in programming is just shallow. by the way, for the switch case. i understand that one. i'm gonna try it. but, perhaps i could learn how to do 2D array.
Re: TX command code & RX respond code of module via serial com
« Reply #3 on: January 15, 2013, 11:11:51 AM »
Bigger Bigger Smaller Smaller Reset Reset Reply with quoteQuote
Code:
while(Serial.available() == 0){
delay(10);
}
Can you describe the exact purpose for the delay()? Does it matter whether the while loop iterates 10 times in 100 milliseconds, or 10,000,000?
If you know (or think/hope) that the response is going to be 6 bytes, wait for 6,
Then, of course, you still need to read all 6 of them.
He is calling it from setup(). Not from loop(). It is only going to run this function once. So he has to wait here.
because the correct command respond is 6 bytes but wrong command respond is 7 bytes. that is the reason why i put 7 sir.
Code:
byte correctRespond[] = {0x4D, 0x58, 0x30, 0x01, 0x01, 0xD7};
byte wrongrespond[] = {0x4D, 0x58, 0x30, 0x02, 0x40, 0x35, 0x4C);
This is misconceived. Any response, which is not the correct response, is the wrong response.