740|0

4

帖子

0

TA的资源

一粒金砂(中级)

楼主
 

【得捷电子Follow me第1期】任务2:驱动外设 [复制链接]

 

在本次活动中使用到的外设有LED、蜂鸣器和OLED显示屏。

本次使用的蜂鸣器为有源蜂鸣器,驱动方法和LED相似,代码如下:

 

 当然也可以使用PWM改变输出的频率和占空比实现不同的音色:  对于OLED显示屏,这次使用到的是0.96寸IIC的OLED屏,在Gitee上可以找到底层驱动的程序,在此感谢前辈造的轮子

链接已隐藏,如需查看请登录或者注册

这里是显示图片和文字的程序:

  • from machine import Pin,I2C
  • from ssd1306 import SSD1306_I2C
  • import framebuf
  • from time import sleep
  • from utime import sleep_ms
  • i2c=machine.I2C(1, sda=machine.Pin("GP6"), scl=machine.Pin("GP7"), freq=400000)
  • oled = SSD1306_I2C(128, 64, i2c)
  • # display.fill(0)
  • # display.show()
  • # display.text("hello eeworld",5,10)
  • # display.show()
  • # Raspberry Pi logo as 32x32 bytearray
  • buffer = bytearray(b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00|?\x00\x01\x86@\x80\x01\x01\x80\x80\x01\x11\x88\x80\x01\x05\xa0\x80\x00\x83\xc1\x00\x00C\xe3\x00\x00~\xfc\x00\x00L'\x00\x00\x9c\x11\x00\x00\xbf\xfd\x00\x00\xe1\x87\x00\x01\xc1\x83\x80\x02A\x82@\x02A\x82@\x02\xc1\xc2@\x02\xf6>\xc0\x01\xfc=\x80\x01\x18\x18\x80\x01\x88\x10\x80\x00\x8c!\x00\x00\x87\xf1\x00\x00\x7f\xf6\x00\x008\x1c\x00\x00\x0c \x00\x00\x03\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
  • # Load the raspberry pi logo into the framebuffer (the image is 32x32)
  • fb = framebuf.FrameBuffer(buffer, 32, 32, framebuf.MONO_HLSB)
  • # Clear the oled display in case it has junk on it.
  • oled.fill(0)
  • # Blit the image from the framebuffer to the oled display
  • oled.blit(fb, 96, 0)
  • # Add some text
  • oled.text("Raspberry Pi",5,5)
  • oled.text("Pico",5,15)
  • # Finally update the oled display so the image & text is displayed
  • oled.show()

实现效果如下:

 

 

点赞 关注
 
 

回复
举报
您需要登录后才可以回帖 登录 | 注册

查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/10 下一条
立即报名 | 2025 瑞萨电子工业以太网技术日即将开启!
3月-4月 深圳、广州、北京、苏州、西安、上海 走进全国6城
2025瑞萨电子工业以太网技术巡回沙龙聚焦工业4.0核心需求,为工程师与企业决策者提供实时通信技术最佳解决方案。
预报从速,好礼等您拿~

查看 »

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

 
机器人开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表