2020年7月3日 星期五

arduino繪圖筆記

參考文章OLED顯示照片與圖像顯示實習

因為用了話比較漂亮圖的方式沒辦法跑其他程式,所以不能照上面那個網頁去繪圖,只能退而求其次用這個方法

因為螢幕的初始設定不一樣,要畫漂亮圖片的話就沒辦法跑一些阿里阿紮的東西,目前測試出用來點亮燈的analogWrite、發出聲音無緣蜂鳴器的noTone、超聲波測距的都不行,DHT溫濕度可以、ds18b20測溫度可以




------------參考文章的OLDE程式碼設定是--------------


#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

void setup() {
  Serial.begin(115200);
  Serial.println();
  // initialize with the I2C addr 0x3C
  if(display.begin(SSD1306_SWITCHCAPVCC, 0x3C))  // Address 0x3D for 128x64
  Serial.println("SSD1036 OLED allocation Successed!");
  else  {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }
  delay(2000); // Pause for 2 seconds
}

------------我用的OLED程式碼設定是-----------
//OLED設定
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
//螢幕設定,定義顯示高度跟寬度
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH  16
#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

void setup() {
  // initialize with the I2C addr 0x3D (for the 128x64)
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
}


1.小畫家採用128*30畫素畫圖後,修飾一下圖片,想像輸出的時候會拉長1.5倍左右


2.使用網站http://javl.github.io/image2cpp/
設定如下
其他的步驟跟原文章都一樣
要輸出的程式碼是

const unsigned char Logo [] PROGMEM = {
};
void setup() {
}

//繪圖程式碼
display.drawBitmap(0, 0, Logo, 128, 64, WHITE);


就可以輸出圖片了

----------完整範例程式如下---------
/*
 * design by orangeV,taiwan,tainan 台南大成國中 蔡智恆
 * need libraries 需要程式庫<SPI.h>,<Wire.h>,<Adafruit_GFX.h>,<Adafruit_SSD1306.h>
 */

//OLED
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET -1
Adafruit_SSD1306 display(OLED_RESET);
//OLEDsetting
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH  16
#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

const unsigned char PHYduino_Logo [] PROGMEM = {
0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 
0x5f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfa, 
0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 
0x67, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe6, 
0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa6, 
0x66, 0xff, 0xfc, 0xff, 0xfc, 0xe0, 0x38, 0x00, 0x18, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x66, 
0x66, 0x00, 0x14, 0xa0, 0x14, 0xa0, 0x68, 0x00, 0x18, 0x00, 0x00, 0x00, 0x02, 0x80, 0x00, 0x66, 
0x66, 0xfc, 0x0c, 0xc0, 0x0c, 0xc0, 0x98, 0x00, 0x18, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x66, 
0x66, 0x0c, 0x0c, 0xc0, 0x00, 0x83, 0x18, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0xa6, 
0x66, 0x0c, 0x0c, 0xc0, 0x00, 0x8c, 0x18, 0x00, 0x18, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0xe6, 
0x66, 0x0c, 0x1c, 0xe0, 0x00, 0xd0, 0x18, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x02, 0x80, 0x00, 0x06, 
0x66, 0xf7, 0xf4, 0xa0, 0x1c, 0xa0, 0x39, 0xff, 0xf7, 0x80, 0x7f, 0xc3, 0xf3, 0x06, 0x00, 0xe6, 
0x66, 0xac, 0x18, 0xff, 0xf4, 0xff, 0xe9, 0x40, 0x1e, 0x80, 0x51, 0x42, 0xd3, 0x05, 0xff, 0xa6, 
0x66, 0xcc, 0x00, 0x00, 0x0c, 0x00, 0x39, 0x80, 0x19, 0x80, 0xf1, 0xf3, 0x33, 0x06, 0x00, 0x66, 
0x66, 0x0c, 0x00, 0x00, 0x04, 0x00, 0x19, 0x80, 0x19, 0x83, 0x31, 0x98, 0x33, 0x06, 0x00, 0x66, 
0x66, 0x0c, 0x00, 0x00, 0x04, 0x00, 0x19, 0x80, 0x19, 0x8c, 0x31, 0x8e, 0x33, 0x06, 0x00, 0x66, 
0x66, 0x0e, 0x00, 0x00, 0x0c, 0x00, 0x39, 0xc0, 0x39, 0xb0, 0x31, 0x83, 0xb3, 0x92, 0x00, 0x66, 
0x66, 0x0a, 0x00, 0x00, 0x14, 0x00, 0x29, 0x40, 0x29, 0x40, 0x51, 0x40, 0xd2, 0xad, 0xff, 0xa6, 
0x67, 0x0f, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xf9, 0xff, 0xf9, 0xc0, 0x73, 0xc6, 0x00, 0xe6, 
0x65, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x66, 
0x67, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf6, 
0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 
0x5f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfa, 
0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 
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, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

void setup() {
  Serial.begin(9600);
  //OLED
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.display();
  display.clearDisplay();
  display.drawBitmap(0, 8, PHYduino_Logo, 128, 64, WHITE);
  display.display();
  delay(1500);
  display.clearDisplay();
}

void loop() {
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.setTextSize(1);
  display.print("By.orangeV  TCJHS.lab");
  display.drawBitmap(0, 8, PHYduino_Logo, 128, 64, WHITE);
  display.display();
  display.clearDisplay();
}

沒有留言:

張貼留言