-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcode-sensor-receiver.py
More file actions
80 lines (73 loc) · 2.37 KB
/
Copy pathcode-sensor-receiver.py
File metadata and controls
80 lines (73 loc) · 2.37 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
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
76
77
78
79
80
#Rename to code.py and put in receiver module
# Write your code here :-)
# import semua library yang berkaitan
import time
import board
import busio
import binascii
import sys
import re
import adafruit_ssd1306
# mendefinisikan penggunaan UART
uart = busio.UART(board.GP0, board.GP1, baudrate=9600)
LCD_SDA = board.GP16
LCD_SCL = board.GP17
i2c = busio.I2C(scl=LCD_SCL, sda=LCD_SDA)
oled = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c)
message_started = False
message_print = []
allstring = ""
printshow = False
# Mula Loop
# Setup AT+TEST=RXLRPKT
uart.write(bytes("AT+MODE=TEST", "utf-8"))
print("Checking.. AT+MODE=TEST")
while uart.readline():
print(uart.readline())
uart.write(bytes("AT+TEST=?", "utf-8"))
print("Checking.. AT+TEST=TEST=?")
while uart.readline():
print(uart.readline())
uart.write(bytes("AT+TEST=RXLRPKT", "utf-8"))
print("Checking.. AT+TEST=RXLRPKT")
while uart.readline():
print(uart.readline())
while True:
try:
byte_read = uart.readline() # read up to 32 bytes
if byte_read:
allstring += byte_read.decode()
printshow = True
else:
if printshow:
if allstring:
left = '"3C'
right = '3E"'
dataRead = re.search(
r"" + left + "(.*?)" + right + "", allstring
).group(1)
clearstring = binascii.unhexlify(dataRead).decode("utf8")
print(clearstring)
letter_list = clearstring.split(",")
temperature = letter_list[0]
humidity = letter_list[1]
co2 = letter_list[2]
oled.fill(0)
#Lukis segiempat sama
oled.rect(10, 10, oled.width-10, oled.height-10, True)
#paparkan pada OLED
oled.text("Demo RX Receiving",20,20,1)
oled.text("CO2 :" +co2, 20, 30,1)
oled.text("Temp :"+temperature, 20, 40, 1)
oled.text("Humidity :"+humidity, 20, 50, 1)
oled.show()
allstring = ""
printshow = False
except ValueError as e:
# print(e)
continue
except AttributeError as ea:
# print(ea)
continue
except KeyboardInterrupt:
sys.exit()