How to use HW and SW serial ata time.

Hello All,

My self Suresh kumar.

I was try to interface R305 finger print sensor with my UNO.
I want to send this through serial---> EF 01 FF FF FF FF 01 00 07 13 00 00 00 00 00 1B.
And My finger print module suddenly response<------EF 01 FF FF FF FF 07 00 03 00 00 0A.

Finger print module connected with 2,3 pin(software serial).
I can send the above data through HW serial.

Now How to read ?.

I tried like this

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2,3); //RX,TX Respectivly

void setup() {
Serial.begin(57600); // Arduino Serial monitor
mySerial.begin(57600); //R305 connected
delay(1000);
mySerial.write(0xEF);
mySerial.write(0x01);
mySerial.write(0xFF);
mySerial.write(0xFF);
mySerial.write(0xFF);
mySerial.write(0xFF);
mySerial.write(0x01);
mySerial.write(0x00);
mySerial.write(0x07);
mySerial.write(0x13);
mySerial.write(0x00);
mySerial.write(0x00);
mySerial.write(0x00);
mySerial.write(0x00);
mySerial.write(0x00);
mySerial.write(0x1B);
if(mySerial.available()){
Serial.write(mySerial.read());
}
}

void loop() {
}

But I did not any response on my serial window.
And I got error message while I try to use this 0x00,0x0.

I do manually using CP2102 usb-ttl. I got response from my module.

Help me.

Thanks and Regards
Sureshkumar.

You need to put the last 3 lines of your setup() in the loop() (the IF statement)

At the moment you send the commands and listens instantly for the answer and it probably did not get a chance to arrive, and then you exit the setup() and do nothing;

So what you want to to is - IN THE LOOP - check if something is coming from software serial and if so print it to Serial and then loop again to get the next byte etc. This way it will work.

Thank you very much for replying J-M-L.

I tried but I did not get any response.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2,3); //RX,TX Respectivly

void setup() {
 Serial.begin(57600); // Arduino Serial monitor
 mySerial.begin(57600); //R305 connected
 delay(1000);
 mySerial.write(0xEF);
 mySerial.write(0x01);
 mySerial.write(0xFF);
 mySerial.write(0xFF);
 mySerial.write(0xFF);
 mySerial.write(0xFF);
 mySerial.write(0x01);
 //mySerial.write(0x00);
 mySerial.write(0x07);
 mySerial.write(0x13);
//  sS.write(0x00);
//  sS.write(0x00);
//  sS.write(0x00);
//  sS.write(0x00);
//  sS.write(0x00);
 mySerial.write(0x1B);
}

void loop() {
 while(mySerial.available()>0){
   Serial.write(mySerial.read());
 }
}

What is the problem ?.

I am tried if also and while also. but I no response in my arduino serial also doclight serial window also. I want read the finger module response and write it to my serial window.

where are pins 2 and 3 connected? (Should be RX to device TX and TX to device RX) and how is the device powered? do you have joining grounds? Are you sure it's communicating at 57600? Are you sure about bit parity, stop bit etc ? Are you sure your device is a 5V device for serial com?

Is your console opened at 57600?

Now I got response from my module.

HW serial pins for serial monitor.
SW serial pins for interface with R305 Finger print module.

R305 operating volt is 5 volt and current is 100mA.

Finger print module(R305)________UNO(Original)

5v---->5v

gnd--->gnd

tx----->pin10(rx)

rx<-----pin11(tx)

Module default Baud rate is 56700.(confirmed).

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX

int task = 0,i = 0;
byte total[12];
byte collect[] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x03,0x01,0x00,0x05};//12
byte char1[] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x04,0x02,0x01,0x00,0x08};//13
byte char2[] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x04,0x02,0x02,0x00,0x09};//13
byte gentmplt[] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x03,0x05,0x00,0x09};//12
byte strtmplt[] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x06,0x06,0x01,0x00,0x00,0x00,0x0E};//15

//byte dlttmplt[] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x07,0x0C,0x00,0x01,0x00,0x01,0x00,0x16};
//byte srchtmplt[] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x08,0x04,0x01,0x00,0x00,0xFF,0xFF,0x02,0x0C};
void setup(){
  Serial.begin(57600);
  mySerial.begin(57600);
  delay(1000);
}

