SSD1306,DIGISparkOLED不使用teensy3.2

时间:2018-04-05 09:58:15

标签: arduino microcontroller arduino-ide teensy

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, 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x00, 0x00, 0x00,
0x7F, 0xC0, 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, 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通信中发出了问题。 请帮帮我。

1 个答案:

答案 0 :(得分:0)

@vasu嗨,我遇到了同样的问题,但在回答我的问题之前,请同时检查是否有硬件故障。 我购买的OLED显示屏只有VCC-GND-SCL-SDA。因此,我这里没有重设PIN。 但是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

尝试上面的方法,让我知道如何进行。

欢呼