-
Notifications
You must be signed in to change notification settings - Fork 4
/
atom_dtu_nb_iot.py
52 lines (45 loc) · 1.22 KB
/
atom_dtu_nb_iot.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
# Copyright (c) 2022 by GWENDESIGN. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
from m5stack import *
from m5ui import *
from uiflow import *
from easyIO import *
from numbers import Number
import time
btnAPressed = None
def sendAT(cmd):
print((str('> ') + str(cmd)))
uart1.write(str(cmd)+"\r\n")
wait_ms(250)
def readResponse(timeout, waitFor):
rgb.setColorAll(0x000000)
while timeout:
if uart1.any():
response = (uart1.readline()).decode()
response = response.strip()
if response != '':
print((str('< ') + str(response)))
if response == waitFor:
break
wait_ms(100)
timeout = (timeout if isinstance(timeout, Number) else 0) + -100
print(str(timeout))
if timeout == 0:
print('timeout')
rgb.setColorAll(0xff0000)
else:
print('found')
rgb.setColorAll(0x00ff00)
def buttonA_wasPressed():
global btnAPressed
btnAPressed = True
pass
btnA.wasPressed(buttonA_wasPressed)
uart1 = machine.UART(1, tx=22, rx=19)
uart1.init(115200, bits=8, parity=None, stop=1)
while True:
if btnAPressed:
btnAPressed = False
sendAT('AT')
readResponse(10000, 'OK')
wait_ms(2)