Posted by : M yunus Minggu, 12 Februari 2017


Oke kali ini kita bakal bikin tampilangambar yang di konversi ke list arduino menggunakan I2C OLED 64x128.

1. terlebih dahulu kita rangkaikan Aduino dan OLED seperti berikut,


2. selanjutnya kita download library OLED disini, dan masukan hasil ekstraknya pad folder sketchbook/libraries.
3. buka file example OLED file/example/...
4. untuk custom gambar agar dapat ditampilkan pada oled, anda perlu merubahnya dari format gambar (bmp, png, jpg, dll) menjadi list 1 dimensi, monokrom, dan bernilai binner)

berikut adalah program konversi gambar menjadai list arduino 1 dimensi, monokrom dan bernilai binner, ditulis dengan menggunakan proram python dan anda membutuhkan library numpy dan opencv untuk pengolahanya,

import cv2 as cv
import numpy as np

img = cv.imread('/arahkan/ke/lokasi/folder/gambar')
bmp = (img[:,:,0] + img[:,:,1] + img[:,:,2])/3
 

#sesuaikan ukuran size yang dinginkan, maks 128x64
bmp2 = cv.resize(bmp, (128,64))


for x in range(bmp2.shape[0]):
   for y in range(bmp2.shape[1]):

         if bmp2[x,y] >0:
            bmp2[x,y] =255

         else:                             
            bmp2[x,y] =0

cv.imwrite("my.jpg", bmp2)

for x in range(bmp2.shape[0]):
   for y in range(bmp2.shape[1]):
             if bmp2[x,y] >0:
                bmp2[x,y] =0
             else:
                bmp2[x,y] =1
            
def loop(x,y):                   
      if x==0:

         result = str(bmp2[y,0])+str(bmp2[y,1])+str(bmp2[y,2])+str(bmp2[y,3])+str(bmp2[y,4])+str(bmp2[y,5])+str(bmp2[y,6])+str(bmp2[y,7])     
     
      if x==1 :
         result = str(bmp2[y,8])+str(bmp2[y,9])+str(bmp2[y,10])+str(bmp2[y,11])+str(bmp2[y,12])+str(bmp2[y,13])+str(bmp2[y,14])+str(bmp2[y,15])      
     
      if x==2 :                        
         result = str(bmp2[y,16])+str(bmp2[y,17])+str(bmp2[y,18])+str(bmp2[y,19])+str(bmp2[y,20])+str(bmp2[y,21])+str(bmp2[y,22])+str(bmp2[y,23])
     
      if x==3 :
         result = str(bmp2[y,24])+str(bmp2[y,25])+str(bmp2[y,26])+str(bmp2[y,27])+str(bmp2[y,28])+str(bmp2[y,29])+str(bmp2[y,30])+str(bmp2[y,31])
     
      if x==4 :

        result = str(bmp2[y,32])+str(bmp2[y,33])+str(bmp2[y,34])+str(bmp2[y,35])+str(bmp2[y,36])+str(bmp2[y,37])+str(bmp2[y,38])+str(bmp2[y,39])
     
      if x==5 :
         result = str(bmp2[y,40])+str(bmp2[y,41])+str(bmp2[y,42])+str(bmp2[y,43])+str(bmp2[y,44])+str(bmp2[y,45])+str(bmp2[y,46])+str(bmp2[y,47])
     
      if x==6 :

        result = str(bmp2[y,48])+str(bmp2[y,49])+str(bmp2[y,50])+str(bmp2[y,51])+str(bmp2[y,52])+str(bmp2[y,53])+str(bmp2[y,54])+str(bmp2[y,55])
     
      if x==7 :
         result = str(bmp2[y,56])+str(bmp2[y,57])+str(bmp2[y,58])+str(bmp2[y,59])+str(bmp2[y,60])+str(bmp2[y,61])+str(bmp2[y,62])+str(bmp2[y,63])

      if x==8:   

 result = str(bmp2[y,64])+str(bmp2[y,65])+str(bmp2[y,66])+str(bmp2[y,67])+str(bmp2[y,68])+str(bmp2[y,69])+str(bmp2[y,70])+str(bmp2[y,71])
     
      if x==9:                                             
         result = str(bmp2[y,72])+str(bmp2[y,73])+str(bmp2[y,74])+str(bmp2[y,75])+str(bmp2[y,76])+str(bmp2[y,77])+str(bmp2[y,78])+str(bmp2[y,79])
     
      if x==10: 
         result = str(bmp2[y,80])+str(bmp2[y,81])+str(bmp2[y,82])+str(bmp2[y,83])+str(bmp2[y,84])+str(bmp2[y,85])+str(bmp2[y,86])+str(bmp2[y,87])
     
      if x==11:                                             
         result = str(bmp2[y,88])+str(bmp2[y,89])+str(bmp2[y,90])+str(bmp2[y,91])+str(bmp2[y,92])+str(bmp2[y,93])+str(bmp2[y,94])+str(bmp2[y,95])
     
      if x==12: 
         result = str(bmp2[y,96])+str(bmp2[y,97])+str(bmp2[y,98])+str(bmp2[y,99])+str(bmp2[y,100])+str(bmp2[y,101])+str(bmp2[y,102])+str(bmp2[y,103])
     
      if x==13:                                             
         result = str(bmp2[y,104])+str(bmp2[y,105])+str(bmp2[y,106])+str(bmp2[y,107])+str(bmp2[y,108])+str(bmp2[y,109])+str(bmp2[y,110])+str(bmp2[y,111])
     
      if x==14: 
         result = str(bmp2[y,112])+str(bmp2[y,113])+str(bmp2[y,114])+str(bmp2[y,115])+str(bmp2[y,116])+str(bmp2[y,117])+str(bmp2[y,118])+str(bmp2[y,119])
      if x==15:                                             
         result = str(bmp2[y,120])+str(bmp2[y,121])+str(bmp2[y,122])+str(bmp2[y,123])+str(bmp2[y,124])+str(bmp2[y,125])+str(bmp2[y,126])+str(bmp2[y,127])

      return result

