Skip to content

Instantly share code, notes, and snippets.

@silageman
Created December 22, 2015 05:34
Show Gist options
  • Save silageman/5c3d9d889dfda0e40900 to your computer and use it in GitHub Desktop.
Save silageman/5c3d9d889dfda0e40900 to your computer and use it in GitHub Desktop.
Serial communication to arduino, requires pyserial.
import serial
import time
import msvcrt
from msvcrt import getch
byte1 = 50
byte2 = 51
print "***********************************"
print "********Opening Serial Port********"
print "***********************************"
arduino = serial.Serial(2, 9600)
time.sleep(3)
while(True):
key = ord(getch())
if key == 49:
print "DEBUG: RELAY INI1 TOGGLED"
arduino.write(chr(byte1))
elif key == 50:
arduino.write(chr(byte2))
print "DEBUG: RELAY INI2 TOGGLED"
elif key == 113:
print "**************EXIT***************"
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment