知识点:什么是掌控板?
掌控板是一块普及STEAM创客教育、人工智能教育、机器人编程教育的开源智能硬件。它集成ESP-32高性能双核芯片,支持WiFi和蓝牙双模通信,可作为物联网节点,实现物联网应用。同时掌控板上集成了OLED显示屏、RGB灯、加速度计、麦克风、光线传感器、蜂鸣器、按键开关、触摸开关、金手指外部拓展接口,支持图形化及MicroPython代码编程,可实现智能机器人、创客智造作品等智能控制类应用。
1、物联网(Internet of Things,缩写:IoT)
是基于互联网、传统电信网等信息承载体,让所有能行使独立功能的普通物体实现互联互通的网络。其应用领域主要包括运输和物流、工业制造、健康医疗、智能环境(家庭、办公、工厂)等,具有十分广阔的市场前景。
物联网的概念最早是在1999年由Kevin Ashton在一次演讲中提出来的,当时他是一个RFID研究机构的执行主任,这家研究机构是在宝洁公司和吉列公司的赞助下成立的。而他本人也因此被称为物联网之父。随后麻省理工学院的Neil Gershenfeld教授出版了一本名为《When things Start to Think》的书。以这些为标志,正式揭开了物联网的序幕。
物联网的英文是Internet of Things,缩写为IoT。这里的“物”指的是我身边一切能与网络联通的物品。例如你带的手表、你骑的共享单车、马路上的汽车、家里的冰箱、路边的路灯、甚至是一棵树。只要一件物品能够与网络相连,它就都是物联网中的“物”。而所谓物联网,就是“物”与人,以及“物”与“物”之间,通过网络来传递和处理信息。
1、微信小程序
小程序的一种,英文名Wechat Mini Program,是一种不需要下载安装即可使用的应用,它实现了应用“触手可及”的梦想,用户扫一扫或搜一下即可打开应用。全面开放申请后,主体类型为企业、政府、媒体、其他组织或个人的开发者,均可申请注册小程序。微信小程序、微信订阅号、微信服务号、微信企业号是并行的体系。
微信小程序是一种不用下载就能使用的应用,也是一项创新,经过将近两年的发展,已经构造了新的微信小程序开发环境和开发者生态。微信小程序也是这么多年来中国IT行业里一个真正能够影响到普通程序员的创新成果,已经有超过150万的开发者加入到了微信小程序的开发,与我们一起共同发力推动微信小程序的发展,微信小程序应用数量超过了一百万,覆盖200多个细分的行业,日活用户达到两个亿,微信小程序还在许多城市实现了支持地铁、公交服务。微信小程序发展带来更多的就业机会,2017年小程序带动就业104万人,社会效应不断提升。
2017年1月9日,张小龙在2017微信公开课Pro上发布的微信小程序正式上线。2018年2月,微信官方发布公告称:已对涉及假货高仿、色情低俗和违规“现金贷”等超过2000个微信小程序,进行永久封禁处理。2019年8月9日,微信向开发者发布新能力公测与更新公告,微信PC版新版本中,支持打开聊天中分享的微信小程序。
7、带输入框的RGB三色调光板
刚添加的小程序控制组件面板
#MicroPython动手做(27)——物联网之微信小程序
#带输入框的RGB三色调光板
#MicroPython动手做(27)——物联网之微信小程序
#带输入框的RGB三色调光板from mpython import *
import network
import time
import music
from umqtt.simple import MQTTClient
from machine import Timer
import machine
import ubinascii
import ujsonmy_wifi = wifi()my_wifi.connectWiFi("zh", "zy1567")def OneNET_recv(_msg):pass
_OneNET_msg_list = []
def OneNET_callback(_topic, _msg):global _OneNET_msg_listtry: _msg = _msg.decode('utf-8', 'ignore')except: print(_msg);returnOneNET_recv(_msg)if _msg in _OneNET_msg_list:eval('OneNET_recv_' + bytes.decode(ubinascii.hexlify(_msg)) + '()')tim14 = Timer(14)_iot_count = 0
def timer14_tick(_):global _iot, _iot_count_iot_count = _iot_count + 1if _iot_count == 1000: _iot.ping(); _iot_count = 0try: _iot.check_msg()except: machine.reset()_iot = None
def OneNET_setup():global _iot_iot = MQTTClient("595250725", "183.230.40.39", 6002, "221628", "hiN7Cwz4Gd7d3ReMnNgtaEKBvv4=", keepalive=300)_iot.set_callback(OneNET_callback)if 1 == _iot.connect(): print('Successfully connected to MQTT server.')tim14.init(period=200, mode=Timer.PERIODIC, callback=timer14_tick)def OneNET_recv(_msg):try:_msgObj = ujson.loads(_msg)_name = _msgObj.get('name')_value = _msgObj.get('value')except: returnif _name == "输入":print(_value)music.play('B3:1')rgb[1] = (int(51), int(102), int(255))rgb.write()time.sleep_ms(1)oled.fill(0)oled.DispChar(_value, 0, 23, 1)oled.show()if _name == "R":print(_value)rgb.fill( (int(_value), int((_value + 20)), int((_value - 20))) )rgb.write()time.sleep_ms(1)if _name == "G":print(_value)rgb.fill( (int((_value + 20)), int(_value), int((_value - 20))) )rgb.write()time.sleep_ms(1)if _name == "B":print(_value)rgb.fill( (int((_value - 20)), int((_value + 20)), int(_value)) )rgb.write()time.sleep_ms(1)rgb[1] = (int(0), int(102), int(0))
rgb.write()
time.sleep_ms(1)
music.play('G4:1')
OneNET_setup()
mPython X 实验图形编程
8、实时监控光线值和声音值
GX与SY 小程序控制组件面板
#MicroPython动手做(27)——物联网之微信小程序
#实时监控光线值和声音值
#MicroPython动手做(27)——物联网之微信小程序
#实时监控光线值和声音值from mpython import *
import network
import time
import music
from umqtt.simple import MQTTClient
from machine import Timer
import machine
import ubinascii
import jsonmy_wifi = wifi()my_wifi.connectWiFi("zh", "zy1567")def OneNET_recv(_msg):pass
_OneNET_msg_list = []
def OneNET_callback(_topic, _msg):global _OneNET_msg_listtry: _msg = _msg.decode('utf-8', 'ignore')except: print(_msg);returnOneNET_recv(_msg)if _msg in _OneNET_msg_list:eval('OneNET_recv_' + bytes.decode(ubinascii.hexlify(_msg)) + '()')tim14 = Timer(14)_iot_count = 0
def timer14_tick(_):global _iot, _iot_count_iot_count = _iot_count + 1if _iot_count == 1000: _iot.ping(); _iot_count = 0try: _iot.check_msg()except: machine.reset()_iot = None
def OneNET_setup():global _iot_iot = MQTTClient("595250725", "183.230.40.39", 6002, "221628", "hiN7Cwz4Gd7d3ReMnNgtaEKBvv4=", keepalive=300)_iot.set_callback(OneNET_callback)if 1 == _iot.connect(): print('Successfully connected to MQTT server.')tim14.init(period=200, mode=Timer.PERIODIC, callback=timer14_tick)def pubdata(_dic):print(_dic)_list = []for _key in list(_dic.keys()):_d = {'id':_key,'datapoints':[{'value':_dic[_key]}]}_list.append(_d)_data = {'datastreams': _list}j_d = json.dumps(_data)j_l = len(j_d)arr = bytearray(j_l + 3)arr[0] = 1arr[1] = int(j_l / 256)arr[2] = j_l % 256arr[3:] = j_d.encode('ascii')return arrrgb[1] = (int(0), int(102), int(0))
rgb.write()
time.sleep_ms(1)
music.play('G4:1')
OneNET_setup()
while True:_iot.publish('$dp', pubdata({"xx":light.read()}))_iot.publish('$dp', pubdata({"yy":sound.read()}))time.sleep(1)
mPython X 实验图形编程
小程序上实时监控光线值和声音值
9、通过小程序控制小车进、退、左和右
调整好的小程序控制组件面板
#MicroPython动手做(27)——物联网之微信小程序
#通过小程序控制小车进、退、左和右
#MicroPython动手做(27)——物联网之微信小程序
#通过小程序控制小车进、退、左和右from mpython import *import networkmy_wifi = wifi()my_wifi.connectWiFi('zh', 'zy1567')import timeimport musicfrom umqtt.simple import MQTTClientfrom machine import Timerimport machineimport ubinasciidef OneNET_recv(_msg):pass
_OneNET_msg_list = []
def OneNET_callback(_topic, _msg):global _OneNET_msg_listtry: _msg = _msg.decode('utf-8', 'ignore')except: print(_msg);returnOneNET_recv(_msg)if _msg in _OneNET_msg_list:eval('OneNET_recv_' + bytes.decode(ubinascii.hexlify(_msg)) + '()')tim14 = Timer(14)_iot_count = 0
def timer14_tick(_):global _iot, _iot_count_iot_count = _iot_count + 1if _iot_count == 1000: _iot.ping(); _iot_count = 0try: _iot.check_msg()except: machine.reset()_iot = None
def OneNET_setup():global _iot_iot = MQTTClient('595250725', '183.230.40.39', 6002, '221628', 'hiN7Cwz4Gd7d3ReMnNgtaEKBvv4=', keepalive=300)_iot.set_callback(OneNET_callback)if 1 == _iot.connect(): print('Successfully connected to MQTT server.')tim14.init(period=200, mode=Timer.PERIODIC, callback=timer14_tick)import ujsonimport parrotdef forward():global _name, _valueparrot.set_speed(parrot.MOTOR_1, 80)parrot.set_speed(parrot.MOTOR_2, 80)oled.fill(0)oled.blit(image_picture.load('face/Information/Forward.pbm', 0), 32, 0)oled.show()def retreat():global _name, _valueparrot.set_speed(parrot.MOTOR_1, -80)parrot.set_speed(parrot.MOTOR_2, -80)oled.fill(0)oled.blit(image_picture.load('face/Information/Backward.pbm', 0), 32, 0)oled.show()def right():global _name, _valueparrot.set_speed(parrot.MOTOR_1, 80)parrot.set_speed(parrot.MOTOR_2, -0)oled.fill(0)oled.blit(image_picture.load('face/Information/Right.pbm', 0), 32, 0)oled.show()def Left():global _name, _valueparrot.set_speed(parrot.MOTOR_1, -0)parrot.set_speed(parrot.MOTOR_2, 80)oled.fill(0)oled.blit(image_picture.load('face/Information/Left.pbm', 0), 32, 0)oled.show()def OneNET_recv(_msg):try:_msgObj = ujson.loads(_msg)_name = _msgObj.get('name')_value = _msgObj.get('value')except: returnif _name == '进':print(_value)rgb.fill((int(0), int(102), int(0)))rgb.write()time.sleep_ms(1)forward()if _name == '退':print(_value)rgb.fill((int(51), int(51), int(255)))rgb.write()time.sleep_ms(1)retreat()if _name == '左':print(_value)rgb[0] = (int(0), int(102), int(0))rgb.write()time.sleep_ms(1)Left()if _name == '右':print(_value)rgb[2] = (int(0), int(102), int(0))rgb.write()time.sleep_ms(1)right()time.sleep(3)parrot.set_speed(parrot.MOTOR_1, 0)parrot.set_speed(parrot.MOTOR_2, 0)rgb.fill( (0, 0, 0) )rgb.write()time.sleep_ms(1)image_picture = Image()
rgb[1] = (int(102), int(0), int(0))
rgb.write()
time.sleep_ms(1)
music.play('G5:1')
OneNET_setup()
后来改为延时3秒关闭电机,小程序组件面板为
mPython 实验图形编程
MicroPython动手做(27)——物联网之微信小程序
通过小程序控制小车进、退、左和右(实验视频)
https://v.youku.com/v_show/id_XNDcwMDE3NTUwOA==.html?spm=a2h0c.8166622.PhoneSokuUgc_1.dtitle