我必须使用哪些命令才能通过 I²C 使用 SSD1306?

p0k*_*0kR -2 c linux arduino i2c raspberry-pi

我想为 SSD1306 创建一个简单的 Linux 驱动程序,我已通过 I\xc2\xb2C 连接到我的 Raspberry Pi。

\n\n

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

\n\n

初始化设备: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

\n\n

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

\n\n

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

\n\n

0x3c是我的SSD1306设备的地址

\n\n

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

\n\n

谢谢,

\n\n

p0kR

\n

小智 5

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

\n\n
function display_off() {\ni2cset -y 0 0x3c 0x00 0xAE  # Display OFF (sleep mode)\nsleep 0.1\n}\n\nfunction init_display() {\ni2cset -y 0 0x3c 0x00 0xA8  # Set Multiplex Ratio\ni2cset -y 0 0x3c 0x00 0x3F    # value\ni2cset -y 0 0x3c 0x00 0xD3  # Set Display Offset\ni2cset -y 0 0x3c 0x00 0x00    # no vertical shift\ni2cset -y 0 0x3c 0x00 0x40  # Set Display Start Line to 000000b\ni2cset -y 0 0x3c 0x00 0xA1  # Set Segment Re-map, column address 127 ismapped to SEG0\ni2cset -y 0 0x3c 0x00 0xC8    # Set COM Output Scan Direction, remapped mode. Scan from COM7 to COM0\n#i2cset -y 0 0x3c 0x00 0xC0   # Set COM Output Scan Direction, remapped mode. Scan from COM7 to COM0\ni2cset -y 0 0x3c 0x00 0xDA  # Set COM Pins Hardware Configuration\n#i2cset -y 0 0x3c 0x00 0x12   # Alternative COM pin configuration, Disable COM Left/Right remap\n#i2cset -y 0 0x3c 0x00 0x2    # Sequential COM pin configuration,  Disable COM\xc2\xa0Left/Right remap\n#i2cset -y 0 0x3c 0x00 0x22   # Sequential COM\xc2\xa0pin configuration,  Enable Left/Right remap  (8pixels height)\ni2cset -y 0 0x3c 0x00 0x32    # Alternative COM\xc2\xa0pin configuration, Enable Left/Right remap   (4pixels height)\n#i2cset -y 0 0x3c 0x00 0x81 # Set Contrast Control\n#i2cset -y 0 0x3c 0x00 0xCF   # value, 0x7F max.\ni2cset -y 0 0x3c 0x00 0xA4  # display RAM content\ni2cset -y 0 0x3c 0x00 0xA6  # non-inverting display mode - black dots on white background\ni2cset -y 0 0x3c 0x00 0xD5  # Set Display Clock (Divide Ratio/Oscillator Frequency)\ni2cset -y 0 0x3c 0x00 0x80    # max fequency, no divide ratio\ni2cset -y 0 0x3c 0x00 0x8D  # Charge Pump Setting\ni2cset -y 0 0x3c 0x00 0x14    # enable charge pump\ni2cset -y 0 0x3c 0x00 0x20  # page addressing mode\ni2cset -y 0 0x3c 0x00 0x20    # horizontal addressing mode\n#i2cset -y 0 0x3c 0x00 0x21   # vertical addressing mode\n#i2cset -y 0 0x3c 0x00 0x22   # page addressing mode\n}\n\nfunction display_on() {\ni2cset -y 0 0x3c 0x00 0xAF  # Display ON (normal mode)\nsleep 0.001\n}\n\nfunction reset_cursor() {\ni2cset -y 0 0x3c 0x00 0x21  # set column address\ni2cset -y 0 0x3c 0x00 0x00  #   set start address\ni2cset -y 0 0x3c 0x00 0x7F  #   set end address (127 max)\ni2cset -y 0 0x3c 0x00 0x22  # set page address\ni2cset -y 0 0x3c 0x00 0x00  #   set start address\ni2cset -y 0 0x3c 0x00 0x07  #   set end address (7 max)\n}\n\ndisplay_off\ninit_display\ndisplay_on\nreset_cursor\n\n# fill screen\nfor i in $(seq 1024)\ndo\n   i2cset -y 0 0x3c 0x40 0xff\ndone\n\nreset_cursor\n\n# clear screen\nfor i in $(seq 1024)\ndo\n   i2cset -y 0 0x3c 0x40 0x0\ndone\n\nreset_cursor\n\n# draw a pattern\nfor i in $(seq 146)\ndo\n    for i in 1 4 16 64 16 4 1\n    do\n        i2cset -y 0 0x3c 0x40 $i\n    done\ndone\n
Run Code Online (Sandbox Code Playgroud)\n\n

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

\n