python - Arduino Serial programming issue -


i'm sending integer python using pyserial.

import serial ser = serial.serial('/dev/cu.usbmodem1421', 9600); ser.write(b'5'); 

when compile,the receiver led on arduino blinks.however want cross check if integer received arduino. cannot use serial.println() because port busy. cannot run serial monitor first on arduino , run python script because port busy. how can achieve this?

you listen arduino's reply additional code.

import serial ser = serial.serial('/dev/cu.usbmodem1421', 9600); # timeout after second  while ser.isopen():     try:         ser.write(b'5');         while not ser.inwaiting():  # wait till something's received             pass         print(str(ser.read(), encoding='ascii'))  #decode , print     except keyboardinterrupt:  # close port ctrl+c         ser.close() 

use serial.print() print arduino receives serial port, python code listening.


Comments

Popular posts from this blog

ios - Memory not freeing up after popping viewcontroller using ARC -

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -