0

OLED 显示器不能与 teensy3.2 板一起使用,但它与 arduino UNO 可以正常工作,代码如下:

#include <U8glib.h>

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK);  // Display which does 
not send AC
int frame=0;
const uint8_t frame1[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0xFE, 0x00, 0x3F, 0xFF, 0xFF, 0x00, 
0x3F, 0xFF, 0xFF, 0x80,
0x30, 0x00, 0x01, 0x80, 0x33, 0xFF, 0x81, 0xC0, 0x33, 0xFF, 0x81, 0xE0, 
0x33, 0xFF, 0x81, 0xE0,
0x33, 0xFF, 0x81, 0xE0, 0x33, 0xFF, 0x81, 0xE0, 0x33, 0xFF, 0x81, 0xE0, 
0x33, 0xFF, 0x81, 0xE0,
0x33, 0xFF, 0x81, 0xE0, 0x33, 0xFF, 0x81, 0xC0, 0x30, 0x00, 0x01, 0x80, 
0x3F, 0xFF, 0xFF, 0x80,
0x3F, 0xFF, 0xFF, 0x00, 0x0F, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00,  
 };

const uint8_t frame2[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x0F, 0x00, 
0x00, 0x09, 0x80, 0x00,
0x08, 0xE0, 0x00, 0x08, 0x38, 0x00, 0x08, 0x1C, 0x0C, 0x08, 0x0F, 0x06, 
0x08, 0x1C, 0x03, 0x88,
0x70, 0x00, 0xC8, 0xE0, 0x00, 0x79, 0x80, 0x00, 0x1E, 0x00, 0x00, 0x1E, 
0x00, 0x00, 0x79, 0x80,
0x00, 0xC8, 0xE0, 0x03, 0x88, 0x70, 0x06, 0x08, 0x1C, 0x0C, 0x08, 0x0F, 
0x00, 0x08, 0x1C, 0x00,
0x08, 0x38, 0x00, 0x08, 0xE0, 0x00, 0x09, 0xC0, 0x00, 0x0F, 0x00, 0x00, 
0x0C, 0x00, 0x00, 0x08,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 
};

const uint8_t frame3 [] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 
0x00, 0x01, 0x80, 0x00,
0x00, 0x01, 0xC0, 0x00, 0x00, 0x01, 0xC0, 0x00, 0x00, 0x03, 0xC0, 0x00, 
0x00, 0x03, 0xC0, 0x00,
0x00, 0x03, 0xC0, 0x00, 0x00, 0x03, 0xC0, 0x00, 0x00, 0x02, 0x40, 0x00, 
0x00, 0x06, 0x40, 0x00,
0x00, 0x06, 0x60, 0x00, 0x00, 0x06, 0x60, 0x00, 0x00, 0x06, 0x60, 0x00, 
0x00, 0x04, 0x60, 0x00,
0x00, 0x0C, 0x60, 0x00, 0x00, 0x0C, 0x60, 0x00, 0x07, 0xFC, 0x61, 0xFC, 
0x07, 0xF8, 0x33, 0xFC,
0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x33, 0x00, 
0x00, 0x00, 0x33, 0x00,
0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x3E, 0x00, 
0x00, 0x00, 0x1E, 0x00,
0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x1C, 0x00, 
0x00, 0x00, 0x1C, 0x00,
0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
};


const uint8_t frame4[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x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00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
};
void setup(void) {
}

void loop(void) {
u8g.firstPage();
 do{
  draw();
 }while(u8g.nextPage());
  frame++;
  if(frame == 13)
  frame=0;
  delay(1000);
  }
