I am having issues communicatong to UART1 of my Beaglebone Black with python
My code on Python3 is as follows:
import Adafruit_BBIO.ADC as ADC
import Adafruit_BBIO.GPIO as GPIO
from time import sleep
import Adafruit_BBIO.UART as UART
import serial
ser = serial.Serial(port = "/dev/ttyO1", baudrate=9600)
print("Open")
ser.write(("Hello").encode)
print("message sent")
ser.read()
However, the beaglebone is sending me back:
Open
Traceback (most recent call last):
File "GPIO60.py", line 14, in ser.write(("Hello").encode) File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 518, in write d = to_bytes(data)
File "/usr/lib/python3/dist-packages/serial/serialutil.py", line 66, in to_bytes return (bytes(bytearray(seq)))
TypeError: 'builtin_function_or_method' object is not iterable
I have searched solutions for this type of error but have found nothing.
Any help would be appreciated! Thanks
-
\$\begingroup\$ You mean: /dev/tty<zero>1 "/dev/tty01"? Also as a general rule of thumb, unless you know what is going on, I avoid serial ports 1-4, as they are often used on the motherboard for inter-device communication. \$\endgroup\$Chris Knudsen– Chris Knudsen2020年10月21日 14:46:23 +00:00Commented Oct 21, 2020 at 14:46
-
\$\begingroup\$ No /dev/ttyO1 which is also /dev/ttyS1. I can communicate using the minicom but I want to do so with python. I am doing a project, but using this just to test if it works \$\endgroup\$Thomas CONNELL– Thomas CONNELL2020年10月21日 14:52:14 +00:00Commented Oct 21, 2020 at 14:52
-
\$\begingroup\$ I’m voting to close this question because it is a python syntax error which belongs on Stackoverflow not EESE \$\endgroup\$Chris Stratton– Chris Stratton2020年10月21日 15:14:46 +00:00Commented Oct 21, 2020 at 15:14
1 Answer 1
Your error message is a pure python programming problem, which means the question doesn't really belong on EESE but rather Stackoverflow, however for sake of efficiency an answer here will migrate with the question.
ser.write(("Hello").encode)
This is invalid python. There is no such thing as .encode
rather you need the method .encode()
if you want the default encoding, or to pass a specific encoding as an argument if you want some other.
ser.write(("Hello").encode()) #UTF-8 which is probably not what you want
or mabye
ser.write(("Hello").encode('iso-8859-1')) #a legacy friendly encoding
Also you probably don't want to both import the Adafruit UART code and use pyserial on the Linux device. For a given UART, you'll need to be consistent in how you work with it.
-
\$\begingroup\$ ok sorry for disturbing, i am new here so i don't know how it works, thanks anyway \$\endgroup\$Thomas CONNELL– Thomas CONNELL2020年10月21日 15:18:34 +00:00Commented Oct 21, 2020 at 15:18