-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharduino.py
More file actions
40 lines (37 loc) · 1.39 KB
/
arduino.py
File metadata and controls
40 lines (37 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from time import sleep
import serial
import sys
#from msvcrt import getch
##==============================================================================
ser =serial.Serial("/dev/ttyACM0", 9600, timeout=2) # Establish the connection on a specific port
##==============================================================================
##=======getchar========================
def getchar():
#Returns a single character from standard input
key = getch() ##Get byte ex: b'a'
key_num=ord(key) ##convert byte to integer 97
key_chr=chr(key_num) ##convert integer to char 'a'
return key_num
##====================================
##======Write Serial Command to arduino============
def SerialWrite(command):
ser.write(command)
rv=ser.readline()
#print (rv) # Read the newest output from the Arduino
print ("last time command: "+rv.decode("utf-8"))
sleep(1) # Delay for one tenth of a second
ser.flushInput()
##====================================
while 1:
var = raw_input("input somthing...")
if len(var) == 1:
SerialWrite(chr(ord(var)))
else:
print("Please input again!!!")
##=======Get Ready================
#print("Connecting to Arduino.....")
#for i in range (1,10):
# rv=ser.readline()
# print("Loading...")
#print(rv)
#Debug print (rv) # Read the newest output from the Arduino