简介
哪吒是全志在线基于全志科技D1芯片定制的AIOT开发板,是全球首款支持64bit RISC-V指令命令集成并支持Linnux系统的可量产开发板。支持1G DDR3*、258MB spi-nand、WiFi/蓝牙连接,具有丰富的音视频接口可强大的音视频编解码能力,可连接各种外设,集成了MIPI-DSI+TP接口、SD卡接口、LED灯、HDMI接口、麦克风子板接口、3.5mm耳机接口、千兆以太网接口、USB HOST、Type-C接口、UART Debug接口、40pins插针阵列等,可以满足日常科研教学、产品项目预研、开发爱好者DIY的需求。
RISC-V初学者D1入门套件是DFRobot打造的一套为刚接触RVBoards-哪吒的初学者而设计的传感器套件。该套件包含一个哪吒专用IO扩展板、6种常用的不同种类信号输入传感器、3个执行器、1块OLED显示屏以及1条USB数据线,结合DFRobot精心编写的一系列保姆级生动教程,即使是初学者也能轻松学会哪吒D1的开发。
特性
-
套件内哪吒专用的IO扩展板使40PIN功能区分更加明确,使用直观简便
-
搭配共10款外设(包括6种常用的不同种类信号输入传感器、3个执行器、1块OLED显示屏),能覆盖入门项目的设备需求
-
支持PINPONG驱动库,大大降低开发难度。
-
详细完整的入门教程
配送清单
SKU | 产品名称 |
---|---|
DFR0883 | 哪吒IO扩展板 |
SEN0409 | LIS2DW12三轴加速度计 |
SEN0443 | SHT31数字温湿度传感器 |
DFR0032 | 数字蜂鸣器模块 |
DFR0029 | 数字大按钮模块 x 2 |
SEN0307 | 超声波测距传感器 |
SER0006 | DF9GMS 180° 微型舵机 |
DFR0031-R | 红色LED灯模块 |
DFR0107 | 红外遥控套件 |
DFR0649 | 1.54"IPS广视角TFT显示屏 |
DFR0231-H | NFC近场通讯模块 |
杜邦线若干 |
使用教程
新手教程引导
在使用本套件的进阶教程之前您需要先阅读关于哪吒主板的系统烧录、远程登录和联网操作等入门级内容。
详情见哪吒扩展板WIKI的教程说明
进阶教程一 : 按钮控制LED灯亮灭
- 硬件准备及接线图
- 示例代码
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
#NeZha
#实验效果:使用按钮控制LED亮灭
import time
from pinpong.board import Board,Pin
Board("nezha").begin()
btn = Pin(6, Pin.IN) #引脚初始化为电平输入,接按钮
led = Pin(11, Pin.OUT)#引脚初始化为电平输出,接LED
while True:
v = btn.value() #读取引脚电平
print(v) #终端打印读取的电平状态
led.value(v) #将按钮状态设置给led灯引脚
time.sleep(0.1)
- 结果
进阶教程二 : 遥控灯
- 硬件准备及接线图
- 示例代码
# -*- coding: utf-8 -*-
#Nezha
#实验效果:展示红外接收功能
import time
from pinpong.board import Board,IRRecv,Pin
Board("nezha").begin()
led = Pin(11, Pin.OUT) #11为引脚号
def ir_recv3(data):
if data==0xbf10:
led.value(1) #输出低电平
print('light on')
elif data == 0xbf0c:
print('light off')
led.value(0)
else:
print('wrong please try again')
ir3 = IRRecv(ir_recv3)
while(1):
time.sleep(0.1)
- 结果
进阶教程三 : 点亮屏幕
- 硬件准备及接线图
- 示例代码
# -*- coding:utf-8 -*-
#NeZha
#实验效果:点亮屏幕(hello world!)
from pinpong.board import Board, Pin
from pinpong.libs.dfrobot_st7789 import ST7789_SPI
Board("nezha").begin()
dc = Pin(24, Pin.OUT)
res = Pin(23, Pin.OUT)
lcd = ST7789_SPI(width=240, height=240, bus_num=1,device_num=0, dc=dc, res=res) #初始化屏幕
lcd.set_font(font="msyh", width = 35, height = 35, kerning = 3, rowledge = 10)
lcd.reset()
lcd.set_blend_mode(lcd.MERGE)#lcd.REPLACE
lcd.fill(lcd.COLOR_BLACK) #填充屏幕为黑色
string = 'hello,world!'
lcd.text(string, 0, 100, lcd.COLOR_WHITE) #在坐标(0,100)处显示文字为白色
- 结果
进阶教程四 : 资料上传
- 硬件准备
哪吒主板 x 1
串口线 x 1
-
步骤
1.网上资料上传到哪吒
apt install wget # 安装wget
wget 链接/压缩包地址 # 用wget命令下载
unzip 压缩包名称 # 若下载的是安装包,可用unzip命令解压
2.本地资料上传
主板接上电源连接好串口线后按照哪吒扩展板wiki中的登录和联网来进行登录操作。
登录上主板后,直接将所需上传的文件拖入Desktop文件夹即可
进阶教程五 : 环境温控风扇
- 硬件准备及接线图
- 示例代码
# -*- coding: utf-8 -*-
#Nezha
#实验效果:使用sht31传感器读取环境温度和湿度,超过设定温度舵机将转动
import time
from pinpong.board import Board,Pin,Servo
from pinpong.libs.dfrobot_sht3x import SHT3x
Board("nezha").begin()
sht31 = SHT3x(iic_addr = 0x45)
s1 = Servo(Pin(3))
while sht31.begin() != 0:
print("The initialization of the chip is failed, please confirm whether the chip connection is correct")
time.sleep(1)
print("The chip serial number = %d "%sht31.read_serial_number())
if sht31.soft_reset() == False:
print("Failed to reset the chip")
while True:
print("\n-------------------------------------------")
print("environment temperature(°C): %f C"%sht31.get_temperature_C())
if sht31.get_temperature_C()>25:
s1.write_angle(60) #控制舵机转到60度位置
time.sleep(1)
s1.write_angle(120) #控制舵机转到120度位置
time.sleep(1)
s1.write_angle(180) #控制舵机转到180度位置
time.sleep(1)
else:
s1.write_angle(0) #控制舵机转到0度位置
time.sleep(1)
- 结果
进阶教程六 : 距离报警器
- 硬件准备及接线图
- 示例代码
# -*- coding:utf-8 -*-
#NeZha
#实验现象:超声波测距报警
import time
from pinpong.board import Board,Pin
from pinpong.libs.dfrobot_urm09 import URM09 #从libs中导入URM09库
Board("nezha").begin()
buzzer = Pin(6, Pin.OUT) #6为引脚号
urm = URM09(i2c_addr=0x11) #初始化传感器,设置I2C地址
urm.set_mode_range(urm._MEASURE_MODE_AUTOMATIC ,urm._MEASURE_RANG_500) #设置URM09模式为自动检测,最大测量距离500cm
while True:
dist = urm.distance_cm() #读取距离数据,单位厘米(cm)
print("Distance is %d cm "%dist)
if dist < 20:
buzzer.value(1)
print ("Please stay away!")
if dist > 20:
buzzer.value(0)
print("right distance!")
time.sleep(0.2)
- 结果
靠近超声波传感器,蜂鸣器发出警报声
进阶教程七 : 小区门禁
- 硬件准备及接线图
- 示例代码
# -*- coding:utf-8 -*-
#NeZha
#实验效果:小区门禁, ST7789 TFT屏幕+NFC+舵机+led灯
import time
from pinpong.board import Board, Pin, Servo
from pinpong.libs.dfrobot_st7789 import ST7789_SPI
from pinpong.libs.dfrobot_pn532 import PN532_UART
Board("nezha").begin()
nfc = PN532_UART("/dev/ttyS5")
s1 = Servo(Pin(3))
led = Pin(11, Pin.OUT)
dc = Pin(pin=24, mode=Pin.OUT)
res = Pin(pin=23, mode=Pin.OUT)
lcd = ST7789_SPI(width=240, height=240, bus_num=1,device_num=0, dc=dc, res=res) #初始化屏幕
lcd.set_font(font="msyh", width = 55, height = 35, kerning = 3, rowledge = 10)
lcd.set_blend_mode(lcd.REPLACE)
lcd.fill(lcd.COLOR_BLACK) #填充屏幕为黑色
led.value(0) #初始化led灯
_uid = ['0x9033537b'] #录入的uid
while not nfc.begin():
print("initial NFC failure")
time.sleep(0.5)
def NFC():
if nfc.scan():
info = nfc.get_information()
if info != None:
temp = list(info.uid)
uid = temp[0] << 24 | temp[1] << 16 | temp[2] << 8 | temp[3]
return str(hex(uid))
return None
lcd.text("请刷卡", 35, 50, lcd.COLOR_RED)
while True:
uid = NFC()
if uid != None and uid in _uid:
lcd.text("正确识别欢迎回家", 0, 120, lcd.COLOR_RED)
s1.write_angle(180)
time.sleep(1)
s1.write_angle(0)
lcd.text("正确识别欢迎回家", 0, 120, lcd.COLOR_BLACK)
elif uid != None:
#print(hex(uid)) #查看uid
lcd.text("识别错误请重试", 0, 120, lcd.COLOR_YELLOW)
led.value(1) #led输出高电平
time.sleep(1)
led.value(0) #led输出高电平
lcd.text("识别错误请重试!", 0, 120, lcd.COLOR_BLACK)
- 结果
进阶教程八 : 电子相册
- 硬件准备及接线图
- 示例代码
# -*- coding:utf-8 -*-
#Nezha
#实验效果:ST7789 TFT屏幕加红外显示图片,红外遥控可选择图片
import sys
import time
from pinpong.board import Board,IRRecv,Pin
from pinpong.libs.dfrobot_st7789 import ST7789_SPI
Board("nezha").begin()
dc = Pin(pin=24, mode=Pin.OUT)
res = Pin(pin=23, mode=Pin.OUT)
lcd = ST7789_SPI(width=240, height=240, bus_num=1,device_num=0, dc=dc, res=res) #初始化屏幕
"""
默认为 MERGE
MERGE: 像素点合并,例如0XF800(红色) 合并 0x07E0(绿色),像素点变为0XF800 | 0x07E0 = 0xFFE0(紫色)
REPLACE:像素点取代,例如0XF800(红色) 取代 0x07E0(绿色),像素点变为0xF800(红色)
"""
#lcd.set_blend_mode(lcd.REPLACE)#使用颜色覆盖模式
'''
font='msyh' 当前只支持微软雅黑字体
size=30 表示中文字体宽度30像素,高度30像素,英文宽度15,高度30
'''
lcd.set_font(font="msyh", width = 30, height = 20, kerning = 0, rowledge = 0)
lcd.set_blend_mode(lcd.REPLACE)
lcd.fill(lcd.COLOR_BLACK) #填充屏幕为黑色
lcd.rect(0,0,119,119,lcd.COLOR_LGRAY)
lcd.picture("1.jpg",10,10,100)
lcd.picture("2.jpg",130,10,100)
lcd.picture("3.jpg",10,130,100)
lcd.picture("4.jpg",130,130,100)
def ir_recv3(data):
global irCode
irCode = data
ir3 = IRRecv(ir_recv3)
cursorPosition = 1
viewMode = 0
irCode = 0x0000
while True:
time.sleep(0.1)
if viewMode == 0:
print('viewMode0')
if irCode == 0xbf06: # >>|
if cursorPosition == 1:
cursorPosition= cursorPosition + 1
lcd.rect(0,0,119,119,lcd.COLOR_BLACK)
lcd.rect(120,0,119,119,lcd.COLOR_LGRAY)
if cursorPosition == 3:
cursorPosition= cursorPosition + 1
lcd.rect(0,120,119,119,lcd.COLOR_BLACK)
lcd.rect(120,120,119,119,lcd.COLOR_LGRAY)
print('you')
irCode = 0x0000
if irCode == 0xbf04: # |<<
if cursorPosition == 2:
cursorPosition= cursorPosition - 1
lcd.rect(120,0,119,119,lcd.COLOR_BLACK)
lcd.rect(0,0,119,119,lcd.COLOR_LGRAY)
if cursorPosition == 4:
cursorPosition= cursorPosition - 1
lcd.rect(120,120,119,119,lcd.COLOR_BLACK)
lcd.rect(0,120,119,119,lcd.COLOR_LGRAY)
print('zuo')
irCode = 0x0000
if irCode == 0xbf09: # VOL-
if cursorPosition == 1:
cursorPosition = cursorPosition + 2
lcd.rect(0,0,119,119,lcd.COLOR_BLACK)
lcd.rect(0,120,119,119,lcd.COLOR_LGRAY)
if cursorPosition == 2:
cursorPosition = cursorPosition + 2
lcd.rect(120,0,119,119,lcd.COLOR_BLACK)
lcd.rect(120,120,119,119,lcd.COLOR_LGRAY)
print('xia')
irCode = 0x0000
if irCode == 0xbf01: # VOL+
if cursorPosition == 3:
cursorPosition = cursorPosition - 2
lcd.rect(0,120,119,119,lcd.COLOR_BLACK)
lcd.rect(0,0,119,119,lcd.COLOR_LGRAY)
if cursorPosition == 4:
cursorPosition = cursorPosition - 2
lcd.rect(120,120,119,119,lcd.COLOR_BLACK)
lcd.rect(120,0,119,119,lcd.COLOR_LGRAY)
print('shang')
irCode = 0x0000
if irCode == 0xbf05: # >||
viewMode = 1
if cursorPosition == 1:
lcd.picture("1.jpg",0,0,239)
if cursorPosition == 2:
lcd.picture("2.jpg",0,0,239)
if cursorPosition == 3:
lcd.picture("3.jpg",0,0,239)
if cursorPosition == 4:
lcd.picture("4.jpg",0,0,239)
print('runstop')
irCode = 0x0000
if viewMode == 1:
print('viewMode1')
if irCode == 0xbf05: # >||
viewMode = 0
lcd.fill(lcd.COLOR_BLACK) #填充屏幕为黑色
lcd.picture("1.jpg",10,10,100)
lcd.picture("2.jpg",130,10,100)
lcd.picture("3.jpg",10,130,100)
lcd.picture("4.jpg",130,130,100)
if cursorPosition == 1:
lcd.rect(0,0,119,119,lcd.COLOR_LGRAY)
if cursorPosition == 2:
lcd.rect(120,0,119,119,lcd.COLOR_LGRAY)
if cursorPosition == 3:
lcd.rect(0,120,119,119,lcd.COLOR_LGRAY)
if cursorPosition == 4:
lcd.rect(120,120,119,119,lcd.COLOR_LGRAY)
print('runstop')
irCode = 0x0000
- 结果
进阶教程九 : 游戏手柄
- 硬件准备及接线图
- 软件解释说明
# -*- coding:utf-8 -*-
#Nezha
#实验效果:走迷宫, ST7789 TFT屏幕加三轴加速度传感器
import sys
import time
import random, math
from pinpong.board import Board,Pin
from pinpong.libs.dfrobot_st7789 import ST7789_SPI
from pinpong.libs.dfrobot_lis2dw12 import LIS2DW12_I2C
Board("nezha").begin()
dc = Pin(pin=24, mode=Pin.OUT)
res = Pin(pin=23, mode=Pin.OUT)
lcd = ST7789_SPI(width=240, height=240, bus_num=1,device_num=0, dc=dc, res=res) #初始化屏幕
lcd.set_blend_mode(lcd.REPLACE)
acce = LIS2DW12_I2C()
def acce_init():
acce.begin()
acce.soft_reset()
acce.set_range(acce.RANGE_2G)
acce.contin_refresh(True)
acce.set_data_rate(acce.RATE_200HZ)
acce.set_filter_path(acce.LPF)
acce.set_filter_bandwidth(acce.RATE_DIV_4)
acce.set_power_mode(acce.CONT_LOWPWRLOWNOISE2_14BIT)
def TFTColor( *color ) :
if len(color) == 1:
return TFTColor((color[0]>>16)&0xff, (color[0]>>8)&0xff, color[0]&0xff)
if len(color) == 3:
return ((color[0] & 0xF8) << 8) | ((color[1] & 0xFC) << 3) | (color[2] >> 3)
return 0
class Maze:
def __init__(self, width, height):
self.width = width
self.height = height
self.map = [[0 if x % 2 == 1 and y % 2 == 1 else 1 for x in range(width)] for y in range(height)]
self.map[1][0] = 0 # 入口
self.map[height - 2][width - 1] = 0 # 出口
self.visited = []
self.dx = [1, 0, -1, 0]
self.dy = [0, -1, 0, 1]
def set_value(self, point, value):
self.map[point[1]][point[0]] = value
def get_value(self, point):
return self.map[point[1]][point[0]]
# 获取坐标(x,y) 的邻居 返回数据结构为:二维数组
def get_neighbor(self, x, y, value):
res = []
for i in range(4):
if 0 < x + self.dx[i] < self.width - 1 and 0 < y + self.dy[i] < self.height - 1 and \
self.get_value([x + self.dx[i], y + self.dy[i]]) == value:
res.append([x + self.dx[i], y + self.dy[i]])
return res
# 获取坐标(x,y) 的邻墙
def get_neighbor_wall(self, point):
return self.get_neighbor(point[0], point[1], 1)
# 获取坐标(x,y) 的邻路
def get_neighbor_road(self, point):
return self.get_neighbor(point[0], point[1], 0)
def deal_with_not_visited(self, point, wall_position, wall_list):
if not [point[0], point[1]] in self.visited:
self.set_value(wall_position, 0)
self.visited.append(point)
wall_list += self.get_neighbor_wall(point)
def generate(self):
start = [1, 1]
self.visited.append(start)
wall_list = self.get_neighbor_wall(start)
while wall_list:
wall_position = random.choice(wall_list)
neighbor_road = self.get_neighbor_road(wall_position)
wall_list.remove(wall_position)
self.deal_with_not_visited(neighbor_road[0], wall_position, wall_list)
self.deal_with_not_visited(neighbor_road[1], wall_position, wall_list)
def is_out_of_index(self, x, y):
return x == 0 or x == self.width - 1 or y == 0 or y == self.height - 1
def is_hit_a_wall(self, x, y):
return self.get_value([x, y]) == 1 or self.is_out_of_index(x, y)
def dfs(self, x, y, path, visited=[]):
if self.is_out_of_index(x, y):
return False
if [x, y] in visited or self.get_value([x, y]) == 1:
return False
visited.append([x, y])
path.append([x, y])
if x == self.width - 2 and y == self.height - 2:
return True
for i in range(4):
if 0 < x + self.dx[i] < self.width - 1 and 0 < y + self.dy[i] < self.height - 1 and \
self.get_value([x + self.dx[i], y + self.dy[i]]) == 0:
if self.dfs(x + self.dx[i], y + self.dy[i], path, visited):
return True
elif not self.is_out_of_index(x, y) and path[-1] != [x, y]:
path.append([x, y])
def dfs_route(self):
path = []
self.dfs(1, 1, path)
ans = [[0, 1]]
for i in range(len(path)):
ans.append(path[i])
if 0 < i < len(path) - 1 and path[i - 1] == path[i + 1]:
ans.append(path[i])
ans.append([width - 1, height - 2])
return ans
def bfs_route(self):
start = {'x': 0, 'y': 1, 'prev': None}
now = start
q = [start]
visited = [[start['x'], start['y']]]
# 1、从起点出发,获取起点周围所有连通的路
# 2、如果该路没有走过,则加入队列 Q,否则跳过 同时记录其前驱节点
while q:
now = q.pop(0)
# 结束
if now['x'] == self.width - 2 and now['y'] == self.height - 2:
break
roads = my_maze.get_neighbor_road([now['x'], now['y']])
for road in roads:
if not road in visited:
visited.append(road)
q.append({'x': road[0], 'y': road[1], 'prev': now})
ans = []
while now:
ans.insert(0, [now['x'], now['y']])
now = now['prev']
ans.append([width - 1, height - 2])
return ans
class Controller:
def __init__(self):
pass
def get_btn(self):
acc = acce.read_acc()
if acc.x < -150: return 0
if acc.x > 250: return 2
if acc.y > 250: return 1
if acc.y < -150: return 3
return -1
class App:
def __init__(self):
self.is_hit_a_wall=my_maze.is_hit_a_wall
self.draw_maze = False
self.is_game_over = False
self.step = 0
self.time = 0
self.role = [0, 1, 0, 1]
def run(self):
if not self.draw_maze:
self.draw()
self.time = int(time.time())
return
btn = controller.get_btn()
if btn == -1:
return
if not self.is_game_over:
next = [self.role[2], self.role[3]]
if btn == 0:
next[1] -= 1
if btn == 1:
next[0] += 1
if btn == 2:
next[1] += 1
if btn == 3:
next[0] -= 1
if self.game_over(next) or not self.is_hit_a_wall(next[0], next[1]):
self.role[0] = self.role[2]
self.role[1] = self.role[3]
self.role[2] = next[0]
self.role[3] = next[1]
self.step += 1
self.draw()
if self.is_game_over:
_time = int(time.time())
lcd.set_font(font="msyh", width = 50, height = 30, kerning = 3, rowledge = 10)
lcd.text("游戏结束", 15, 70, TFTColor(0xFF0000))
lcd.set_font(font="msyh", width = 30, height = 20, kerning = 2, rowledge = 10)
lcd.text(str(self.step)+str("步"), 90, 110, TFTColor(0xFF0000))
lcd.set_font(font="msyh", width = 30, height = 20, kerning = 2, rowledge = 10)
lcd.text(str(_time-self.time)+str("秒"), 90, 140, TFTColor(0xFF0000))
def draw(self):
# draw maze
if not self.draw_maze:
lcd.set_flush_mode(lcd.FULL)
for x in range(height):
for y in range(width):
lcd.fill_rect(start_x + y * pixel, start_y + x * pixel, int(pixel), int(pixel), wall_color if my_maze.map[x][y] else back_color)
lcd.fill_rect(0, start_y+pixel, pixel + start_x, pixel, start_point_color)
lcd.fill_rect(start_x + (width - 1) * pixel, start_y + (height - 2) * pixel, 240 - (start_x + (width - 1) * pixel), pixel, end_point_color)
lcd.fill_circle(int(start_x+self.role[2]*pixel+pixel/2), int(start_y+self.role[3]*pixel+pixel/2), int(role_size/2), role_color)
lcd.show()
self.draw_maze = True
if self.role[0] != self.role[2] or self.role[1] != self.role[3]:
lcd.set_flush_mode(lcd.PART)
lcd.fill_circle(int(start_x+self.role[0]*pixel+pixel/2), int(start_y+self.role[1]*pixel+pixel/2), int(role_size/2), back_color)
lcd.fill_circle(int(start_x+self.role[2]*pixel+pixel/2), int(start_y+self.role[3]*pixel+pixel/2), int(role_size/2), role_color)
def game_over(self, point):
self.is_game_over = point[0] > width-2 and point[1] == height-2
return self.is_game_over
pixel = 10 # 格子大小
start_x , start_y = 5, 5 # 偏移坐标
width, height = 23, 23 # 格子数量
role_size = 9 # 角色大小
start_point_color, end_point_color = TFTColor(0xFAF088), TFTColor(0xFAF088)
back_color, role_color, wall_color = TFTColor(0xFAF088), TFTColor(0x206AE2), TFTColor(0x8DC743)
acce_init() #初始化三轴加速度传感器
lcd.fill(wall_color) #填充屏幕为黑色
my_maze = Maze(width, height)
my_maze.generate()
controller = Controller()
app = App()
while True:
app.run()
time.sleep(0.1)
- 结果
进阶教程十 : 网上天气站
- 硬件准备及接线图
- 示例代码
# -*- coding:utf-8 -*-
#Nezha
#实验效果:ST7789 TFT屏幕显示成都天气
import requests
from pinpong.board import Board, Pin
from pinpong.libs.dfrobot_st7789 import ST7789_SPI
Board("nezha").begin()
dc = Pin(pin=24, mode=Pin.OUT)
res = Pin(pin=23, mode=Pin.OUT)
lcd = ST7789_SPI(width=240, height=240, bus_num=1,device_num=0, dc=dc, res=res) #初始化屏幕
lcd.set_font(font="msyh", width = 30, height = 20, kerning = 0, rowledge = 0)
lcd.fill(lcd.COLOR_BLACK) #填充屏幕为黑色
"""
默认为 MERGE
MERGE: 像素点合并,例如0XF800(红色) 合并 0x07E0(绿色),像素点变为0XF800 | 0x07E0 = 0xFFE0(紫色)
REPLACE:像素点取代,例如0XF800(红色) 取代 0x07E0(绿色),像素点变为0xF800(红色)
"""
#lcd.set_blend_mode(lcd.REPLACE)#使用颜色覆盖模式
'''
font='msyh' 当前只支持微软雅黑字体
size=30 表示中文字体宽度30像素,高度30像素,英文宽度15,高度30
'''
'''
COLOR_NAVY = 0x000F # 深蓝色
COLOR_DGREEN = 0x03E0 # 深绿色
COLOR_DCYAN = 0x03EF # 深青色
COLOR_MAROON = 0x7800 # 深红色
COLOR_PURPLE = 0x780F # 紫色
COLOR_OLIVE = 0x7BE0 # 橄榄绿
COLOR_LGRAY = 0xC618 # 灰白色
COLOR_DGRAY = 0x7BEF # 深灰色
COLOR_CYAN = 0x07FF # 青色
COLOR_RED = 0xF800 # 红色
COLOR_MAGENTA = 0xF81F # 品红
COLOR_YELLOW = 0xFFE0 # 黄色
COLOR_BLACK = 0x0000 # 黑色
COLOR_BLUE = 0x001F # 蓝色
COLOR_GREEN = 0x07E0 # 绿色
COLOR_WHITE = 0xFFFF # 白色
'''
r = requests.get('http://www.weather.com.cn/data/sk/101270101.html')
r.encoding='utf-8'
string = r.json()
string1 = 'Id : ' + string['weatherinfo']['cityid']
string2 = 'City : ' + string['weatherinfo']['city']
string3 = 'Temp : ' + string['weatherinfo']['temp'] + '℃'
string4 = 'WD : ' + string['weatherinfo']['WD']
string5 = 'WS : ' + string['weatherinfo']['WS']
string6 = 'SD : ' + string['weatherinfo']['SD']
string7 = 'AP : ' + string['weatherinfo']['AP']
lcd.text(string1, 0, 5, lcd.COLOR_MAGENTA) #打印文字(text,x,y,color)
lcd.text(string2, 0, 30, lcd.COLOR_YELLOW) #打印文字(text,x,y,color)
lcd.text(string3, 0, 55, lcd.COLOR_RED) #打印文字(text,x,y,color)
lcd.text(string4, 0, 80, lcd.COLOR_WHITE) #打印文字(text,x,y,color)
lcd.text(string5, 0, 105, lcd.COLOR_BLUE) #打印文字(text,x,y,color)
lcd.text(string6, 0, 130, lcd.COLOR_GREEN) #打印文字(text,x,y,color)
lcd.text(string7, 0, 155, lcd.COLOR_CYAN) #打印文字(text,x,y,color)
- 结果
教程十一 :智能门锁
- 硬件准备及接线图
- 软件解释说明
# -*- coding: utf-8 -*-
#Nezha
#实验效果:Esay Iot远程控制舵机
import siot #使用siot需连上wifi
import time
from pinpong.board import Board,Pin,Servo
Board("nezha").begin()
s1 = Servo(Pin(3)) #将Pin传入Servo中初始化舵机引脚
# 事件回调函数
def on_message_callback(client, userdata, msg):
angle = int(msg.payload)
if 0 <= angle <= 180:
s1.write_angle(angle)
siot.init(client_id="",server="iot.dfrobot.com.cn",port=1883,user="F2BvTZ8Mg",password="KhfDoWUMRz")
siot.connect() #连接
siot.loop() #保持连接状态
siot.set_callback(on_message_callback) #设置回调函数
siot.getsubscribe(topic="Ae0xHqXMR") #订阅topic
while True:
time.sleep(1)
-
步骤
1. 打开网页Easy IOT,进行注册,将用户名与密码填入程序中
2.1 新增设备
2.2 打开设备向主机发送消息控制舵机旋转(0~180°)
使用说明
使用过程中有什么注意事项
更多
更多问题及有趣的应用,可以访问论坛进行查阅或发帖!