That is the not the right way to read an Integer
from Arduino. Integer
is a 32-bit type while your serial port would be set to EIGHTBITS (Both in pyserial and Arduino. Correct me if I'm wrong) in byte size, therefore you have to write the Character
version of the Integer
from Arduino while transmitting it through a Serial Port because a Character
takes only EIGHTBITS in size which is also the convenient way to do the stuff that you need to, very easily.
Long story short, convert your Integer
into a String
or a Character
Array before transmitting. (Chances are there are inbuilt functions available for the conversion).
On a side note here is the correct python code that you'd prefer to use:
ser = serial.Serial(
port='COM3',
baudrate=9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS
)
ser.isOpen()
while 1:
out = ''
while ser.inWaiting() > 0:
out += ser.read(1)
if out != '':
print ">>Received String: %s" % out
integer
take? What's its type exactly? Could it be you're passing such bytes that may be interpreted as non-printable ASCII or space? – Ilja Everilä