0
from machine import Pin, I2C, UART
import utime
from ustruct import unpack
import time

checkCardCmd = bytes([0xff,0x00,0x01,0x83,0x84])
getFirmwareVersionCmd = bytes([0xff,0x00,0x01,0x81,0x82])

uart = UART(1, baudrate=19200, bits=8, parity=None, stop=1)

while True:
    # Check if card is present
    uart.write(checkCardCmd)
    val = uart.read()
    print(val)

    utime.sleep_ms(250)

When a card is presented on the NFC reader I get this back from val b'\xff\x00\x06\x83\x02\x01#Eg['

This is the reply to the checkCardCmd. I have no clue why it ends with #Eg[ also the reply for no card found comes back as b'\xff\x00\x02\x83N\xd3' notice the N character on the 4th byte, that should just be x83.

Baud Rate is correct and with similar code in NodeJS I get the proper response from UART without the extra N or #Eg]

What am I missing here?

Bento
  • 725
  • 2
  • 8
  • 22
  • 2
    Your device is responding with raw binary bytes. Those are being stored in a string. Where a byte corresponds to a printable ASCII character, that character is being printed. Where the byte does not correspond to an ASCII character, or corresponds to an unprintable one, the `\xnn` syntax is used. `#` is simply the same as `\x23`, i.e. `0x23`. `N` in ASCII is `0x4E`. `#Eg[` is the byte sequence `0x23 0x45 0x67 0x5B` – canton7 Jun 19 '21 at 20:32
  • 1
    @canton7 Oh jesus I didn't even think of that. Thanks! Problem solved and I got the correct output from the reader now :-) – Bento Jun 19 '21 at 21:30

0 Answers0