【问题标题】:Which Commands do I have to use SSD1306 over I²C?我必须通过 I²C 使用 SSD1306 哪些命令?
【发布时间】:2017-03-23 15:49:49
【问题描述】:

我想为我通过 I²C 连接到我的 Raspberry Pi 的 SSD1306 创建一个简单的 linux 驱动程序。

在开始编码之前,我想了解设备以及我必须发送哪些命令。我使用 i2c-tools for linux 来测试我的命令。我研究了一些 Arduino 项目和 SSD1306 的数据表,但我只能在命令行上重新创建一些命令:

正在初始化设备:i2cset -y 1 0x3c 0xAE 0x20 0x10 0xb0 0xc8 0x00 0x10 0x40 0x81 0x7f 0xa1 0xa6 0xa8 0x3f 0xa4 0xd3 0x00 0xd5 0xf0 0xd9 0x22 0xda 0x12 0xdb 0x20 0x8d 0x14 0xaf i

发送数据到设备内存:i2cset -y 1 0x3c 0x40 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF i 这会从当前位置向右填充一些像素。

跳转到左上角像素:i2cset -y 1 0x3c 0xb0 0x00 0x10 i 这并不总是有效:(

0x3c 是我的 SSD1306 设备的地址

如果有人能告诉我更多命令或知道在哪里可以找到有关 cmets 的好示例或教程,我会很高兴。

谢谢,

p0kR

【问题讨论】:

  • 所有命令都应在数据表中列出。如果有些不存在,那么它们要么不存在,要么您的数据表不正确。
  • 关于在哪里可以找到显示手册、教程或其他场外资源的问题不在此处讨论。
  • 我有一个数据表,但我很难找到正确的命令。没有人要求提供数据表
  • 我要求的一个很好的示例/教程也可以作为关于同一设备的完全不同问题的答案。也许你找不到它,因为对我来说有趣的部分只是它的一小部分。????但如果我的问题以某种方式冒犯了某人,我很抱歉✌

标签: c linux arduino raspberry-pi i2c


【解决方案1】:

这是一个受https://www.mikrocontroller.net/topic/390980启发的扩展示例:

function display_off() {
i2cset -y 0 0x3c 0x00 0xAE  # Display OFF (sleep mode)
sleep 0.1
}

function init_display() {
i2cset -y 0 0x3c 0x00 0xA8  # Set Multiplex Ratio
i2cset -y 0 0x3c 0x00 0x3F    # value
i2cset -y 0 0x3c 0x00 0xD3  # Set Display Offset
i2cset -y 0 0x3c 0x00 0x00    # no vertical shift
i2cset -y 0 0x3c 0x00 0x40  # Set Display Start Line to 000000b
i2cset -y 0 0x3c 0x00 0xA1  # Set Segment Re-map, column address 127 ismapped to SEG0
i2cset -y 0 0x3c 0x00 0xC8    # Set COM Output Scan Direction, remapped mode. Scan from COM7 to COM0
#i2cset -y 0 0x3c 0x00 0xC0   # Set COM Output Scan Direction, remapped mode. Scan from COM7 to COM0
i2cset -y 0 0x3c 0x00 0xDA  # Set COM Pins Hardware Configuration
#i2cset -y 0 0x3c 0x00 0x12   # Alternative COM pin configuration, Disable COM Left/Right remap
#i2cset -y 0 0x3c 0x00 0x2    # Sequential COM pin configuration,  Disable COM Left/Right remap
#i2cset -y 0 0x3c 0x00 0x22   # Sequential COM pin configuration,  Enable Left/Right remap  (8pixels height)
i2cset -y 0 0x3c 0x00 0x32    # Alternative COM pin configuration, Enable Left/Right remap   (4pixels height)
#i2cset -y 0 0x3c 0x00 0x81 # Set Contrast Control
#i2cset -y 0 0x3c 0x00 0xCF   # value, 0x7F max.
i2cset -y 0 0x3c 0x00 0xA4  # display RAM content
i2cset -y 0 0x3c 0x00 0xA6  # non-inverting display mode - black dots on white background
i2cset -y 0 0x3c 0x00 0xD5  # Set Display Clock (Divide Ratio/Oscillator Frequency)
i2cset -y 0 0x3c 0x00 0x80    # max fequency, no divide ratio
i2cset -y 0 0x3c 0x00 0x8D  # Charge Pump Setting
i2cset -y 0 0x3c 0x00 0x14    # enable charge pump
i2cset -y 0 0x3c 0x00 0x20  # page addressing mode
i2cset -y 0 0x3c 0x00 0x20    # horizontal addressing mode
#i2cset -y 0 0x3c 0x00 0x21   # vertical addressing mode
#i2cset -y 0 0x3c 0x00 0x22   # page addressing mode
}

function display_on() {
i2cset -y 0 0x3c 0x00 0xAF  # Display ON (normal mode)
sleep 0.001
}

function reset_cursor() {
i2cset -y 0 0x3c 0x00 0x21  # set column address
i2cset -y 0 0x3c 0x00 0x00  #   set start address
i2cset -y 0 0x3c 0x00 0x7F  #   set end address (127 max)
i2cset -y 0 0x3c 0x00 0x22  # set page address
i2cset -y 0 0x3c 0x00 0x00  #   set start address
i2cset -y 0 0x3c 0x00 0x07  #   set end address (7 max)
}

display_off
init_display
display_on
reset_cursor

# fill screen
for i in $(seq 1024)
do
   i2cset -y 0 0x3c 0x40 0xff
done

reset_cursor

# clear screen
for i in $(seq 1024)
do
   i2cset -y 0 0x3c 0x40 0x0
done

reset_cursor

# draw a pattern
for i in $(seq 146)
do
    for i in 1 4 16 64 16 4 1
    do
        i2cset -y 0 0x3c 0x40 $i
    done
done

它很慢但有效。使用 128x32 OLED 显示屏 + 树莓派 1 进行测试。

【讨论】:

  • 这看起来和我要找的完全一样,非常感谢。我明天试试
猜你喜欢
  • 2019-01-04
  • 1970-01-01
  • 2013-08-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多