Closed ethugbaby closed 3 years ago
Please include the full backtrace. It will tell us what line errors in your example code.
File "/home/pi/Desktop/uart_rftest.py", line 43, in <module>
pn532 = PN532_UART(uart, debug=False)
File "/usr/local/lib/python3.7/dist-packages/adafruit_pn532/uart.py", line 55, in __init__
super().__init__(debug=debug, reset=reset)
File "/usr/local/lib/python3.7/dist-packages/adafruit_pn532/adafruit_pn532.py", line 195, in __init__
self._wakeup()
File "/usr/local/lib/python3.7/dist-packages/adafruit_pn532/uart.py", line 60, in _wakeup
self.SAM_configuration()
File "/usr/local/lib/python3.7/dist-packages/adafruit_pn532/adafruit_pn532.py", line 363, in SAM_configuration
self.call_function(_COMMAND_SAMCONFIGURATION, params=[0x01, 0x14, 0x01])
File "/usr/local/lib/python3.7/dist-packages/adafruit_pn532/adafruit_pn532.py", line 296, in call_function
if not self.send_command(command, params=params, timeout=timeout):
File "/usr/local/lib/python3.7/dist-packages/adafruit_pn532/adafruit_pn532.py", line 317, in send_command
self._write_frame(data)
File "/usr/local/lib/python3.7/dist-packages/adafruit_pn532/adafruit_pn532.py", line 249, in _write_frame
self._write_data(bytes(frame))
File "/usr/local/lib/python3.7/dist-packages/adafruit_pn532/uart.py", line 85, in _write_data
"\x55\x55\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 532, in write
d = to_bytes(data)
File "/usr/lib/python3/dist-packages/serial/serialutil.py", line 63, in to_bytes
raise TypeError('unicode strings are not supported, please encode to bytes: {!r}'.format(seq))
TypeError: unicode strings are not supported, please encode to bytes: 'UU\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'```
ok im kind of a noob but how does adding low power state fix this and how do i implement it
@ethugbaby It was something that I fixed while adding the low power code. The two aren't related but it just so happens to be in that pull request.
You could download the code from my fork, and use that temporarily, until the pull request is merged in order to get it working. Or for that specific error, if you change the string from Line 85
in uart.py
from a regular string to a bytestring that should also fix it.
So instead of this: (uart.py - Line 85
)
"\x55\x55\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
It should be this:
b"\x55\x55\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
There were some other problems with the uart code from the current version. Changing this line will fix the error you're getting but I don't remember if any other change was needed to get the code working. The pull request I made is being tested so hopefully it won't be too long before this is all fixed!
thank you so much sorry for the waste of time to help me!!
No worries @ethugbaby, I'm glad I was able to help you! If you run into any other problems feel free to open another issue!
i am trying to read nfc using a raspi 4b i have pn532 connected through uart
i keep getting this error
TypeError: unicode strings are not supported, please encode to bytes: 'UU\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'