[ESP32-Audio-Kit音频开发板测评]OLED屏显示驱动
<div class='showpostmsg'><p>ESP32-Audio-Kit音频开发板为用户提供的扩展资源实在称得上是紧缺,用扩展接口提供的引脚也多是复用的。要是使用个SPI接口啥的,估计能都给整没了!</p><p>为了显示的需要,这里就为它配置一个I2C接口OLED屏来显示。</p>
<p>该显示屏是一款0.91寸的单色屏,其显示效果如图1所示。</p>
<p><span style="font-size:12pt"><span style="background:white"><span style="24.0pt"><span style="font-family:宋体"><span style="font-size:10.5pt"><span style="font-family:"微软雅黑","sans-serif""><span style="color:#444444"><span style="letter-spacing:.75pt">图1显示效果</span></span></span></span></span></span></span></span></p>
<p><span style="font-size:12pt"><span style="background:white"><span style="24.0pt"><span style="font-family:宋体"><span style="font-size:10.5pt"><span style="font-family:"微软雅黑","sans-serif""><span style="color:#444444"><span style="letter-spacing:.75pt">显示屏与开发板的连接关系为:</span></span></span></span></span></span></span></span></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif">SCL---IO23</span></span></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif">SDA---IO18</span></span></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">其初始化函数为:</span></span></span></p>
<pre>
<code class="language-cpp">void OLED_Init(){
//SSD1306
delay(100);
OLED_WR_Byte(0xAE,OLED_CMD);
OLED_WR_Byte(0x40,OLED_CMD);
OLED_WR_Byte(0xB0,OLED_CMD);
OLED_WR_Byte(0xC8,OLED_CMD);
OLED_WR_Byte(0x81,OLED_CMD);
OLED_WR_Byte(0xff,OLED_CMD);
OLED_WR_Byte(0xa1,OLED_CMD);
OLED_WR_Byte(0xa6,OLED_CMD);
OLED_WR_Byte(0xa8,OLED_CMD);
OLED_WR_Byte(0x1f,OLED_CMD);
OLED_WR_Byte(0xd3,OLED_CMD);
OLED_WR_Byte(0x00,OLED_CMD);
OLED_WR_Byte(0xd5,OLED_CMD);
OLED_WR_Byte(0xf0,OLED_CMD);
OLED_WR_Byte(0xd9,OLED_CMD);
OLED_WR_Byte(0x22,OLED_CMD);
OLED_WR_Byte(0xda,OLED_CMD);
OLED_WR_Byte(0x02,OLED_CMD);
OLED_WR_Byte(0xdb,OLED_CMD);
OLED_WR_Byte(0x49,OLED_CMD);
OLED_WR_Byte(0x8d,OLED_CMD);
OLED_WR_Byte(0x14,OLED_CMD);
OLED_WR_Byte(0xaf,OLED_CMD);
OLED_Clear();
}</code></pre>
<p style="text-align:justify"> </p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">显示定位函数为:</span></span></span></p>
<pre>
<code class="language-cpp">void OLED_Set_Pos(unsigned char x, unsigned char y){
OLED_WR_Byte(0xb0+y,OLED_CMD);
OLED_WR_Byte(((x&0xf0)>>4)|0x10,OLED_CMD);
OLED_WR_Byte((x&0x0f),OLED_CMD);
}</code></pre>
<p style="text-align:justify"> </p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">清屏函数为:</span></span></span></p>
<pre>
<code class="language-cpp">void OLED_Clear(void){
unsigned char i,n;
for(i=0;i<8;i++)
{
OLED_WR_Byte (0xb0+i,OLED_CMD);
OLED_WR_Byte (0x00,OLED_CMD);
OLED_WR_Byte (0x10,OLED_CMD);
for(n=0;n<128;n++) OLED_WR_Byte(0,OLED_DATA);
}
}</code></pre>
<p style="text-align:justify"> </p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">字符显示函数为:</span></span></span></p>
<pre>
<code class="language-cpp">void OLED_ShowChar(unsigned char x,unsigned char y,unsigned char chr,unsigned char Char_Size)
{
unsigned char c=0,i=0;
c=chr-' ';
if(x>Max_Column-1){x=0;y=y+2;}
if(Char_Size ==16)
{
OLED_Set_Pos(x,y);
for(i=0;i<8;i++)
OLED_WR_Byte(F8X16,OLED_DATA);
OLED_Set_Pos(x,y+1);
for(i=0;i<8;i++)
OLED_WR_Byte(F8X16,OLED_DATA);
}
else {
OLED_Set_Pos(x,y);
for(i=0;i<6;i++)
OLED_WR_Byte(F6x8,OLED_DATA);
}
}</code></pre>
<p style="text-align:justify"> </p>
<p><span style="font-size:12pt"><span style="background:white"><span style="24.0pt"><span style="font-family:宋体"><span style="font-size:10.5pt"><span style="font-family:"微软雅黑","sans-serif""><span style="color:#444444"><span style="letter-spacing:.75pt">相应的主程序为:</span></span></span></span></span></span></span></span></p>
<pre>
<code class="language-cpp">void setup() {
pinMode(SCLK, OUTPUT);
pinMode(SDIN, OUTPUT);
pinMode(ledPin, OUTPUT);
OLED_Init();
OLED_Clear();
OLED_Showstring(0,0,15,16);
}
void loop() {
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
}</code></pre>
<p style="text-align:justify"> </p>
<p><span style="font-size:12pt"><span style="background:white"><span style="24.0pt"><span style="font-family:宋体"><span style="font-size:10.5pt"><span style="font-family:"微软雅黑","sans-serif""><span style="color:#444444"><span style="letter-spacing:.75pt">由于ArduinoIDE不支持指针的使用,故在显示字符串时需要借助数组来解决,基于字符显示函数的字符串显示函数为:</span></span></span></span></span></span></span></span></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif">char Str = "ESP32-Audio-Kit";</span></span></p>
<pre>
<code class="language-cpp">void OLED_Showstring(unsigned char x,unsigned char y,unsigned char n,unsigned char Char_Size)
{
unsigned char i;
for(i=0;i<n;i++)
{
OLED_ShowChar(x,y,Str,16);
x=x+8;
}
}</code></pre>
<p><span style="font-size:12pt"><span style="background:white"><span style="24.0pt"><span style="font-family:宋体"><span style="font-size:10.5pt"><span style="font-family:"微软雅黑","sans-serif""><span style="color:#444444"><span style="letter-spacing:.75pt">有了OLED屏的显示功能,信息的显示任务就不用完全依赖串口通信了!</span></span></span></span></span></span></span></span></p>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> <p>单色屏,I2C接口,显示效果可以,简洁高效</p>
Jacktang 发表于 2021-9-29 10:29
单色屏,I2C接口,显示效果可以,简洁高效
<p>哈哈,这款板子的可用引脚资源很紧缺呀!</p>
<p>期待音频方面的测评呀~</p>
w494143467 发表于 2021-9-30 16:01
期待音频方面的测评呀~
<p>正在准备着换开发环境来解决这个问题</p>
页:
[1]