void loop(){
  if(task==0){
  mySerial.write(collect, sizeof(collect));
  for (i=0; i<12; i++){
    while(!mySerial.available());
    int incomingByte = mySerial.read();
    Serial.print(incomingByte,HEX);
    Serial.print(" ");
    Serial.print();
  }
  }
}

How to display the 0x00 hex value on serial monitor.

This is actual response from my module.

EF 01 FF FF FF FF 07 00 03 00 00 0A

But I got like this

EF 1 FF FF FF FF 7 3 A.

I need to display 0 also.

Don't expect SoftwareSerial to work at 57600 baud. Get it working at 9600 baud and then experiment with higher speeds.

...R

I need to display 0 also.

Why? The leading 0 add NO benefit.

But, if you just absolutely insist, if the value is less than 16, print a 0 with no space, then the value, then the space.

Thanks for J-M-L, Robin2, And PaulS.

Ok Robin JI. I am going to use SW Serial in 9600 baud rate.

Ok PaulS JI. If I send this series bytes like 0xFF 0xAB 0x0C 0x00 0xE4 total lebgth 5 bytes our arduino send like this

0xFF 0xAB 0xC 0xE4 so total 3 bytes and 0xC has only 4 bits.

Ok you said 0x00 does not affect the length. i am right ?

You mean

0xFF 0xAB 0x0C 0x00 0xE4 = 0xFF 0xAB 0xC 0xE4.

Thank you JI. but in programming how to calculate the length. if these kind of problem ?.

Thank You all guys for remote teaching.

Serial.print simply leaves the leading zeroes. What @PaulsS is saying is to change

    Serial.print(incomingByte,HEX);

to

    // if single 'digit'
    if( incomingByte < 0x10)
    {
      // add leading 0
      Serial.print(0);
    }
    Serial.print(incomingByte,HEX);

Thank you sterretje JI.

Ok. I understand that. Our arduino only show without leading 0x an 0x00, But My question is I want to send the series data to my finger print module.

like this

EF 01 FF FF FF FF 01 00 04 02 01 00 08 it has some zeros. total length is 13 bytes. If I send through serial the total length(13 bytes) is gone into my module or the zeros are ignored by compiler ?.

EF 01 FF FF FF FF 01 00 04 02 01 00 08== EF 1 FF FF FF FF 1 4 2 1 8.

Your fingerprint reader almost certainly does NOT expect the data as ASCII data. It almost certainly expects you to send it 13 bytes using Serial.write().

In your #1 message you said

SureshKumar2610:
I do manually using CP2102 usb-ttl. I got response from my module.

were you sending bytes or ASCII representation of the bytes to get it to answer?

I try to send these 13 bytes through SW serial(tx) to my R305 finger print module. module respond if the data is correct through SW serial(rx) from my module.

I try to send these 13 bytes through SW serial(tx) to my R305 finger print module. module respond if the data is correct through SW serial(rx) from my module.

Is that an answer to my question in #11?

J-M-L Ji. Thanks for reply.

I cant understand what you asked.

Can or cannot ?

I'm asking what did you send to know it was working ASCII letters or bytes?

I am sending bytes like these 0xEF 0x01. If can I send same equivalent ASCII ?. I did not send

If the module expects bytes in raw format then don't send ascii
If the module answers with raw bytes, then read raw bytes
If you want to print the raw bytes in hexadecimal ASCII then use print(value, HEX);. Yes as you have noticed it does not print the leading 0 if the value is less than 16. For example 15 would be printed as F, not 0F - that is just a screen representation of the byte's value

What is really your question?

J-M-L JI

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX

int i=0;
int task=0;

uint8_t ctotal[]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}; // Reply bytes all are 12 bytes

uint8_t collect[] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x03,0x01,0x00,0x05};//12
uint8_t char1[] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x04,0x02,0x01,0x00,0x08};//13
uint8_t char2[] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x04,0x02,0x02,0x00,0x09};//13
uint8_t gentmplt[] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x03,0x05,0x00,0x09};//12
uint8_t strtmplt[] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x06,0x06,0x01,0x00,0x00,0x00,0x0E};//15

//byte dlttmplt[] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x07,0x0C,0x00,0x01,0x00,0x01,0x00,0x16};
//byte srchtmplt[] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x08,0x04,0x01,0x00,0x00,0xFF,0xFF,0x02,0x0C};

