文章目录[隐藏]
树莓派Pico (RP2040芯片) SH1106OLED屏 避坑指南
显示屏为SH1106芯片,像素128*64
接口分别为GND,VCC,SCL,SDA
折腾了很久,网上也没有相关资料,成功点亮的同时想写篇博客分享一下.
首先,上图.
成功点亮的关键在于读好这个图.
右边框框里说 UART 为default,即标有 UART 的接口为默认的.
因此,将OLED的SDA,SCL接口分别接上,arduino里库管理器搜索sh1106下载某一个,
打开示例,
上传,
然后,
OLED不亮…
避坑结束…
开玩笑呢,库管理器里搜索sh1106,然后下载 OneBitDisplay ,注意注意,笔者暂时只发现这个库可以用.
下载完以后打开示例 multi_oled_demo,
大概长这个样子:
//
// OneBitDisplay library multi-display demo
//
// Demonstrates how to initialize and use multiple displays
//
#include <OneBitDisplay.h>
// Use -1 for the Wire library default pins
// or specify the pin numbers to use with the Wire library or bit banging on any GPIO pins
// These are reversed because I did straight-through wiring for my SSD1306
// and it has the 4-pin header as GND,VCC,SCL,SDA, but the GROVE connector is
// GND,VCC,SDA,SCL
#define GROVE_SDA_PIN 0
#define GROVE_SCL_PIN 1
// These are the pin numbers for the M5Stack Atom default I2C
#define SDA_PIN 0
#define SCL_PIN 1
// Set this to -1 to disable or the GPIO pin number connected to the reset
// line of your display if it requires an external reset
#define RESET_PIN -1
// let ss_oled figure out the display address
#define OLED_ADDR -1
// don't rotate the display
#define FLIP180 0
// don't invert the display
#define INVERT 0
// Bit-Bang the I2C bus
#define USE_HW_I2C 0
// Change these if you're using different OLED displays
#define MY_OLED1 OLED_128x64
#define MY_OLED2 OLED_64x32
// 2 copies of the SSOLED structure. Each structure is about 56 bytes
// There is no limit to the number of simultaneous displays which can be controlled by ss_oled
OBDISP obd[2];
void setup() {
char *msgs[] = {(char *)"SSD1306 @ 0x3C", (char *)"SSD1306 @ 0x3D",(char *)"SH1106 @ 0x3C",(char *)"SH1106 @ 0x3D"};
int rc;
// The I2C SDA/SCL pins set to -1 means to use the default Wire library
// If pins were specified, they would be bit-banged in software
// This isn't inferior to hw I2C and in fact allows you to go faster on certain CPUs
// The reset pin is optional and I've only seen it needed on larger OLEDs (2.4")
// that can be configured as either SPI or I2C
//
// obdI2CInit(OBDISP *, type, oled_addr, rotate180, invert, bWire, SDA_PIN, SCL_PIN, RESET_PIN, speed)
rc = obdI2CInit(&obd[0], MY_OLED1, OLED_ADDR, FLIP180, INVERT, 1, SDA_PIN, SCL_PIN, RESET_PIN, 400000L); // use standard I2C bus at 400Khz
if (rc != OLED_NOT_FOUND)
{
obdFill(&obd[0], 0, 1);
obdWriteString(&obd[0], 0,0,0,msgs[rc], FONT_8x8, 0, 1);
obdWriteString(&obd[0], 0,8,3,(char *)"Display", FONT_16x16, 0, 1);
obdWriteString(&obd[0], 0,56,6,(char *)"0", FONT_16x16, 0, 1);
}
rc = obdI2CInit(&obd[1], MY_OLED1, OLED_ADDR, FLIP180, INVERT, 0, GROVE_SDA_PIN, GROVE_SCL_PIN, RESET_PIN, 400000L); // use standard I2C bus at 400Khz
if (rc != OLED_NOT_FOUND)
{
obdFill(&obd[1], 0, 1);
obdSetTextWrap(&obd[1], 1);
obdWriteString(&obd[1], 0,0,0,msgs[rc], FONT_6x8, 0, 1);
obdWriteString(&obd[1], 0,4,2,(char *)"Display", FONT_8x8, 0, 1);
obdWriteString(&obd[1], 0,28,3,(char *)"1", FONT_8x8, 0, 1);
}
} /* setup() */
void loop() {
// put your main code here, to run repeatedly:
} /* loop() */
其中,这里
#define GROVE_SDA_PIN 0
#define GROVE_SCL_PIN 1
// These are the pin numbers for the M5Stack Atom default I2C
#define SDA_PIN 0
#define SCL_PIN 1
就是需要修改的,
观察发现
rc = obdI2CInit(&obd[0], MY_OLED1, OLED_ADDR, FLIP180, INVERT, 1, SDA_PIN, SCL_PIN, RESET_PIN, 400000L); // use standard I2C bus at 400Khz
if (rc != OLED_NOT_FOUND)
{
obdFill(&obd[0], 0, 1);
obdWriteString(&obd[0], 0,0,0,msgs[rc], FONT_8x8, 0, 1);
obdWriteString(&obd[0], 0,8,3,(char *)"Display", FONT_16x16, 0, 1);
obdWriteString(&obd[0], 0,56,6,(char *)"0", FONT_16x16, 0, 1);
}
rc = obdI2CInit(&obd[1], MY_OLED2, OLED_ADDR, FLIP180, INVERT, 0, GROVE_SDA_PIN, GROVE_SCL_PIN, RESET_PIN, 400000L); // use standard I2C bus at 400Khz
if (rc != OLED_NOT_FOUND)
{
obdFill(&obd[1], 0, 1);
obdSetTextWrap(&obd[1], 1);
obdWriteString(&obd[1], 0,0,0,msgs[rc], FONT_6x8, 0, 1);
obdWriteString(&obd[1], 0,4,2,(char *)"Display", FONT_8x8, 0, 1);
obdWriteString(&obd[1], 0,28,3,(char *)"1", FONT_8x8, 0, 1);
}
} /* setup() */
示例中定义了两块屏幕,根据这里
// Change these if you're using different OLED displays
#define MY_OLED1 OLED_128x64
#define MY_OLED2 OLED_64x32
不难发现是不同尺寸的OLED,
所以
#define GROVE_SDA_PIN 0
#define GROVE_SCL_PIN 1
// These are the pin numbers for the M5Stack Atom default I2C
#define SDA_PIN 0
#define SCL_PIN 1
中 GROVE_SDA_PIN和GROVE_SCL_PIN为小屏幕的接口
另外一个为大屏幕的接口,注意指的是GPIO号,
将对应的接口接上,就成功了!
根据其示例可以完成其他功能!
OK,以上就是血与泪的尝试后得出的结果,
希望可以给你一些帮助.
转载请说明来处:By RidgeFrank(CSDN)
版权声明:本文为CSDN博主「RidgeFrank」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/ChirpTB/article/details/122900463
暂无评论