好梦成空

  • 2024-06-20
  • 加入了学习《Digi-Key: Follow Me 系列(1) 直播回放及答疑记录》,观看 Raspberry Pi Pico W 使用入门

  • 加入了学习《Digi-Key: Follow Me 系列(2) 直播回放》,观看 Adafruit ESP32-S3 TFT Feather开发板使用入门

  • 2024-04-27
  • 加入了学习《follow me 第二期作品视频提交》,观看 follow me 第二期作品视频提交

  • 2024-04-23
  • 回复了主题帖: Python 综合手册

    下载学习

  • 2023-11-22
  • 加入了学习《【得捷电子Follow me第2期】任务合集(可选任务:24颗流水灯)》,观看 【得捷电子Follow me第2期】任务合集(可选任务:24颗流水灯动画)

  • 2023-11-21
  • 回复了主题帖: 《我的python世界》电子书

    谢谢分享  

  • 2023-11-12
  • 加入了学习《【得捷电子Follow me第2期】任务视频》,观看 【得捷电子Follow me第2期】任务视频

  • 2023-11-11
  • 加入了学习《2022得捷创新设计大赛-USB 便携式可编程仪表》,观看 2022 得捷创新设计大赛-USB 便携式可编程仪表(多功能USB电源)

  • 加入了学习《罗伊斯争第一_followme第二期_任务提交》,观看 罗伊斯争第一_followme第二期_任务提交

  • 加入了学习《follow me 第二期作品视频提交》,观看 ADC光、传感器

  • 加入了学习《follow me 第二期作品视频提交》,观看 任务4

  • 加入了学习《follow me 第二期作品视频提交》,观看 任务3

  • 加入了学习《follow me 第二期作品视频提交》,观看 任务2

  • 加入了学习《follow me 第二期作品视频提交》,观看 任务1

  • 上传了资料: follow me第二期任务代码提交

  • 2023-11-10
  • 加入了学习《【得捷电子Follow me第2期】DIY天气时钟 》,观看 【得捷电子Follow me第2期】DIY天气时钟

  • 加入了学习《【得捷电子Follow me第2期】任务项目简介》,观看 【得捷电子Follow me第2期】任务项目简

  • 加入了学习《【得捷电子Follow me第2期】玩转Adafruit ESP32-S3 TFT Feather 》,观看 【得捷电子Follow me第2期】玩转Adafruit ESP32-S3 TFT Feather 任务提交视频

  • 2023-11-04
  • 发表了主题帖: 得捷电子 Follow me 第2期任务提交汇总

    感谢得捷电子和eeworld 举办的这次活动,首次发帖写的有些混乱见谅 以下是本次活动的汇总 部分一 视频链接:https://training.eeworld.com.cn/video/38269   部分二   一、准备工作 (1)开发板详情 本次活动使用的是adafruit的esp32s3_feather_TFT,从官方页面https://learn.adafruit.com/adafruit-esp32-s3-tft-feather/overview可以了解到 4 MB 闪存和 2 MB PSRAM,自带一个240*135的TFT屏幕、WIFI、蓝牙和板载ws2812b灯珠,官方circuitpy对板子做好了预定义,可以很方便的使用,下面是它的引脚图 使用circuipython在vscode上完成此次活动 (1)烧入cpy固件 板子cpy固件下载地址: 双击rst按钮进入U盘烧入模式,板子显示如下界面 并且会识别到一个磁盘  将cpy官网上下载的板子对应UF2固件拖到磁盘里就自动会刷入   (2)搭建编程环境 在vscode安装好circuitpython的插件,以及python插件,使用vscode可以很方便的导入需要的模组,还有代码补全等功能   二、任务部分 任务1:控制屏幕显示中文 总代码 #任务1 import time,board,displayio from adafruit_display_text import label from adafruit_bitmap_font import bitmap_font display = board.DISPLAY font_cn_file = "font/sanjiruosixingkai_m_16.pcf" font_cn = bitmap_font.load_font(font_cn_file) text_cn1 = "生年不满百\n常怀千岁忧\n昼短苦夜长\n何不秉烛游" text_cn2 = "为乐当及时\n何能待来兹\n愚者爱惜费\n但为后世嗤" text_group = displayio.Group( scale=1, x=0, y=0, ) text_cn_area1 = label.Label(font_cn, text=text_cn1, color=0x00FF00, x=0, y=10) text_cn_area2 = label.Label(font_cn, text=text_cn2, color=0xFF0000, x=120, y=10) text_group.append(text_cn_area1) text_group.append(text_cn_area2) display.show(text_group) time.sleep(10) --------------------------------------------------- 1)导入模组和字体 import time,board,displayio from adafruit_display_text import label from adafruit_bitmap_font import bitmap_font 其中adafruit_display_text是用来创建文本标签,adafruit_bitmap_font  导入点阵字体, bdf字体文件生成,先去网上下载好ttf字体 在通过字符集工具FontSmaller 2.0和Fontmin ,只保留要的字符,能大大减小字体文件大小  再通过fontforge 导出bdf格式的字体  ttf转bdf格式教程:https://learn.adafruit.com/custom-fonts-for-pyportal-circuitpython-display/conversion 使用到了 adafruit_display_text ,adafruit_bitmap_font 等模组 ,显示中文需要导入包含中文字符集的点阵字体 2)设置屏幕文本字体以及文本内容 display = board.DISPLAY font_cn_file = "font/sanjiruosixingkai_m_16.pcf" font_cn = bitmap_font.load_font(font_cn_file) text_cn1 = "生年不满百\n常怀千岁忧\n昼短苦夜长\n何不秉烛游" text_cn2 = "为乐当及时\n何能待来兹\n愚者爱惜费\n但为后世嗤" text_group = displayio.Group( scale=1, x=0, y=0, ) text_cn_area1 = label.Label(font_cn, text=text_cn1, color=0x00FF00, x=0, y=10) text_cn_area2 = label.Label(font_cn, text=text_cn2, color=0xFF0000, x=120, y=10) text_group.append(text_cn_area1) text_group.append(text_cn_area2) 3)输出显示 display.show(text_group) time.sleep(10) 执行效果:     任务2:网络功能使用(必做任务)   (1)配置setting.toml 文件 #配置wifi id名称 CIRCUITPY_WIFI_SSID = "ovq" #配置wifi 密码 CIRCUITPY_WIFI_PASSWORD = "略" 使用circuitpython联网十分方便,只要在circuitpython磁盘下的settings.toml中输入wifi 名称(SSID)和wifi 密码(password),就能进行联网,板子重启后板子自动就会联网,板子联网成功会在TFT屏幕左上角显示ip地址  (2)创建热点并测试联网成功 import wifi wifi.radio.start_ap('ESP32_s3_Feather_TFT', '00000000') # SPDX-FileCopyrightText: 2020 Brent Rubell for Adafruit Industries # SPDX-License-Identifier: MIT import os import ipaddress import ssl import wifi import socketpool import adafruit_requests # URLs to fetch from TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html" JSON_QUOTES_URL = "https://www.adafruit.com/api/quotes.php" JSON_STARS_URL = "https://api.github.com/repos/adafruit/circuitpython" print("ESP32-S2 WebClient Test") print(f"My MAC address: {[hex(i) for i in wifi.radio.mac_address]}") print("Available WiFi networks:") for network in wifi.radio.start_scanning_networks(): print("\t%s\t\tRSSI: %d\tChannel: %d" % (str(network.ssid, "utf-8"), network.rssi, network.channel)) wifi.radio.stop_scanning_networks() print(f"Connecting to {os.getenv('CIRCUITPY_WIFI_SSID')}") wifi.radio.connect(os.getenv("CIRCUITPY_WIFI_SSID"), os.getenv("CIRCUITPY_WIFI_PASSWORD")) print(f"Connected to {os.getenv('CIRCUITPY_WIFI_SSID')}") print(f"My IP address: {wifi.radio.ipv4_address}") ping_ip = ipaddress.IPv4Address("8.8.8.8") ping = wifi.radio.ping(ip=ping_ip) # retry once if timed out if ping is None: ping = wifi.radio.ping(ip=ping_ip) if ping is None: print("Couldn't ping 'google.com' successfully") else: # convert s to ms print(f"Pinging 'google.com' took: {ping * 1000} ms") pool = socketpool.SocketPool(wifi.radio) requests = adafruit_requests.Session(pool, ssl.create_default_context()) print(f"Fetching text from {TEXT_URL}") response = requests.get(TEXT_URL) print("-" * 40) print(response.text) print("-" * 40) print(f"Fetching json from {JSON_QUOTES_URL}") response = requests.get(JSON_QUOTES_URL) print("-" * 40) print(response.json()) print("-" * 40) print() print(f"Fetching and parsing json from {JSON_STARS_URL}") response = requests.get(JSON_STARS_URL) print("-" * 40) print(f"CircuitPython GitHub Stars: {response.json()['stargazers_count']}") print("-" * 40) print("Done") 在上一步配置好seting.toml就可以联网了,为了验证联网成功,用了adaftuit 官网的wifi测试例程https://learn.adafruit.com/adafruit-esp32-s3-tft-feather/circuitpython-internet-test  来测试验证的确连上网了,例程进行访问网址并在屏幕打印出接受内容。 (3)创建热点 import wifi wifi.radio.start_ap('ESP32_s3_Feather_TFT', '00000000') 在开头加上了创建热点 (asses point)的语句,热点名字设置为活动板子的名称   任务3:控制WS2812B(必做任务) 总代码 import board,time,digitalio import neopixel color_dict ={0: (255, 0, 0), 1: (0, 255, 0), 2: (0, 0, 255), 3: (0, 255, 255), 4: (255, 0, 255), 5: (255, 255, 0), 6: (255, 255, 255), 7: (0, 0, 0) } button = digitalio.DigitalInOut(board.BUTTON) button.switch_to_input(pull=digitalio.Pull.UP) power = digitalio.DigitalInOut(board.NEOPIXEL_POWER) power.direction = digitalio.Direction.OUTPUT power.value = 1 neoled = neopixel.NeoPixel(board.NEOPIXEL, 1) neoled.brightness = 0.5 color = 0 status = 1 while True: if button.value : if status: status = 0 color += 1 if color>=8: color = 0 else : status = 1 neoled.fill(color_dict[color]) (1)导入模块并且定义红绿蓝色青紫黄白黑(关)的颜色数组 使用neopixel就可以控制板载炫彩灯珠ws2818b的颜色了,导入模组adafruit_led_animation还可以实现更多的效果 import board,time,digitalio import neopixel color_dict ={0: (255, 0, 0), 1: (0, 255, 0), 2: (0, 0, 255), 3: (0, 255, 255), 4: (255, 0, 255), 5: (255, 255, 0), 6: (255, 255, 255), 7: (0, 0, 0) } (2)定义neopixel neopixel_power button对象 定义neopixel neopixel_power button,设置灯珠亮度为0.3 button = digitalio.DigitalInOut(board.BUTTON) button.switch_to_input(pull=digitalio.Pull.UP) power = digitalio.DigitalInOut(board.NEOPIXEL_POWER) power.direction = digitalio.Direction.OUTPUT power.value = 1 neoled = neopixel.NeoPixel(board.NEOPIXEL, 1) neoled.brightness = 0.3 (3)循环检测按键输入以及点亮灯珠 while True: if button.value : if status: status = 0 color += 1 if color>=8: color = 0 else : status = 1 neoled.fill(color_dict[color]) 执行效果:     任务4:日历&时钟(选做任务) 日历功能由先显示时钟界面、联网获取信息、根据获取的信息对标签文本进行修改更新组成。加了一个简陋的闹钟功能,通过板载boot按键进入闹钟设置,通过引脚的电容触摸功能对小时和分钟增加,当返回的时间与闹钟时间相等时,led点亮,时间过了熄灭。 #---1------时钟界面显示部分 联网获取信息、对标签文本进行修改来更新信息 import board,time,displayio#内置库 import adafruit_imageload #图片加载 from adafruit_display_text import label from adafruit_bitmap_font import bitmap_font h = 20 m = 50 #----配置屏幕显示设置 display = board.DISPLAY def display_interface1(): global group1,weather_label,temperature_label,time_label,week_label,date_label #---导入背景图片 image, palette = adafruit_imageload.load("/pic/picture.png")# 加载图片 palette.make_transparent(0)# 关闭透明设置 #---导入字体 font22 = bitmap_font.load_font("/font/22.bdf") font33 = bitmap_font.load_font("/font/33.bdf") font66 = bitmap_font.load_font("/font/662.bdf") color = 0x0076A3 #--设置显示 group1 = displayio.Group() grid = displayio.TileGrid(image, pixel_shader=palette) group1.append(grid) display.show(group1)#显示背景图 #设置文字标签(日期、星期、时间、温度、天气) #设置日期标签字体、颜色、x,y轴坐标,然后添加到图像组 date_label = label.Label(font22, text="23年11月8日", color=color) date_label.x = 6 date_label.y = 15 group1.append(date_label) week_label = label.Label(font22, text="星期三", color=color) week_label .x = 6 week_label .y = 40 group1.append(week_label ) #设置时间标签字体、颜色、x,y轴坐标,然后添加到图像组 time_label = label.Label(font66, text="11:50", color=color) time_label.x = 85 time_label.y = 70 group1.append(time_label) #设置温度标签字体、颜色、x,y轴坐标,然后添加到图像组 temperature_label = label.Label(font33, text="29°", color=color) temperature_label.x = 200 temperature_label.y = 22 group1.append(temperature_label) #设置天气标签字体、颜色、x,y轴坐标,然后添加到图像组 weather_label = label.Label(font33, text="大雨", color=color) weather_label.x = 6 weather_label.y = 115 group1.append(weather_label) def display_interface2(): global group2,clock_time_label_hour,font66,clock_time_label_minute font22 = bitmap_font.load_font("/font/22.bdf") font33 = bitmap_font.load_font("/font/33.bdf") font66 = bitmap_font.load_font("/font/662.bdf") font36 = bitmap_font.load_font("/font/36.bdf") clock_time_label_hour = label.Label(font66, text=str(h), color=0x0076A3) clock_time_label_hour.x = 75 clock_time_label_hour.y = 80 clock_time_label_minute = label.Label(font66, text=str(m), color=0x0076A3) clock_time_label_minute.x = 150 clock_time_label_minute.y = 80 clock_colon = label.Label(font66, text=":", color=0x0076A3) clock_colon.x = 120 clock_colon.y = 80 clock_text = label.Label(font36, text="设置闹钟", color=0x0076A3) clock_text.x = 60 clock_text.y = 20 group2 = displayio.Group() group2.append(clock_time_label_hour) group2.append(clock_time_label_minute) group2.append(clock_text) group2.append(clock_colon) display_interface1() display_interface2() # 显示加上文本标签后的图像组 display.show(group1) #display.show(group2) import touchio,digitalio button = digitalio.DigitalInOut(board.BUTTON) button.switch_to_input(pull=digitalio.Pull.UP) touch_add = touchio.TouchIn(board.A4) touch_minus = touchio.TouchIn(board.D12) button_status = 0 def set_clock(): global h ,m,button_status,button_numberS button_number = 0 if not button.value: while button_number <2: if not button.value : #如果按键按下 if not button_status: #如果按键首次按下 button_status = 1 button_number += 1 if button_number > 2: button_number = 0 else : button_status = 0 if button_number == 1: display.show(group2) if touch_add.value: time.sleep(1) h += 1 if touch_minus.value: time.sleep(1) m += 1 clock_time_label_hour.text = str(h) clock_time_label_minute.text = str(m) display.show(group2) if h > 23: h = 0 if m > 59: m = 0 led = digitalio.DigitalInOut(board.LED) led.direction = digitalio.Direction.OUTPUT t = time.localtime() def action_clock(): if (m == t.tm_min and h == t.tm_hour): led.value = 1 else: led.value = 0 #-----------2----------- #---------------------------联网 import wifi,os ssid = os.getenv("CIRCUITPY_WIFI_SSID") password = os.getenv("CIRCUITPY_WIFI_PASSWORD") wifi.radio.connect(ssid, password) #-----从天气网址获取信息 #创建套接字池 import ssl #内置库 import socketpool,adafruit_ntp,adafruit_requests#需要导入 pool = socketpool.SocketPool(wifi.radio) ntp = adafruit_ntp.NTP(pool, tz_offset=8, server="ntp.aliyun.com") # 使用ntp时间更新时间 import rtc rtc.RTC().datetime = ntp.datetime #数据转换成星期文本 def get_dateweek(dateweek): if (dateweek == 0): return "星期一" elif (dateweek == 1): return "星期二" elif (dateweek == 2): return "星期三" elif (dateweek == 3): return "星期四" elif (dateweek == 4): return "星期五" elif (dateweek == 5): return "星期六" elif (dateweek == 6): return "星期日" # 初始化requests对象 pool = socketpool.SocketPool(wifi.radio) requests = adafruit_requests.Session(pool, ssl.create_default_context()) #--------------------获取天气 def get_weather(): # 设置url city = "350500" #泉州洛江区城市id key = "879ce07226836f672b80f1414a065e2e" #高德api key getweather_url = "https://restapi.amap.com/v3/weather/weatherInfo?city=" + city + "&key=" + key # 获取天气json数据 response = requests.get(getweather_url) json_resp = response.json() response.close()# 关闭连接 # 解析json数据,返回温度和天气信息 for da in json_resp["lives"]: return da["temperature"], da["weather"] # 先创建一个status变量,用来在设备启动时获取天气信息 status = "boot" # 主循环 while True: # 每秒获取一次本地RTC时间 t = time.localtime() # 开机初次进入或者本地RTC时间的分钟属性为0时,更新一次日期标签和天气标签 if (status == "boot" or t.tm_min == 0): # 更新日期标签 date_label.text = "23年%d月%d日" % (t.tm_mon, t.tm_mday) week_label .text = get_dateweek(t.tm_wday) # 获取天气信息 str_t, str_tz = get_weather() # 更新温度标签 temperature_label.text = "%s°" % (str_t) # 更新天气标签 weather_label.text = str_tz status = "updated" #表示设备已经设置过时间里 # 每隔1秒 更新一次时钟标签,刷新时间 if (t.tm_sec % 2 == 0): time_label.text = "%02d:%02d" % ( t.tm_hour, t.tm_min) time_label.color = 0x000000 else: time_label.text = "%02d:%02d" % ( t.tm_hour, t.tm_min) time_label.color = 0x0076A3 # 刷新屏幕 set_clock() action_clock() display.show(group1) # 休眠1秒 time.sleep(1) (1)准备工作 用pixso 制作设计稿 用pixso大致做了日历时钟的布局设计 在隐藏文本标签后导出压缩图片     高德天气api申请     (2)代码 显示界面设置 import board,time,displayio#内置库 import adafruit_imageload #图片加载 from adafruit_display_text import label from adafruit_bitmap_font import bitmap_font 其中adafruit_display_text是用来显示文本标签,adafruit_bitmap_font  导入点阵字体,import adafruit_imageload 图片加载。 def display_interface1(): global group1,weather_label,temperature_label,time_label,week_label,date_label #---导入背景图片 image, palette = adafruit_imageload.load("/pic/picture.png")# 加载图片 palette.make_transparent(0)# 关闭透明设置 #---导入字体 font22 = bitmap_font.load_font("/font/22.bdf") font33 = bitmap_font.load_font("/font/33.bdf") font66 = bitmap_font.load_font("/font/662.bdf") color = 0x0076A3 #--设置显示 group1 = displayio.Group() grid = displayio.TileGrid(image, pixel_shader=palette) group1.append(grid) display.show(group1)#显示背景图 #设置文字标签(日期、星期、时间、温度、天气) #设置日期标签字体、颜色、x,y轴坐标,然后添加到图像组 date_label = label.Label(font22, text="23年11月8日", color=color) date_label.x = 6 date_label.y = 15 group1.append(date_label) week_label = label.Label(font22, text="星期三", color=color) week_label .x = 6 week_label .y = 40 group1.append(week_label ) #设置时间标签字体、颜色、x,y轴坐标,然后添加到图像组 time_label = label.Label(font66, text="11:50", color=color) time_label.x = 85 time_label.y = 70 group1.append(time_label) #设置温度标签字体、颜色、x,y轴坐标,然后添加到图像组 temperature_label = label.Label(font33, text="29°", color=color) temperature_label.x = 200 temperature_label.y = 22 group1.append(temperature_label) #设置天气标签字体、颜色、x,y轴坐标,然后添加到图像组 weather_label = label.Label(font33, text="大雨", color=color) weather_label.x = 6 weather_label.y = 115 group1.append(weather_label) def display_interface2(): global group2,clock_time_label_hour,font66,clock_time_label_minute font22 = bitmap_font.load_font("/font/22.bdf") font33 = bitmap_font.load_font("/font/33.bdf") font66 = bitmap_font.load_font("/font/662.bdf") font36 = bitmap_font.load_font("/font/36.bdf") clock_time_label_hour = label.Label(font66, text=str(h), color=0x0076A3) clock_time_label_hour.x = 75 clock_time_label_hour.y = 80 clock_time_label_minute = label.Label(font66, text=str(m), color=0x0076A3) clock_time_label_minute.x = 150 clock_time_label_minute.y = 80 clock_colon = label.Label(font66, text=":", color=0x0076A3) clock_colon.x = 120 clock_colon.y = 80 clock_text = label.Label(font36, text="设置闹钟", color=0x0076A3) clock_text.x = 60 clock_text.y = 20 group2 = displayio.Group() group2.append(clock_time_label_hour) group2.append(clock_time_label_minute) group2.append(clock_text) group2.append(clock_colon) display_interface1() display_interface2() 设置了两个显示界面 一个用于正常显示 另一个是设置闹钟 import touchio,digitalio button = digitalio.DigitalInOut(board.BUTTON) button.switch_to_input(pull=digitalio.Pull.UP) touch_add = touchio.TouchIn(board.A4) touch_minus = touchio.TouchIn(board.D12) button_status = 0 导入模组touchio,引脚电容触摸输入设置   官方教程https://learn.adafruit.com/adafruit-esp32-s3-tft-feather/capacitive-touch def set_clock(): global h ,m,button_status,button_numberS button_number = 0 if not button.value: while button_number <2: if not button.value : #如果按键按下 if not button_status: #按键时松开后再按下的 button_status = 1 button_number += 1 if button_number > 2: button_number = 0 else : button_status = 0 if button_number == 1: display.show(group2) if touch_add.value: time.sleep(1) h += 1 if touch_minus.value: time.sleep(1) m += 1 clock_time_label_hour.text = str(h) clock_time_label_minute.text = str(m) display.show(group2) if h > 23: h = 0 if m > 59: m = 0 led = digitalio.DigitalInOut(board.LED) led.direction = digitalio.Direction.OUTPUT t = time.localtime() def action_clock(): if (m == t.tm_min and h == t.tm_hour): led.value = 1 else: led.value = 0 闹钟设置功能和闹钟动作功能,h,m分别是设置的小时和分钟,button_status 是用来表示松开后再按下的,避免长按不停执行的情况,时间到了led点亮,一分钟后熄灭。 #---------------------------联网 import wifi,os ssid = os.getenv("CIRCUITPY_WIFI_SSID") password = os.getenv("CIRCUITPY_WIFI_PASSWORD") wifi.radio.connect(ssid, password) #-----从天气网址获取信息 #创建套接字池 import ssl #内置库 import socketpool,adafruit_ntp,adafruit_requests#需要导入 pool = socketpool.SocketPool(wifi.radio) ntp = adafruit_ntp.NTP(pool, tz_offset=8, server="ntp.aliyun.com") # 使用ntp时间更新时间 import rtc rtc.RTC().datetime = ntp.datetime #返回数据转换成星期文本 def get_dateweek(dateweek): if (dateweek == 0): return "星期一" elif (dateweek == 1): return "星期二" elif (dateweek == 2): return "星期三" elif (dateweek == 3): return "星期四" elif (dateweek == 4): return "星期五" elif (dateweek == 5): return "星期六" elif (dateweek == 6): return "星期日" # 初始化requests对象 pool = socketpool.SocketPool(wifi.radio) requests = adafruit_requests.Session(pool, ssl.create_default_context()) #--------------------获取天气 def get_weather(): # 设置url city = "350500" #泉州洛江区城市id key = "879ce07226836f672b80f1414a065e2e" #高德api key getweather_url = "https://restapi.amap.com/v3/weather/weatherInfo?city=" + city + "&key=" + key # 获取天气json数据 response = requests.get(getweather_url) json_resp = response.json() response.close()# 关闭连接 # 解析json数据,返回温度和天气信息 for da in json_resp["lives"]: return da["temperature"], da["weather"] # 先创建一个status变量,用来在设备启动时获取天气信息 status = "boot" # 主循环 while True: # 每秒获取一次本地RTC时间 t = time.localtime() # 开机初次进入或者本地RTC时间的分钟属性为0时,更新一次日期标签和天气标签 if (status == "boot" or t.tm_min == 0): # 更新日期标签 date_label.text = "23年%d月%d日" % (t.tm_mon, t.tm_mday) week_label .text = get_dateweek(t.tm_wday) # 获取天气信息 str_t, str_tz = get_weather() # 更新温度标签 temperature_label.text = "%s°" % (str_t) # 更新天气标签 weather_label.text = str_tz status = "updated" #表示设备已经设置过时间里 # 每隔1秒更新一次时钟标签,刷新时间 if (t.tm_sec % 2 == 0): time_label.text = "%02d:%02d" % ( t.tm_hour, t.tm_min) time_label.color = 0x000000 else: time_label.text = "%02d:%02d" % ( t.tm_hour, t.tm_min) time_label.color = 0x0076A3 # 刷新屏幕 set_clock() action_clock() display.show(group1) # 休眠1秒 time.sleep(1) 导入相关模块,其中wifi: WiFi设备模块ssl: SSL证书处理模块socketpool: socket处理模块adafruit_requests:网络请求处理模块 从seting.toml中获取wiff名称和密码并联网,创建套接字池,adafruit_ntp.NTP()初始化ntp,使用ntp时间更新小时和分钟,get_weather(),get_dateweek(),将返回的数据转换成天气温度日期等字符,while True循环更新所有的文本标签并显示,以及设置时钟和执行时钟动作。 5:使用ADC和光传感器 和板子一起凑单的买的ADC、光传感器、树莓派pico和pico H 。下单的时候草率了 ,本来想买pico w,买成两个相似的了 。这里用到了ADC、光传感器这两个器件,ADC连接了一个应变式传感器,接线按惠斯通桥布置。获取亮度和并在屏幕上显示。在adafruit网址上有这两个器件的详情页https://learn.adafruit.com/adafruit-nau7802-24-bit-adc-stemma-qt-qwiic     https://learn.adafruit.com/adafruit-ltr-329-ltr-303/python-circuitpython提供了例程参考   总代码 # SPDX-FileCopyrightText: 2023 Cedar Grove Maker Studios # SPDX-License-Identifier: MIT """ nau7802_simpletest.py 2023-01-13 2.0.2 Cedar Grove Maker Studios Instantiates two NAU7802 channels with default gain of 128 and sample average count of 2. """ import time import board from cedargrove_nau7802 import NAU7802 # Instantiate 24-bit load sensor ADC; two channels, default gain of 128 nau7802 = NAU7802(board.I2C(), address=0x2A, active_channels=2) def zero_channel(): """Initiate internal calibration for current channel.Use when scale is started, a new channel is selected, or to adjust for measurement drift. Remove weight and tare from load cell before executing.""" print( "channel %1d calibrate.INTERNAL: %5s" % (nau7802.channel, nau7802.calibrate("INTERNAL")) ) print( "channel %1d calibrate.OFFSET: %5s" % (nau7802.channel, nau7802.calibrate("OFFSET")) ) print("...channel %1d zeroed" % nau7802.channel) def read_raw_value(samples=2): """Read and average consecutive raw sample values. Return average raw value.""" sample_sum = 0 sample_count = samples while sample_count > 0: while not nau7802.available(): pass sample_sum = sample_sum + nau7802.read() sample_count -= 1 return int(sample_sum / samples) # Instantiate and calibrate load cell inputs print("*** Instantiate and calibrate load cells") # Enable NAU7802 digital and analog power enabled = nau7802.enable(True) print("Digital and analog power enabled:", enabled) print("REMOVE WEIGHTS FROM LOAD CELLS") time.sleep(3) nau7802.channel = 1 zero_channel() # Calibrate and zero channel nau7802.channel = 2 zero_channel() # Calibrate and zero channel print("READY") ### Main loop: Read load cells and display raw values nau7802.channel = 1 value = read_raw_value() # SPDX-FileCopyrightText: Copyright (c) 2022 ladyada for Adafruit Industries # # SPDX-License-Identifier: Unlicense from adafruit_ltr329_ltr303 import LTR329 i2c = board.I2C() # uses board.SCL and board.SDA # i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller time.sleep(0.1) # sensor takes 100ms to 'boot' on power up ltr329 = LTR329(i2c) import time,board,displayio from adafruit_display_text import label from adafruit_bitmap_font import bitmap_font display = board.DISPLAY font_file = "font/36.bdf" font = bitmap_font.load_font(font_file) text1 = "Visible + IR:" + str(ltr329.visible_plus_ir_light) text2 = "Infrared :" + str(ltr329.ir_light) text3 = "raw value :" + str(value) text_group = displayio.Group( scale=1, x=0, y=0, ) text_area1 = label.Label(font, text=text1, color=0x00FF00, x=20, y=20) text_area2 = label.Label(font, text=text2, color=0x00FF00, x=20, y=60) text_area3 = label.Label(font, text=text3, color=0xFF0000, x=20, y=100) text_group.append(text_area1) text_group.append(text_area2) text_group.append(text_area3) ltr329 = LTR329(i2c) while True : value = read_raw_value() text_area1.text = "Visible + IR:" + str(ltr329.visible_plus_ir_light) text_area2.text = "Infrared :" + str(ltr329.ir_light) text_area3.text = "raw value :" + str(value) display.show(text_group) time.sleep(0.5) 分别导入官方和社区提供的模组,然后在例程上修改就能获取到传感器数据,最后加一段用文本在屏幕显示出来的语句   总结(心得体会) 本次活动大多还是跟着直播回放和大佬的教程去学的,通过此次活动的学习,熟悉了一些cpy的用法。在任务一我学习了怎样导出只包含想要的字的bdf字体文件、tft屏幕的显示方式等 任务二通过教程以及百度大致了解到网络有ip,端口,ipv4,ivp6,socket套接字,udp,tcp,sta,ap,json之类的名词,此前我对这些一概不知。任务三ws2812 怎么设置的颜色 任务四 综合运用了前面几个的内容,比较复杂还学习了高德天气api的使用。 此次活动让我看到自己还有许多的不会的东西,例如实现什么功能该用什么库什么函数,怎么阅读官方文档,怎么样去查找信息,之后会进一步学习python和单片机。最后感谢得捷电子和eeworld举办的活动以及各位大佬提供教程。       部分三  代码:https://download.eeworld.com.cn/detail/%E5%A5%BD%E6%A2%A6%E6%88%90%E7%A9%BA/629845

最近访客

< 1/1 >

统计信息

已有1人来访过

  • 芯积分:61
  • 好友:--
  • 主题:1
  • 回复:2

留言

你需要登录后才可以留言 登录 | 注册


现在还没有留言