void draw(){
 if(frame == 0 )
 {  u8g.drawBitmapP(0,0,4,20,frame1);
    u8g.drawBitmapP(103,0,3.5,28, frame2); 
    u8g.setFont(u8g_font_helvR24);
    u8g.setColorIndex(1);
    u8g.drawStr(20,45,"11:45");
    u8g.setFont(u8g_font_helvB12);
    u8g.drawStr(100,60,"AM");
 }
 if(frame == 1 )
 { u8g.setFont(u8g_font_profont22);
   u8g.setColorIndex(1);
   u8g.drawStr(0,20,"Heart Rate");
   u8g.setFont(u8g_font_helvR24);
   u8g.drawStr(25,60,"75"); 
   u8g.setFont(u8g_font_helvB12);
   u8g.drawStr(90,60,"BPM");
 }   
 if(frame == 2 )
 {  u8g.setFont(u8g_font_profont22);
    u8g.setColorIndex(1);
    u8g.drawStr(10,20,"Analysing");
    u8g.drawBitmap(10,30,4,32, frame3);
    u8g.setFont(u8g_font_helvR24);
    u8g.setColorIndex(1);
    u8g.drawStr(50,58,"10");
    u8g.setFont(u8g_font_profont22);
    u8g.drawStr(90,58,"sec");
  } 
   if(frame == 3 )
 {  u8g.setFont(u8g_font_profont22);
    u8g.setColorIndex(1);
    u8g.drawStr(10,20,"Analysing");
    u8g.drawBitmap(10,30,4,32, frame3);
    u8g.setFont(u8g_font_helvR24);
    u8g.setColorIndex(1);
    u8g.drawStr(60,58,"9");
    u8g.setFont(u8g_font_profont22);
    u8g.drawStr(90,58,"sec");
   } 
  if(frame == 4 )
  {  u8g.setFont(u8g_font_profont22);
     u8g.setColorIndex(1);
    u8g.drawStr(10,20,"Analysing");
    u8g.drawBitmap(10,30,4,32, frame3);
    u8g.setFont(u8g_font_helvR24);
    u8g.setColorIndex(1);
    u8g.drawStr(60,58,"8");
    u8g.setFont(u8g_font_profont22);
    u8g.drawStr(90,58,"sec");
  } 
  if(frame == 5 )
  {  u8g.setFont(u8g_font_profont22);
     u8g.setColorIndex(1);
     u8g.drawStr(10,20,"Analysing");
     u8g.drawBitmap(10,30,4,32, frame3);
     u8g.setFont(u8g_font_helvR24);
     u8g.setColorIndex(1);
     u8g.drawStr(60,58,"7");
     u8g.setFont(u8g_font_profont22);
     u8g.drawStr(90,58,"sec");
   } 
   if(frame == 6 )
   {  u8g.setFont(u8g_font_profont22);
      u8g.setColorIndex(1);
      u8g.drawStr(10,20,"Analysing");
      u8g.drawBitmap(10,30,4,32, frame3);
      u8g.setFont(u8g_font_helvR24);
      u8g.setColorIndex(1);
      u8g.drawStr(60,58,"6");
      u8g.setFont(u8g_font_profont22);
      u8g.drawStr(90,58,"sec");
     } 
   if(frame == 7 )
   {  u8g.setFont(u8g_font_profont22);
      u8g.setColorIndex(1);
      u8g.drawStr(10,20,"Analysing");
      u8g.drawBitmap(10,30,4,32, frame3);
      u8g.setFont(u8g_font_helvR24);
      u8g.setColorIndex(1);
      u8g.drawStr(60,58,"5");
      u8g.setFont(u8g_font_profont22);
      u8g.drawStr(90,58,"sec");
     } 
    if(frame == 8 )
    {  u8g.setFont(u8g_font_profont22);
       u8g.setColorIndex(1);
       u8g.drawStr(10,20,"Analysing");
       u8g.drawBitmap(10,30,4,32, frame3);
       u8g.setFont(u8g_font_helvR24);
       u8g.setColorIndex(1);
       u8g.drawStr(60,58,"4");
       u8g.setFont(u8g_font_profont22);
       u8g.drawStr(90,58,"sec");
      } 
     if(frame == 9 )
      {  u8g.setFont(u8g_font_profont22);
         u8g.setColorIndex(1);
         u8g.drawStr(10,20,"Analysing");
         u8g.drawBitmap(10,30,4,32, frame3);
         u8g.setFont(u8g_font_helvR24);
         u8g.setColorIndex(1);
         u8g.drawStr(60,58,"3");
         u8g.setFont(u8g_font_profont22);
         u8g.drawStr(90,58,"sec");
        } 
        if(frame == 10 )
       {  u8g.setFont(u8g_font_profont22);
          u8g.setColorIndex(1);
          u8g.drawStr(10,20,"Analysing");
          u8g.drawBitmap(10,30,4,32, frame3);
          u8g.setFont(u8g_font_helvR24);
          u8g.setColorIndex(1);
          u8g.drawStr(60,58,"2");
          u8g.setFont(u8g_font_profont22);
          u8g.drawStr(90,58,"sec");
        } 
      if(frame == 11 )
      {u8g.setFont(u8g_font_profont22);
       u8g.setColorIndex(1);
       u8g.drawStr(10,20,"Analysing");
       u8g.drawBitmap(10,30,4,32, frame3);
       u8g.setFont(u8g_font_helvR24);
       u8g.setColorIndex(1);
       u8g.drawStr(60,58,"1");
       u8g.setFont(u8g_font_profont22);
       u8g.drawStr(90,58,"sec");
       } 
      if(frame == 12)
      {u8g.drawBitmapP(45,0,5.375,43, frame4);
       u8g.setFont(u8g_font_profont22);
       u8g.setColorIndex(1);
       u8g.drawStr(45,58,"Done");
      } 
      }

它们没有编译错误。OLED甚至没有打开。并且在扫描地址时显示为 0X3C。我在谷歌上搜索了很多,但我认为他们的和 I2C 通信中的问题。请帮帮我。

4

1 回答 1

0

@vasu嗨,我遇到了同样的问题,但在我回答之前请检查是否有任何硬件故障。我买的OLED显示器只有VCC-GND-SCL-SDA。所以我这里没有重置密码。但 oled 库最初尝试在启动时将复位 PIN 拉高。因为我没有复位引脚,所以它坐在那里等待复位高。因此,为了在没有复位引脚的情况下初始化您的 oled 显示器,请在您的 Arduino 草图文件中尝试此操作

 //1-->Manually set HIGH to digitally assigned reset pin

        pinMode(A4, OUTPUT);  //A4 is reset pin assigned programmatically (for example)
        digitalWrite(A4, HIGH);       



    //2-->Try changing your init to this

        U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);

        //As this will be the right one to define from the user manual shown in the link
        //https://reprap.org/forum/file.php?267,file=54605

试试上面的,让我知道它是怎么回事。

干杯

于 2018-08-08T23:15:56.847 回答