bmp3 = [["B"+loop(x,y) for x in range(bmp2.shape[1]/8)]for y in range(bmp2.shape[0])]

print ", ".join(np.array(bmp3).flatten())


program diatas akan menghasilkan output contohnya sebagai berikut, list arduino untuk gambar dengan resize 16x16 :

B00000000, B00000000, 
B00111110, B01111100, 
B01111111, B11111110, 
B11111111, B11111111, 
B11111111, B11111111, 
B11111111, B11111111, 
B11111111, B11111111, 
B01111111, B11111110, 
B01111111, B11111110, 
B00111111, B11111100, 
B00011111, B11111000, 
B00001111, B11110000,
B00000111, B11100000, 
B00000011, B11000000, 
B00000001, B10000000, 
B00000000, B00000000

gambar aslinya adalah sebagai berikut :











sisipkan list array pada program arduino seperti berikut :


#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

static const unsigned char PROGMEM page2[] = 
{
B00000000, B00000000,
B00111110, B01111100,
B01111111, B11111110,
B11111111, B11111111,
B11111111, B11111111,
B11111111, B11111111,
B11111111, B11111111,
B01111111, B11111110,
B01111111, B11111110,
B00111111, B11111100,
B00011111, B11111000,
B00001111, B11110000,
B00000111, B11100000,
B00000011, B11000000,
B00000001, B10000000,
B00000000, B00000000
};

void setup()   {               
  Serial.begin(9600);

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.display();
  delay(1);

  display.clearDisplay();

  display.clearDisplay();
  testdrawbitmap(page2, 16, 16);
}


void loop() {
}


void testdrawbitmap2(const uint8_t *bitmap, uint8_t w, uint8_t h) {
      display.clearDisplay();
      display.drawBitmap(0, 0, bitmap, h, w, WHITE);
      display.display();
      delay(2000);
}


sumber :
https://learn.adafruit.com/monochrome-oled-breakouts/arduino-library-and-examples

Leave a Reply

Subscribe to Posts | Subscribe to Comments

- Copyright © Legendre-electronics - Date A Live - Powered by Blogger - Designed by Johanes Djogan -