import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.OUT)
a=GPIO.PWM(4,50)
a.start(5)
piw = serial.Serial('/dev/ttyAMA0', 115200, timeout=1)
piw.open()
try:
while 1:
response = 'no'
response = piw.readline()
if response == 'pi':
a.ChangeDutyCycle(99)
print'ON'+response
else:
a.ChangeDutyCycle(0)
print'off'+response
except KeyboardInterrupt:
piw.close()
https://github.com/lurch/rpi-serial-console
sudo rpi-serial-console disable
關掉才能傳輸參考:
http://pyserial.sourceforge.net/shortintro.html
https://mail.python.org/pipermail/python-list/2009-October/555361.html
沒有留言:
張貼留言