建立串行通信b / t Beaglebone Black(RevC,Deb)和Arduino Mega

时间:2016-03-14 20:25:41

标签: python arduino cloud9-ide beagleboneblack

我正在尝试在Beaglebone Black和Arduino Mega之间建立串行通信,但是我遇到了问题,特别是在Beagle方面。我不断收到此错误消息:

Traceback (most recent call last):
  File "/var/lib/cloud9/IBID 2.0 /data stream test (1).py", line 35, in <module>
    sensorValue += ser.read('UART1') #add more for more pins
  File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 449, in read
    buf = os.read(self.fd, size-len(read))
TypeError: unsupported operand type(s) for -: 'str' and 'int'

响应尝试运行此代码:

import Adafruit_BBIO.UART as UART
import serial

UART.setup('UART1')

name = raw_input('name your file: ')
final_name = os.path.join(/sequence of files and folders/, name + '.txt')
data = open(name + '.txt', 'a+')

ser = serial.Serial(port = "/dev/ttyO1", baudrate=9600, timeout = 1000)

sensorValue = 0
header = 'Sensor 1 output'
data.write(str(header))
data.write(str('\n'))
while True:
    ser.open()
    sensorValue += ser.read('UART1')
    data.write(sensorValue)

我正在使用cloud 9 IDE对Beaglebone进行编程,以便从连接到Arduino的传感器(通过逻辑转换器)接收传入数据。至少可以说错误代码让我感到困惑。它提供的链接不会引导我在IDE中找到任何东西(没有找到文件)。我找不到[关于如何解决此错误。]

1 个答案:

答案 0 :(得分:1)

在这一行

sensorValue += ser.read('UART1')

您正在调用序列为str的serial.Serial.read(size = 1)作为参数。该方法需要int