Transform int in byte into python

2

Hello, I need to convert an int value to byte.

I tried to do this:

import serial
ser = serial.Serial('/dev/ttyACM0', 9600)

angulo = 90

ser.write(angulo)

#while 1 :
print ser.readline()

I need to send a value to the Arduino, at first, it only accepts byte. Thanks!

    
asked by anonymous 30.05.2017 / 01:48

1 answer

4

Only use:

valor = bytes([90])

See more here .

To convert from byte to integer, use:

int.from_bytes(meus_bytes, byteorder='big')

If big endian , and

int.from_bytes(neus_bytes, byteorder='little')

If it's little endian .

    
30.05.2017 / 01:52