Unable to read HEX values via RX/TX

Hello comunity,
sorry for my english. This is not my primary language and i like to ask much people as possible.

I have a RFID-reader that reads special TAGS and send them via an onboard-RS232 interface.
if i try to read the output with a usual Terminal i only get random characters. If i read the output with a program like hterm and set it to HEX i can see the correct hexvalues.
the Boad sends the Data like:

i know the Start Hexvalues:
0x10 and 0x02
and the End Hexvalues:
0x10 and 0x3
and i like to get the Data inbetween.

i have a Pro-Micro to send the gathered Data as a Keyboardoutput to the computer.
i like to convert the DATA that i receved to a unsigned integer (a number).

But my simple testcode do not show me the results i like to see.

#include "Keyboard.h";

String readString;
String output = "";
bool available = false;
int length = 30;
int wartezeit = 3000;

void setup() {
  Serial1.begin(19200);
  //Serial.begin(19200); // for debuging
  Keyboard.begin();
  delay(wartezeit);
}

void loop() {

  if (Serial1.available())
  {
    
    for(int i = 0 ; i < length ; i++)
    {
      delay(10);
      readString = readString + Serial1.read();
    }
    available = true;
  }

  if (available == true)
  {

    output = readString;
    Keyboard.println(output);
    readString="";
   
    available = false;
  }
}

i get the output:
10325422432264210020239540ß1ß1ß1ß1ß1ß1ß1ß1ß1ß1ß1ß1ß1ß1ß1ß1ß1ß1ß1

but i like to see this (this is what i see with “hterm”):
10 02 00 FF 20 00 07 B5 13 CD 10 03 B2

i think i dont realy know how to read the data the correct way.

can someone help me out with this?
im not a good coder. :confused:

thank you and… stay healty!!!

Have a look at Robin’s tutorial on Serial Input Basics here.

Pay particular attention to his Example #3 in reply #1.

As a start, change startMarker and endMarker to match your STX and ETX characters (ASCII codes 02 and 03). You will need to further parse your data to skip past “” and “”.

Are you sure that the checksum comes after ETX?

Hi Markd833,

thank you for your reply.

Yes the Checksum is send @ last. I get the datalayout from the manufaktuer.
The data i in HEX, not in ASCII
it looks this way:
10 02 00 FF 20 00 07 B5 13 CD 10 03 B2

i need the red data.
the Problem is, that iam unable to read and show the Data correct.
if i use Serial.print(Serial.read,HEX)
i get different hexvalues... this confuses me. not that ones i get with hterm in HEX-mode.

I still think Robin's tutorial is the way forward for you.

If the data is being sent as binary, then you should treat it as such and store it in a byte array. Storing binary data in a String is not a good idea.

Hi guys,

i have tryed to send some sample-bytes with my Pro Micro via TX RX over Serial1
to my RS232 - USB Adapter.
I send 4 Bytes:
01 10 0A A0

and in HTerm i receved:
7F 07 3D 01

whats goint on here? i think the Pro Micros have some general problems with the Serialcomunication. :o

ExampleCode:

byte sendbyte[] = {0x01, 0x10, 0x0a, 0xa0};
int lenght = sizeof(sendbyte);

void setup() {
  Serial1.begin(19200);
}

void loop()
{
  delay(2000);
  for (int i = 0; i < lenght; i++)
  {
    delay(20);
    Serial1.write(sendbyte[i]);

  }
}

Can someone help me with this?

I may not have understood correctly how you have connected your Pro Micro to your PC.

It sounds like you have it connected as:
Pro Micro → RS232-USB Adapter → PC

If that is the case, then I think you are missing a converter. It should be something like this:
Pro Micro → RS232 Adapter → RS232-USB Adapter → PC

But then again, maybe i’ve misunderstood how you have connected things together.

Yes. i connected it:
Pro Micro -> RS232 Adapter -> RS232-USB Adapter -> PC

The Adapter reads the data from my RFID-Reader without problems.

In your picture, I can see 3 wires coming off your Pro Micro. Do those 3 wires run directly to the big 9-pin connector on the right hand side of your picture?

I assume that the large silver block in the middle of the picture with the clear cable coming out to the left is the RS-232->USB converter that you have plugged into your PC.

Yes this is correct.
and i have tested another FTDI-> USB adapter (6Wires > USB)
And this FTDI receved all the date from the Arduino correctly. This means there is a difference between the WIRES->FTDI2USB->USB
and the WIRE->RS232->ADATPER->USB

Maybe some kind of voltage difference? inverted bits?
The RFID Reader have a RS232 TTL output. is this TTL something different then regular RX-TX stuff?

here is the READER:
DORSET 665 RFID-READER

I made some other tests.

Reader > "MOXA UPORT1100" (RS232>Adapter>USB):
10 02 00 FF 20 00 07 B5 13 CD 10 03 B2 (this is what i like to get)

READER > FTDI(original from FTDI):
67 FE 02 FC F3 E2 2A 64 CA F8 F2 36 00

Reader > Arduino:
67 FE 2 F3 E2 2A 64 CA 27 36 0 (missing zeros)

Camparing FTDI & Arduino readings
67 FE 02 FC F3 E2 2A 64 CA F8 F2 36 00 FTDI
67 FE 2 F 3 E2 2A 64 CA 2736 0 Arduino

looks like the arduino is missing some bytes...
i know about the HEX-displayBug(missing leading zeros)
but whats about the other missing bytes?
Baudrate is 9600

From you latest post and the photo , it looks like you have it connected as:
Pro Micro -> RS232-USB Adapter -> PC

There is no RS232 Adapter for the Pro Mini. You need one of these in order to convert the Pro Micro serial data into RS-232 signal voltage levels. These signals can then be passed to your RS32->USB converter and on to your PC.