-
Notifications
You must be signed in to change notification settings - Fork 0
/
serialTest.py
38 lines (30 loc) · 894 Bytes
/
serialTest.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
#!/usr/bin/env python
#WORKS SO FAR!!!!
import serial
import RPi.GPIO as GPIO
import time
import io
from time import sleep
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(31, GPIO.OUT, initial=GPIO.LOW) #enable pin, high for send, low for receive
ser = serial.Serial(
port='/dev/ttyAMA1',
baudrate = 57600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
i = ["<30,36,1,1>"] #sending message <left press, right press, auto(0)/manual(1), pump off(0)/on(1)>
GPIO.output(31, 1)
msgInterval = 3
msgTime = time.time()
while True:
t1 = time.time()
if t1 - msgTime >= msgInterval:
msgTime = time.time()
for x in i:
ser.write(str.encode(x, encoding="ascii"))
print(str(x))
#GPIO.output(31, 0)