找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1351|回復(fù): 1
打印 上一主題 下一主題
收起左側(cè)

esp32 s3驅(qū)動OLED屏SSD1306黑屏

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:476652 發(fā)表于 2023-4-22 20:18 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
各位大神,哪位大神能指點下這是什么情況,感謝
   我在用源地的esp32s3 開發(fā)板驅(qū)動7針0.96 OLED屏顯示。
可咋都驅(qū)動不亮,這個olde屏插到STM32開發(fā)板上就能政策顯示
我的軟件:micropython
開發(fā)板:源地ESP32 S3
OLED屏:7針SPI 0.96 SSD1306屏
開發(fā)板和屏連線:D0/SCK--P6;  D1/MOSI--P7;  RES/RST--P5;  DC--P4;  CS--P10;


主程序
main.py


ESP32-C3 OLED顯示測試
元件:
    AI-THINKER ESP-C3-13/13U-KIT
    128*64 1306 OLED SPI/I2C
功能:
    ESP32-C3 OLED顯示測試
'''


import machine
from machine import Pin,SoftSPI
from ssd1306 import SSD1306_SPI

spi = SoftSPI(baudrate=80000000, polarity=0, phase=0, sck=Pin(6,Pin.OUT), mosi=Pin(7,Pin.OUT), miso=Pin(8))
#sck(D0)=6 mosi(D1)=7 miso=unused
oled = SSD1306_SPI(128, 64, spi, Pin(4),Pin(5), Pin(10))
#4=dc 5=res 10=cs

oled.text("First line", 0, 0, 1)
oled.text("Second line", 0, 8, 1)
oled.text("Third line", 0, 16, 1)
oled.text("Forth line", 0, 24, 1)
oled.text("Fifth line", 0, 32, 1)
oled.text("Sixth line", 0, 40, 1)
oled.text("Seventh line", 0, 48, 1)
oled.text("Last line", 0, 56, 1)
oled.show()


# MicroPython SSD1306 OLED driver, I2C and SPI interfaces

from micropython import const
import framebuf

SSD1306程序
ssd1306.py
# register definitions
SET_CONTRAST = const(0x81)
SET_ENTIRE_ON = const(0xA4)
SET_NORM_INV = const(0xA6)
SET_DISP = const(0xAE)
SET_MEM_ADDR = const(0x20)
SET_COL_ADDR = const(0x21)
SET_PAGE_ADDR = const(0x22)
SET_DISP_START_LINE = const(0x40)
SET_SEG_REMAP = const(0xA0)
SET_MUX_RATIO = const(0xA8)
SET_IREF_SELECT = const(0xAD)
SET_COM_OUT_DIR = const(0xC0)
SET_DISP_OFFSET = const(0xD3)
SET_COM_PIN_CFG = const(0xDA)
SET_DISP_CLK_DIV = const(0xD5)
SET_PRECHARGE = const(0xD9)
SET_VCOM_DESEL = const(0xDB)
SET_CHARGE_PUMP = const(0x8D)

# Subclassing FrameBuffer provides support for graphics primitives

class SSD1306(framebuf.FrameBuffer):
    def __init__(self, width, height, external_vcc):
        self.width = width
        self.height = height
        self.external_vcc = external_vcc
        self.pages = self.height // 8
        self.buffer = bytearray(self.pages * self.width)
        super().__init__(self.buffer, self.width, self.height, framebuf.MONO_VLSB)
        self.init_display()

    def init_display(self):
        for cmd in (
            SET_DISP,  # display off
            # address setting
            SET_MEM_ADDR,
            0x00,  # horizontal
            # resolution and layout
            SET_DISP_START_LINE,  # start at line 0
            SET_SEG_REMAP | 0x01,  # column addr 127 mapped to SEG0
            SET_MUX_RATIO,
            self.height - 1,
            SET_COM_OUT_DIR | 0x08,  # scan from COM[N] to COM0
            SET_DISP_OFFSET,
            0x00,
            SET_COM_PIN_CFG,
            0x02 if self.width > 2 * self.height else 0x12,
            # timing and driving scheme
            SET_DISP_CLK_DIV,
            0x80,
            SET_PRECHARGE,
            0x22 if self.external_vcc else 0xF1,
            SET_VCOM_DESEL,
            0x30,  # 0.83*Vcc
            # display
            SET_CONTRAST,
            0xFF,  # maximum
            SET_ENTIRE_ON,  # output follows RAM contents
            SET_NORM_INV,  # not inverted
            SET_IREF_SELECT,
            0x30,  # enable internal IREF during display on
            # charge pump
            SET_CHARGE_PUMP,
            0x10 if self.external_vcc else 0x14,
            SET_DISP | 0x01,  # display on
        ):  # on
            self.write_cmd(cmd)
        self.fill(0)
        self.show()

    def poweroff(self):
        self.write_cmd(SET_DISP)

    def poweron(self):
        self.write_cmd(SET_DISP | 0x01)

    def contrast(self, contrast):
        self.write_cmd(SET_CONTRAST)
        self.write_cmd(contrast)

    def invert(self, invert):
        self.write_cmd(SET_NORM_INV | (invert & 1))

    def rotate(self, rotate):
        self.write_cmd(SET_COM_OUT_DIR | ((rotate & 1) << 3))
        self.write_cmd(SET_SEG_REMAP | (rotate & 1))

    def show(self):
        x0 = 0
        x1 = self.width - 1
        if self.width != 128:
            # narrow displays use centred columns
            col_offset = (128 - self.width) // 2
            x0 += col_offset
            x1 += col_offset
        self.write_cmd(SET_COL_ADDR)
        self.write_cmd(x0)
        self.write_cmd(x1)
        self.write_cmd(SET_PAGE_ADDR)
        self.write_cmd(0)
        self.write_cmd(self.pages - 1)
        self.write_data(self.buffer)

    def disp(self, s: str, x: int, y: int, c: int = 1):
        print('jjj')
        self.text('*'+s, x, y, c)

class SSD1306_I2C(SSD1306):
    def __init__(self, width, height, i2c, addr=0x3C, external_vcc=False):
        self.i2c = i2c
        self.addr = addr
        self.temp = bytearray(2)
        self.write_list = [b"\x40", None]  # Co=0, D/C#=1
        super().__init__(width, height, external_vcc)

    def write_cmd(self, cmd):
        self.temp[0] = 0x80  # Co=1, D/C#=0
        self.temp[1] = cmd
        self.i2c.writeto(self.addr, self.temp)

    def write_data(self, buf):
        self.write_list[1] = buf
        self.i2c.writevto(self.addr, self.write_list)


class SSD1306_SPI(SSD1306):
    def __init__(self, width, height, spi, dc, res, cs, external_vcc=False):
        self.rate = 10 * 1024 * 1024
        dc.init(dc.OUT, value=0)
        res.init(res.OUT, value=0)
        cs.init(cs.OUT, value=1)
        self.spi = spi
        self.dc = dc
        self.res = res
        self.cs = cs
        import time

        self.res(1)
        time.sleep_ms(1)
        self.res(0)
        time.sleep_ms(10)
        self.res(1)
        super().__init__(width, height, external_vcc)

    def write_cmd(self, cmd):
        self.spi.init(baudrate=self.rate, polarity=0, phase=0)
        self.cs(1)
        self.dc(0)
        self.cs(0)
        self.spi.write(bytearray([cmd]))
        self.cs(1)

    def write_data(self, buf):
        self.spi.init(baudrate=self.rate, polarity=0, phase=0)
        self.cs(1)
        self.dc(1)
        self.cs(0)
        self.spi.write(buf)
        self.cs(1)

51hei圖片_202304222012303.jpg (133.61 KB, 下載次數(shù): 54)

51hei圖片_202304222012303.jpg

51hei圖片_202304222012302.jpg (138.22 KB, 下載次數(shù): 53)

51hei圖片_202304222012302.jpg

51hei圖片_202304222012301.jpg (98.93 KB, 下載次數(shù): 61)

51hei圖片_202304222012301.jpg

51hei圖片_20230422201230.jpg (157.97 KB, 下載次數(shù): 52)

51hei圖片_20230422201230.jpg
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

沙發(fā)
ID:476652 發(fā)表于 2023-4-22 20:21 | 只看該作者
23-OLED 7SPI-4.rar (2.4 KB, 下載次數(shù): 4)
這是源文件
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表