boktor
boktor

Reputation: 35

Establishing Serial Communication b/t Beaglebone Black (RevC, Deb) and Arduino Mega

I'm trying to establish serial communications between a Beaglebone Black and Arduino Mega, but I'm having issues getting this to work, particularly on the Beagle's side. I keep getting this error message:

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'

in response to trying to run this code:

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)

I'm using the cloud 9 IDE to program the Beaglebone to receive incoming data from a sensor hooked up to the Arduino (via logic converter.) The error code is mystifying me, to say the least. The links it provides aren't leading me to anything (no files found) in the IDE. I haven't been able to find much [on how to resolve this error.]

Upvotes: 0

Views: 366

Answers (1)

pholtz
pholtz

Reputation: 474

On this line

sensorValue += ser.read('UART1')

you are calling serial.Serial.read(size=1) with type str as an argument. The method takes an int.

Upvotes: 1

Related Questions