698 views|0 replies

4

Posts

0

Resources
The OP
 

[Digi-Key Follow Me Issue 1] Task 2: Driving Peripherals [Copy link]

 

The peripherals used in this activity include LED, buzzer and OLED display.

The buzzer used this time is an active buzzer, and the driving method is similar to that of LED. The code is as follows:

Of course, you can also use PWM to change the output frequency and duty cycle to achieve different timbres: For the OLED display, this time I used a 0.96-inch IIC OLED screen. You can find the underlying driver program on Gitee. Thanks to the predecessors for making the wheel.

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

Here is the program that displays images and text:

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()

The effect is as follows:

This post is from DigiKey Technology Zone
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list