-
Notifications
You must be signed in to change notification settings - Fork 1
/
piArduinoSPI.py
76 lines (62 loc) · 1.15 KB
/
piArduinoSPI.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import binascii
import spidev
import time
import RPi.GPIO as GPIO
spi = spidev.SpiDev()
GPIO.setmode(GPIO.BOARD)
def setSlave(ardSelect):
device = 0
if (ardSelect == 1):
spi.open(device,1)
def transmit(msg):
try:
spi.open(0,0)
spi.mode=0
spi.max_speed_hz = 115200
while True:
#print(msg)
tx=spi.writebytes([msg])
time.sleep(0.3)
finally:
spi.close()
def setupGPIO():
GPIO.setup(7, GPIO.OUT)
GPIO.setup(11, GPIO.OUT)
def fwd0():
GPIO.output(7,0)
GPIO.output(11,0)
cmd=ord('F')
print cmd
transmit(cmd)
def fwd1():
GPIO.output(7,1)
GPIO.output(11,0)
cmd=ord('F')
print cmd
transmit(cmd)
def fwd2():
GPIO.output(7,0)
GPIO.output(11,1)
cmd=ord('F')
print cmd
transmit(cmd)
def fwd3():
GPIO.setup(7, GPIO.OUT)
GPIO.setup(11, GPIO.OUT)
GPIO.output(7,1)
GPIO.output(11,1)
cmd=ord('F')
print cmd
transmit(cmd)
def back(A, B, msg):
GPIO.output(7,A)
GPIO.output(11,B)
cmd=ord(msg)
#print cmd
transmit(cmd)
def fwd(A,B, msg):
GPIO.output(7,A)
GPIO.output(11,B)
cmd=ord(msg)
#print cmd
transmit(cmd)