I'm trying to write a simple Python script to print RFID tag numbers to the terminal. Code example below. Using a Pi 2 Model B, with the reader here attached via USB.

I'm having difficulties understanding the output from the RFID reader. When displaying 15 characters, as in the example code above, consecutive reads of the same tag yield this output including line breaks (includes unicode start-of-text and end-of-text characters as [STX] and [ETX]):

  1. Are these start & end-of-text characters distinct from "stop bits"? I'm unsure of why I'm not reading the end-of-text character on the first read, but all subsequent reads pick it up.

  2. Any insight on the timing of line breaks?


import serial

device = serial.Serial("/dev/ttyUSB0", 9600, 8, "N", 1)

while True:
    tag_id = device.read(15)
    print tag_id

1 Answer 1


There appear to be 14 characters not 15. The datasheet says there should be 16 but the CR and LF do not appear to be present. So try reading 14 rather than 15 characters.

EOT and SOT are ASCII characters with the values 2 and 3. Look at an ASCII chart to get the idea. They are distinct from the stop bit. Each ASCII character is sent as 8N1 (as defined in the datasheet) which means one start bit, 8 data bits, and 1 stop bit. The hardware converts the bits to characters so your software has no visibilty of the start and stop bits.

If you want a robust solution to reading the data you should be reading character by character to accumulate the data between the SOT and EOT. Just reading x characters at a time falls over as soon as there is a lost byte or if the read starts mid data transmission.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.