固件烧录
注意:此固件处于测试阶段,可能会存在一些bug,推荐有一定技术能力的用户使用。目前无法中文显示和体验AI部分功能,如需使用请使用mind+图形化编程方式。
注意:烧录micropython固件后,要想再使用Mind+中的图形化模式,需要恢复初始设置。
恢复时先按住boot,再接数据线,待识别出端口后即可松开BOOT键,此时再点击恢复初始设置。完成后摁下板子的RST复位即可完成恢复
-
下载ESP32固件烧录软件:点击下载
-
解压后运行exe文件,选择ESP32-S3。
-
选择对应的文件,填入相应地址,并勾选最前面的对号。
-
按住行空板K10背面的BOOT按钮,连接板子与电脑,在软件中选择对应的端口。
-
先点击“ERASE”清除flsh,待成功后再点击"START"进行烧录。
-
烧录完成后摁下行空板K10板子的RST复位键。
软件准备
-
下载并安装Thonny
-
安装完成后打开软件,软件右下角选择ESP32
-
点击左上角新建文件,输入代码
-
CTRL+S保存到micropython设备。选择保存到此电脑也可以,若选择保存到此电脑,则程序未保存到板子中,重启板子后程序会丢失,测试阶段适合保存到电脑中。
-
保存文件命名为main.py。
-
点击运行。
全部板载资源示例
from unihiker_k10 import screen,camera,tf_card,
from unihiker_k10 import temp_humi,light,acce
from unihiker_k10 import rgb,button
from unihiker_k10 import mic,speaker
import time
#初始化屏幕 设置方向为(0-3)
screen.init(dir=2)#代码中不调用时默认为2
camera.init()#初始化摄像头
#板载2812
rgb.write(num = 0, R=255,G=0,B=0)
rgb.write(num = 1, R=0,G=255,B=0)
rgb.write(num = 2, R=0,G=0,B=255)
time.sleep(1)
rgb.clear()
#开始录音,并将音频文件保存到文件系统中,然后播放录音
screen.draw_text(text="begin sys recode",line=0)
screen.show_draw()
mic.recode_sys(name="sound.wav",time=5)
screen.draw_text(text="recode sys done",line=0)
screen.show_draw()
time.sleep(1)
screen.draw_text(text="begin sys play",line=0)
screen.show_draw()
speaker.play_sys_music("sound.wav")
screen.draw_text(text="end sys play",line=0)
screen.show_draw()
time.sleep(1)
#将摄像头画面显示到屏幕上
screen.show_camera(camera)
bt_a=button(button.a)#初始化板载按键传感器 A
bt_b=button(button.b)#初始化板载按键传感器 B
def button_a_pressed():
screen.draw_text(text="btn_a:pressed",line=5)
screen.show_draw()
def button_a_released():
screen.draw_text(text="btn_a:released",line=5)
screen.show_draw()
def button_b_pressed():
screen.draw_text(text="btn_b:pressed",line=6)
screen.show_draw()
def button_b_released():
screen.draw_text(text="btn_b:released",line=6)
screen.show_draw()
bt_a.event_pressed = button_a_pressed
bt_a.event_released = button_a_released
bt_b.event_pressed = button_b_pressed
bt_b.event_released = button_b_released
while True:
screen.draw_text(text="temp=" + str(temp_humi.read_temp()) + " humi=" + str(temp_humi.read_humi()),line=0)
screen.show_draw()
screen.draw_text(text="light=" + str(light.read()) ,line=1)
screen.show_draw()
screen.draw_text(text="ax=" + str(acce.read_x()),line=2)
screen.show_draw()
screen.draw_text(text="ay=" + str(acce.read_y()),line=3)
screen.show_draw()
screen.draw_text(text="az=" + str(acce.read_z()),line=4)
screen.show_draw()
time.sleep(0.1)
屏幕显示
from unihiker_k10 import screen
import time
screen.init(dir=2)
screen.show_bg(color=0xFFFF00)
screen.set_width(width=5)
screen.draw_line(x0=0,y0=0,x1=80,y1=80,color=0x0000FF)
screen.draw_point(x=100,y=10,color=0xFF0000)
screen.draw_rect(x=120,y=100,w=80,h=120,bcolor=0xFF6666,fcolor=0x0000FF)
screen.draw_rect(x=120,y=100,w=40,h=60,bcolor=0x012345)
screen.draw_circle(x=80,y=80,r=40,bcolor=0x00FF00,fcolor=0x0000FF)
screen.draw_circle(x=80,y=80,r=20,bcolor=0xFF0000)
screen.draw_text(text="hello\n123",x=10,y=0,font_size=24,color=0xFF0000)
screen.draw_text(text="line\n456\nhgjh\n",line=2,font_size=24,color=0xFF0000)
screen.show_draw()
time.sleep(2)
screen.clear()
while True:
pass
板载按钮
from unihiker_k10 import button
import time
bt_a=button(button.a)#初始化板载按键传感器 A
bt_b=button(button.b)#初始化板载按键传感器 B
#当按键(A/B)(按下/松开)
def button_a_pressed():
print("button_a_pressed")
def button_a_released():
print("button_a_released")
def button_b_pressed():
print("button_b_pressed")
def button_b_released():
print("button_b_released")
bt_a.event_pressed = button_a_pressed
bt_a.event_released = button_a_released
bt_b.event_pressed = button_b_pressed
bt_b.event_released = button_b_released
while True:
#print("button_a.status=",bt_a.status())
#print("button_b.status=",bt_b.status())
time.sleep(0.1)
pass
板载温湿度
from unihiker_k10 import button,temp_humi
#读取(温度℃/温度℉/湿度)
print(temp_humi.read_temp())#摄氏度
print(temp_humi.read_temp_f())#华氏度
print(temp_humi.read_humi())
while True:
pass
板载环境光
from unihiker_k10 import light
import time
while True:
print(light.read())
time.sleep(0.1)
板载加速度传感器
from unihiker_k10 import acce
import time
#读取加速度的值(x/y/z)
while True:
print("x=",acce.read_x())
print("y=",acce.read_y())
print("z=",acce.read_z())
time.sleep(0.1)
板载RGB灯
from unihiker_k10 import rgb
import time
#灯号(0,1,2,全部)显示颜色()
rgb.write(num = 0,color=0x0000FF)#可以用-1或不传num代表全部
#灯号(0,1,2,全部)显示颜色R()G()B()
rgb.write(num = 0,R=255,G=0,B=0)
#关闭(全部,0,1,2)RGB
rgb.write(num = 0,color=0x000000)
#设置RGB亮度为(0-9)
rgb.brightness(9)
while True:
rgb.write(color=0xFF00FF)
time.sleep(1)
rgb.write(num = 0, R=255,G=0,B=0)
rgb.write(num = 1, R=0,G=255,B=0)
rgb.write(num = 2, R=0,G=0,B=255)
time.sleep(1)
rgb.clear()
time.sleep(1)
rgb.write(num = 2, R=0,G=0,B=255)
time.sleep(1)
rgb.write(color=0x0000)
time.sleep(1)
TF卡
from unihiker_k10 import tf_card
import os
files = os.listdir("/sd")
print("Files in /sd:",files)
录放音
from unihiker_k10 import mic,speaker
import time
print("begin sys recode")
mic.recode_sys(name="sound.wav",time=5)
print("recode sys done")
time.sleep(1)
print("begin sys play")
speaker.play_sys_music("sound.wav")
print("end sys play")
time.sleep(1)
print("begin tf recode")
mic.recode_tf(name="sound.wav",time=5)
print("recode tf done")
time.sleep(1)
print("begin tf play")
speaker.play_tf_music("sound.wav")
print("end tf play")
while True:
pass
WiFi
from unihiker_k10 import wifi
wifi.connect(ssid="dfrobotOffice",psd="dfrobot2011",timeout=50000) #尝试连接wifi网络。可以不写参数名称。timeout为可选参数,表示连接超时时长,默认超时时间为10000毫秒
wifi.status() #返回网络连接状态,True表示已连接,False表示未连接
wifi.info() #返回包含当前IP地址、子网掩码、网关等信息的字符串
MQTT
# EASYIOT
from unihiker_k10 import wifi
from unihiker_k10 import mqttclient
import time
wifi.connect(ssid="Redm",psd="aijine12345",timeout=50000) #尝试连接wifi网络。可以不写参数名称。timeout为可选参数,表示连接超时时长,默认超时时间为10000毫秒
wifi.status() #返回网络连接状态,True表示已连接,False表示未连接
wifi.info() #返回包含当前IP地址、子网掩码、网关等信息的字符串
def received_1ffdf0jpLa():
msg=mqttclient.message(topic='AwErylzNg')
print(msg)
mqttclient.connect(server= "iot.dfrobot.com.cn",
port=1883,
client_id="",
user= "VB3Xs_kHg" ,
psd= "VB3Xy_zNgz") #阻塞运行,默认超时时间为3秒
mqttclient.connected() #返回连接状态
mqttclient.publish(topic='AwErylzNg',content= 'hello')#向对应主题发送消息,content为发送内容
#msg=mqttclient.message(topic='1ffdf0jpLa') #获取对应主题接收的消息,若该主题无消息,则返回None
mqttclient.received (topic='AwErylzNg', #对应主题收到消息时,回调函数
callback=received_1ffdf0jpLa) #通过callback指定回调函数
while True:
time.sleep(0.1)
pass
# SIOT V1
from unihiker_k10 import wifi
from unihiker_k10 import mqttclient
import time
wifi.connect(ssid="DFRobot-guest",psd="dfrobot@2017",timeout=50000) #尝试连接wifi网络。可以不写参数名称。timeout为可选参数,表示连接超时时长,默认超时时间为10000毫秒
wifi.status() #返回网络连接状态,True表示已连接,False表示未连接
wifi.info() #返回包含当前IP地址、子网掩码、网关等信息的字符串
def received_1ffdf0jpLa():
msg=mqttclient.message(topic='siot/Speed')
print(msg)
mqttclient.connect(server= "192.168.7.141",
port=1883,
client_id="",
user= "siot" ,
psd= "dfrobot") #阻塞运行,默认超时时间为3秒
mqttclient.connected() #返回连接状态
mqttclient.publish(topic='siot/Speed',content= 'hello')#向对应主题发送消息,content为发送内容
#msg=mqttclient.message(topic='1ffdf0jpLa') #获取对应主题接收的消息,若该主题无消息,则返回None
mqttclient.received (topic='siot/Speed', #对应主题收到消息时,回调函数
callback=received_1ffdf0jpLa) #通过callback指定回调函数
while True:
time.sleep(0.1)
pass
# SIOT V2 mqttclient.publishs上报消息位置要加"->"
from unihiker_k10 import wifi
from unihiker_k10 import mqttclient
import time
wifi.connect(ssid="Redm",psd="aijine12345",timeout=50000) #尝试连接wifi网络。可以不写参数名称。timeout为可选参数,表示连接超时时长,默认超时时间为10000毫秒
wifi.status() #返回网络连接状态,True表示已连接,False表示未连接
wifi.info() #返回包含当前IP地址、子网掩码、网关等信息的字符串
def received_1ffdf0jpLa():
msg=mqttclient.message(topic='siot/Speed')
print(msg)
mqttclient.connect(server= "192.168.45.146",
port=1883,
client_id="",
user= "siot" ,
psd= "dfrobot") #阻塞运行,默认超时时间为3秒
mqttclient.connected() #返回连接状态
mqttclient.publish(topic='siot/Speed',content= '->hello')#向对应主题发送消息,content为发送内容
#msg=mqttclient.message(topic='1ffdf0jpLa') #获取对应主题接收的消息,若该主题无消息,则返回None
mqttclient.received (topic='siot/Speed', #对应主题收到消息时,回调函数
callback=received_1ffdf0jpLa) #通过callback指定回调函数
while True:
time.sleep(0.1)
pass
蓝牙HID
from unihiker_k10 import screen, hid, keycode,button
import time
bt_a=button(button.a)#初始化板载按键传感器 A
bt_b=button(button.b)#初始化板载按键传感器 B
ble_hid = hid(name='mpy_hid') #初始化蓝牙 HID 设备并命名为 mpy_hid
screen.init(dir = 2)
screen.show_bg(color=0xFFFF00)
screen.draw_text(text="ready",line=1,font_size=24,color=0xFF0000)
screen.show_draw()
while True:
if ble_hid.isconnected():#判断是否已经连接,True 为连接,False 为未连接 非阻塞
screen.draw_text(text="connect",line=1,font_size=24,color=0xFF0000)
screen.show_draw()
else:
screen.draw_text(text="disconnect",line=1,font_size=24,color=0xFF0000)
screen.show_draw()
if bt_a.status() == 1:
ble_hid.keyboard_send(keycode.SPACE) #模拟键盘按下空格
if bt_b.status() == 1:
ble_hid.keyboard_send([keycode.CTRL,keycode.a]) #按下组合键CTRL+a
time.sleep(0.1)
舵机
from unihiker_k10 import servo
import time
s1=servo(1) # 将舵机连接到P1引脚
while True:
s1.angle(value=170) #设置舵机转动到 180°位置,角度范围为:0~180°
time.sleep(1)
s1.angle(value=10)
time.sleep(1)
RGB灯带
from unihiker_k10 import neopixel
ws2812=neopixel(0,3) #将灯带连接到 1 号引脚,数量3
ws2812.brightness(9)#设置亮度0-9
ws2812.write(0,1,0x00,0x00,0xFF) #让 0-2 号灯珠根据 r、g、b 值显示色彩
DHT11/DHT22温湿度
from unihiker_k10 import dht
import time
dhtsensor=dht(0)#初始化连接在 0 号口上的DHT传感器,能自动识别11还是22
while True:
temp,hum=dhtsensor.read()
print(temp)
print(hum)
time.sleep(1)
DS18B20
from unihiker_k10 import ds18b20
import time
ds=ds18b20(1)
while True:
temp=ds.read()
print(temp)
time.sleep(1)
超声波
from unihiker_k10 import ultrasonic
import time
sonic=ultrasonic(trig=0,echo=0) #连接 trig 和 echo 引脚,填一样的引脚时用的是SEN0388
while True:
print(sonic.distance())
time.sleep(0.1)
重量传感器KIT0176
from unihiker_k10 import force
import time
fs=force()
fs.zero() #清零
while True:
print(fs.read(mass=False)) #返回质量值,单位为克。#默认返回质量,当参数mass=False时,返回力的单位N(牛顿)
time.sleep(0.5)