Fingerprint scanner, how get HEX output to send to it?

I've got this fingerprint scanner from sparkfun
https://learn.sparkfun.com/tutorials/fingerprint-scanner-gt-521fxx-hookup-guide/all#example-code-for-arduino
and I'm trying to write my own code to send it commands

// sketch to send fingerprint scanner commands
// take in 5 words big endian, add up bytes for word checksum (not currently working, entering checksum also
// (simple summing of the individual byte, saved as word)
// send out 6 words little endian (swap bytes)

#include <SoftwareSerial.h>
SoftwareSerial mySerial(4, 5); // (Arduino SS_RX = pin 4, Arduino SS_TX = pin 5)

byte incomingCommand[24]; // from Serial
byte outgoingCommand[24]; // to device
unsigned int outgoingWords[12];
unsigned int x;
byte newByte;

void setup() {
  Serial.begin(115200);
  mySerial.begin(9600);
  Serial.println ("ready (.s are for entry readability only)");
}

void loop() {
  if (Serial.available() > 23 ) { // read in big endian words, 5 words + checksum word
    for (x = 0; x < 24; ++x) {
      newByte = Serial.read();
      if (newByte <= '9') { // 48 to 57 = 0 to 9
        newByte = newByte - '0';
      }
      if (newByte >= 'A') { // 65 to 70 = A to F
        newByte = newByte + 10 - 'A';
      }
      incomingCommand[x] = newByte;
    }

    Serial.print("inCommand + checksum: ");
    for (x = 0; x < 24; ++x) {
      Serial.print (incomingCommand[x], HEX); // display them
      if ((x & 0x01) == 1) {
        Serial.print (".");
      }
    }
    Serial.println("");

    for (x = 0; x < 6; ++x) { // swap the words
      outgoingCommand[(x * 4) + 0] = incomingCommand[(x * 4) + 2];
      outgoingCommand[(x * 4) + 1] = incomingCommand[(x * 4) + 3];
      outgoingCommand[(x * 4) + 2] = incomingCommand[(x * 4) + 0];
      outgoingCommand[(x * 4) + 3] = incomingCommand[(x * 4) + 1];
    }
    Serial.print ("to device:            ");
    for (x = 0; x < 24; ++x) {
      Serial.print (outgoingCommand[x], HEX);
      if ((x & 0x01) == 1) {
        Serial.print (".");
      }
      mySerial.write (outgoingCommand[x]);
    }
    Serial.println("");
    Serial.println("from device");
  }

  if (mySerial.available() > 0) {
    Serial.print ("got ");
    Serial.print (mySerial.read() );
  }
}

Supposedly this code will "open", and send it the command to turn the LED on and off.
The messages are little endian, I am entering the message as big endian as that is what the document describes, and then converting it. Also makes it easier to follow.
I can enter AA5500010000000000010101
and confirm it puts that in the incomingCommand array as 24 bytes,
then swap the words in the outgoingCommand array as 24 bytes.

It seems to me that each byte now represents one nibble of a byte to be sent out to make up 12 bytes, and I can't figure out how to combine them to do that. I'm pretty sure what I am doing is not correct as I never get a reply from the unit. If I run the Blink example using the FPS_GT511C3.h library the module works.

Examples given:
FPS - Open
FPS - SEND: "55 AA 01 00 00 00 00 00 01 00 01 01"
FPS - RECV: "55 AA 01 00 00 00 00 00 30 00 30 01"

FPS - LED on
FPS - SEND: "55 AA 01 00 01 00 00 00 12 00 13 01"
FPS - RECV: "55 AA 01 00 00 00 00 00 30 00 30 01"

FPS - LED off
FPS - SEND: "55 AA 01 00 00 00 00 00 12 00 12 01"
FPS - RECV: "55 AA 01 00 00 00 00 00 30 00 30 01"

What I am seeing on the serial monitor

ready (.s are for entry readability only)
inCommand + checksum: AA.55.00.01.00.00.00.00.00.01.01.01.
to device:            55.AA.01.00.00.00.00.00.01.00.01.01.
from device
inCommand + checksum: AA.55.00.01.00.00.00.00.00.01.01.01.
to device:            55.AA.01.00.00.00.00.00.01.00.01.01.
from device

What I think I need to end up with
0x55AA (or 0x55 and 0xAA)
0x0001
0x0000
0x0000
0x0001
0x0101

How do I make the code do that?
Thanks

FPS_Blink.ino (3.81 KB)

FPS_GT511C3.h (13.9 KB)

Bump ...

It looks like only multibyte fields in the packet are little endian, which means I think that you will need to keep some data that tells you the packet format including offset and length. Then you'll need to work through the packet using what you know about the format and flipping bytes as needed.

To make matters worse, it looks like command and data packets are different.

Ok, I can do that.
How do I combine the characters 5 and 5 into the byte 0x55? I think that is what I am missing.

You know what, last night I tried

outgoingCommand[x] = (incomingCommand[x] << 8) + incomingCommand [x];

I'm thinking maybe I should have just shifted 4 bits before combining.
Will try it again when MrsCrossRoads gets done playing withe scanner on a RPi.

CrossRoads:
Ok, I can do that.
How do I combine the characters 5 and 5 into the byte 0x55? I think that is what I am missing.

You know what, last night I tried

outgoingCommand[x] = (incomingCommand[x] << 8) + incomingCommand [x];

I'm thinking maybe I should have just shifted 4 bits before combining.
Will try it again when MrsCrossRoads gets done playing withe scanner on a RPi.

Nearly. You're trying to combine nibbles though so try this:

byte incomingText[24]; // from Serial
byte outgoingbytes[12]; // to device

for(int lp=0;lp<12;lp++)
  {
  outgoingbytes[lp]=incomingText[lp*2]*16 + incomingText[lp*2+1];
  }

Got it:

for (x = 0; x < 12; x = x + 1) {
      outgoingArray[x] = (outgoingCommand[x * 2] << 4) + (outgoingCommand[(x * 2) + 1] & 0x0f);
      Serial.print (outgoingArray[x], HEX);
      mySerial.write (outgoingArray[x]);
    }

and finally a response!
(after some incoming HEX to ascii manipulation)
(and ignoring the serial monitor dropping leading 0s on bytes)

ready (.s are for entry readability only)
inCommand + checksum: AA.55.00.01.00.00.00.00.00.01.01.01.
to device:            55.AA.01.00.00.00.00.00.01.00.01.01.55AA1000001011
from device:  55AA100000300301inCommand + checksum: AA.55.00.01.00.01.00.00.00.12.01.13.
to device:            55.AA.01.00.01.00.00.00.12.00.13.01.55AA101000120131
from device:  55AA100000300301inCommand + checksum: AA.55.00.01.00.00.00.00.00.12.01.12.
to device:            55.AA.01.00.00.00.00.00.12.00.12.01.55AA100000120121
from device:  55AA100000300301

Turns on the scanner, lights the LED, turns off the LED.
On to better commands!