void setup(){
  Serial.begin(9600);
  mySerial.begin(9600);
  delay(500);
}

void loop(){
   switch (task){
    case 0: finger1();
    break;
    case 1: character1();
    break;
    case 2: finger2();
    break;
    case 3: character2();
    break;
    case 4: generate();
    break;
    case 5: store();
    break;
    case 6: Serial.println("Template Stored"); task =7;
   }
}

int finger1(){
  if(task==0){
    mySerial.write(collect, sizeof(collect));
    for (i=0; i<12; i++){
      while(!mySerial.available());
      uint8_t incomingByte = mySerial.read();
      Serial.print(incomingByte,HEX);
      ctotal[i]=incomingByte;
      Serial.print(" ");
    }
    Serial.println();
   if(ctotal[9]==0x00){
    task=1;
    i=0;
    ctotal[9]=0xBB;
    Serial.println();
    Serial.println("Finger 1 Sucess");
   }
   return task;
  }
}

int character1(){
    mySerial.write(char1, sizeof(char1));
    for (i=0; i<12; i++){
      while(!mySerial.available());
      uint8_t incomingByte = mySerial.read();
      Serial.print(incomingByte,HEX);
      ctotal[i]=incomingByte;
      Serial.print(" ");
    }
    Serial.println();
   if(ctotal[9]==0x00){
    task=2;
    i=0;
    ctotal[9]=0xBB;
    Serial.println();
    Serial.println("Char 1 Sucess");
   }
   return task;
}

int finger2(){
    mySerial.write(collect, sizeof(collect));
    for (i=0; i<12; i++){
      while(!mySerial.available());
      uint8_t incomingByte = mySerial.read();
      Serial.print(incomingByte,HEX);
      ctotal[i]=incomingByte;
      Serial.print(" ");
    }
    Serial.println();
   if(ctotal[9]==0x00){
    task=3;
    i=0;
    ctotal[9]=0xBB;
    Serial.println();
    Serial.println("Finger 2 Sucess");
   }
   return task;
}

int character2(){
    mySerial.write(char2, sizeof(char2));
    for (i=0; i<12; i++){
      while(!mySerial.available());
      uint8_t incomingByte = mySerial.read();
      Serial.print(incomingByte,HEX);
      ctotal[i]=incomingByte;
      Serial.print(" ");
    }
    Serial.println();
   if(ctotal[9]==0x00){
    task=4;
    i=0;
    ctotal[9]=0xBB;
    Serial.println();
    Serial.println("Char 2 Sucess");
   }
   return task;
}


int generate(){
    mySerial.write(gentmplt, sizeof(gentmplt));
    for (i=0; i<12; i++){
      while(!mySerial.available());
      uint8_t incomingByte = mySerial.read();
      Serial.print(incomingByte,HEX);
      ctotal[i]=incomingByte;
      Serial.print(" ");
    }
    Serial.println();
   if(ctotal[9]==0x00){
    task=5;
    i=0;
    ctotal[9]=0xBB;
    Serial.println();
    Serial.println("Template Sucess");
   }
   return task;
}

int store(){
    mySerial.write(strtmplt, sizeof(strtmplt));
    for (i=0; i<12; i++){
      while(!mySerial.available());
      uint8_t incomingByte = mySerial.read();
      Serial.print(incomingByte,HEX);
      ctotal[i]=incomingByte;
      Serial.print(" ");
    }
    Serial.println();
   if(ctotal[9]==0x00){
    task=6;
    i=0;
    ctotal[9]=0xBB;
    Serial.println();
    Serial.println("Stored Sucess");
   }
   return task;
}

Finally I get clarified you replied people. thanks for the help.

This is my code now My code is send the data and receive it back from finger print module. But I expect 0x00 format.

I Said Thanks to all the helping mind programmers. I am also embedded engineer. I am using Microchip PIC devices. Some simple tasks only I am using Arduino and discontinued to use the Arduino So I forgot everything. That is the problem.

Now I am started to use this Arduino only. C++ . Also I would like to create Arduino Libraries. Finally I am also helping to other beginners like you peoples.

Thanks a lot you people.

J-M-L JI. Robin2 JI, PaulS JI, sterretje JI.