0

I have a program on my Arduino Due that receives lists of data, parsed by one of this solutions https://forum.arduino.cc/t/serial-input-basics-updated/382007 and it is working fine!

I am sending this data from my Raspberry Pi via UART. In the first column of the list is the topic, that the Arduino knows, what the datas are for. So I send a list and the first column is the topic, the rest (undefined length) are integers. Here is my mini example:

import serial

ser = serial.Serial(
        port='/dev/ttyS0', 
        baudrate = 9600,
        timeout=1
)

new_list = [b"topic"]

for i in range(10):
    new_list.append(i)

def sendData(data):
    ser.write(data)
    
sendData(new_list)

But now I get the Error "TypeError: 'bytes' object cannot be interpreted as an integer" and I don't know how to fix it. I've tried already many ways of encoding but then I just get others errors.

In the time from when it worked until now I've replaced the memory of my Raspberry Pi with new Raspbian OS, maybe a package is missing?

Full error traceback:

Traceback (most recent call last):
  File "/media/local/2E32-36C4/test.py", line 17, in <module>
    sendData(new_list)
  File "/media/local/2E32-36C4/test.py", line 15, in sendData
    ser.write(data)
  File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 598, in write
    d = to_bytes(data)
  File "/usr/lib/python3/dist-packages/serial/serialutil.py", line 68, in to_bytes
    return bytes(bytearray(seq))
TypeError: 'bytes' object cannot be interpreted as an integer
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
AndrewFFL
  • 37
  • 5
  • 1
    Please show the full error traceback. – mkrieger1 May 28 '22 at 16:24
  • Does this answer your question? [TypeError: 'bytearray' object cannot be interpreted as an integer](https://stackoverflow.com/questions/59110653/typeerror-bytearray-object-cannot-be-interpreted-as-an-integer) PS: it's the first result when googling for your eror. – TDG May 28 '22 at 16:39
  • Which of the solutions in the link are you referring to? When you want to send data did you mean a string like this: `“”`? – quamrana May 28 '22 at 16:42
  • 1
    Can you show which bytes you want to send in this example? – mkrieger1 May 28 '22 at 16:50
  • Unfortunately this wasn't successful for me. The reason why I've tried to convert the text to a byte was because I've hoped it might solve the issue, but it doesn't. @quamrana, in the end at the Arduino I received at the last time the following: ["text", 1,2,3,...] and used the [ as start end ] as end marker. – AndrewFFL May 28 '22 at 18:03
  • So did you mean: `ser.write(str(data).encode('utf-8'))`? – quamrana May 28 '22 at 18:39
  • @quamrana, many thanks! This solved the issue! :) – AndrewFFL May 29 '22 at 09:04

0 Answers0