-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBluetoothCommandTerm.py
50 lines (44 loc) · 1.39 KB
/
BluetoothCommandTerm.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
from machine import UART, Pin
from time import sleep
# uos provides information such as the machine name and build version numbers
import uos
# setup the UART
id = 0
rx = Pin(1)
tx = Pin(0)
baudrate=115200 # default is 9600 for HC-06 and DX-BT04-E modules
# default is 115200 for Waveshare Pico-BLE module
# create the UART
uart = UART(id=id, baudrate=baudrate,tx=tx, rx=rx, bits=8, parity=None, stop=1)
# Print a pretty command line
print("-"*50)
print("PicoTerm")
print(uos.uname())
print("type 'quit' to exit, or help for commands")
# Loop
command = ""
while True and command !='quit':
# Write our command prompt
command = input("PicoTerm> ")
if command == 'help':
help()
elif command != 'quit':
#uart.write(command)
# DX-BT04-E and Waveshare Pico-BLE modules require appended CR and LF chars!
commandTermin = str(command)+"\r\n"
uart.write(commandTermin)
print(command)
sleep(0.1)
response = bytes()
while uart.any() > 0:
response = uart.read()
# output = "".join(["'",str(command),"'","response:",str(response.decode('utf-8'))])
try:
print("decoded: ")
output = str(response.decode('utf-8'))
print(output)
except:
print("weird response")
elif command == 'quit':
print("-"*50)
print('Bye.')