I want to send a message from Rpi to Atmega328 via UART and there must be only 8 bit message (address, address, direction, number of steps [5 bits]).
import RPi.GPIO as GPIO
import serial
import time,sys
var=0b11110000
SERIAL_PORT = "/dev/ttyS0"
ser=serial.Serial(SERIAL_PORT,baudrate=9600,parity=serial.PARITY_NONE,stopbits=serial.STOPBITS_ONE,bytesize=serial.EIGHTBITS)
time.sleep(1)
print("Sending")
ser.write(var)
ser.close()
But i got this
Sending
Traceback (most recent call last):
File "UART_2.py", line 11, in <module>
ser.write(var)
File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 558, in write
return len(data)
TypeError: object of type 'int' has no len()
What should I do to send it correctly?