Created
December 4, 2013 10:09
-
-
Save oampo/7785192 to your computer and use it in GitHub Desktop.
Python->Arduino communication example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void setup() { | |
Serial.begin(9600); | |
pinMode(13, OUTPUT); | |
} | |
void loop() { | |
String serialString; | |
while (Serial.available()) { | |
serialString += Serial.read(); | |
} | |
if (serialString == "119") { | |
digitalWrite(13, 1); | |
} | |
else if (serialString == "115") { | |
digitalWrite(13, 0); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import serial | |
print('Starting USB') | |
# Change /dev/ttyACM0 for COMX if on Windows | |
s = serial.Serial('/dev/ttyACM0', 9600, timeout=1) | |
while (1): | |
# Change raw_input for input if using Python 3 | |
key=raw_input('Enter key:\n').strip() | |
if key=='w': | |
s.write("w".encode("ascii")) | |
if key=='s': | |
s.write("s".encode("ascii")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment