아두이노 esp8266 교육사이트(원본)

https://arduino-esp8266.readthedocs.io/en/2.4.0/index.html

 

esp8266 기반 교육 자료

http://embedded-lab.com/blog/category/esp8266-tutorials/

 

 

esp8266 oled 관련

https://github.com/ThingPulse/esp8266-oled-ssd1306

 

 

esp8266 을 스크레치 같은 그림 언어로 개발 하기

http://easycoding.tn/index.php/category/conferences/

 

 

아두이노 PC GUI 연결 프로그램 저작툴

https://devicedruid.com/about/

 

 

U8g library 설명

http://www.hardcopyworld.com/gnuboard5/bbs/board.php?bo_table=tech_etc&wr_id=15

 

 

U8g library 기반 추가 라이브러리

https://github.com/olikraus/m2tklib/wiki/m2tklib

 

 

OLED 설명

http://www.hardcopyworld.com/ngine/aduino/index.php/archives/762

 

 

U8G 라이브러리 기반 그림 출력 하기

https://kocoafab.cc/tutorial/view/448

 

 

아두이노 기반 프로젝트 모음

http://www.hardcopyworld.com/

 

https://www.kocoafab.cc/tutorial/all?level=1&page=0

 

 

아두이노 font 출력

http://blog.naver.com/PostView.nhn?blogId=compass1111&logNo=221077475023&redirect=Dlog&widgetTypeCall=true

 

 

아두이노 bitmap 출력

http://blog.naver.com/PostView.nhn?blogId=compass1111&logNo=221082215247&parentCategoryNo=&categoryNo=14&viewDate=&isShowPopularPosts=false&from=postView

 

 

아두이노 블루투스 한글 출력

http://orasman.tistory.com/341

 

ESP8266 관련 스터디 자료

http://answerofgod.tistory.com/category/Study/ESP8266%28WIFI%29,ESP32%28BLE,WIFI%29

 

 

아마존알렉사 연결

http://winchild.tistory.com/69

 

 

Visual Studio2015 Community 에서 개발

https://blog.naver.com/crucian2k3/220776868235

 

 

 

 

 

 

 

 

 

 

아두이노 IDE 에서 한개의 파일만 가지고 사용하기에 어려움이 많은데

멀티 파일로 사용이 가능하다.

 

텝 화면의 오른쪽 에 역삼각형 icon 이 있다.

 

 

이 버튼을 누르면 아래와 같이 신규 tab 을 만들수 있다.

 

 

신규 이름을 부여하면 파일이 추가로 등록 된다.

 

관리된는 소스폴더에 가서 보면 생성된 파일을 볼수 있다.

 

 

 

컴파일된것을보면 하나의 파일처럼 컴파일되어 따로 header 로 정의 하지 않아도 사용이 가능하다.

 

 

마찬가지로 폴더에  "xxxx.h" 파일을 생성해서 넣으면 자동으로 파일을 불러 온다.

 

 

위와 같이 같은 디렉토리에 있는 header 파일은 " " 사이에 넣어야 한다.

 

 

 

 

 

 

 

 

 

 

 

'공부 > arduino' 카테고리의 다른 글

esp32 arduino 보드 설명  (0) 2018.04.02
여러 참고 사이트  (0) 2018.03.27
nodeMCU tft LCD 라이브러리변경(Adafruit ->Ucglib)  (0) 2018.03.26
nodeMCU에 ST7735 Tft Lcd 연결  (0) 2018.03.26
nodeMCU oled 드라이브 Adafruit  (0) 2018.03.26

Adafruit 를 사용해서 시험해보니 어느 순간 알수 없는 문제로 오동작이 발생한다.

그래서 해당 라이브러리가 문제가 있는것 같아서 다른 라이브러리인 Ucglib 로 변경해보았다.

 

라이브러리를 설치 한다.

 

 

 

예제소스는 Ucglib 아래의 GraphicsTest.ino 를 사용했다.

 

관련 소스를 바로 사용 할수 없어서 초기 부분만 변경 했다 나머지 부분은 기존 소스를 보면 되니

초기 선언부분만 올리겠다.

 

소스에서는 S/W TEST 도 가능하게 하였으나 실제 TEST 해보면 동작중 먹통이 되어버린다.

S/W 적인 방법은 사용을 안하는 것이 좋을것 같다.

 

-------------------------------------  소스 ------------------------------------------

 


#define dSPI_HW_DEF   1//1:hw spi , 0:sw spi

 

#if dSPI_HW_DEF
  #include <SPI.h>
#endif

 

#include "Ucglib.h"

 

#define OLED_PCLK     D5    //14
#define OLED_PDATA    D7    //13
#define OLED_PRESET   D1    //6
#define OLED_PCMD     D4    //2
#define OLED_PCS     D8     //15

 

#if dSPI_HW_DEF
  Ucglib_ST7735_18x128x160_HWSPI ucg(/*cd=*/ OLED_PCMD, /*cs=*/ OLED_PCS, /*reset=*/ OLED_PRESET);
#else
  Ucglib_ST7735_18x128x160_SWSPI ucg(/*sclk=*/ OLED_PCLK, /*data=*/ OLED_PDATA, /*cd=*/ OLED_PCMD, /*cs=*/ OLED_PCS, /*reset=*/ OLED_PRESET);
#endif

#define T 4000
#define DLY() delay(2000)

 

void setup() {

 

  Serial.begin(115200);
  delay(10);

 

  ucg.begin(UCG_FONT_MODE_TRANSPARENT);
  ucg.setFont(ucg_font_ncenR14_hr);
  ucg.clearScreen();

}

 

void loop() {

 

.........

}

 

 

--------------------------------------------------------------------------------------

 

 

 

 

 

'공부 > arduino' 카테고리의 다른 글

여러 참고 사이트  (0) 2018.03.27
아두이노 멀티 소스 프로젝트  (0) 2018.03.27
nodeMCU에 ST7735 Tft Lcd 연결  (0) 2018.03.26
nodeMCU oled 드라이브 Adafruit  (0) 2018.03.26
nodeMCU oled 드라이브 U8g2  (0) 2018.03.23

Esp8266 nodeMCU 에 ST7735S (해상도 160*128 RGB) tft LCD 를 연결해 봤다.

 

먼저 ST7735 관련 라이브러리를 인스톨 해야 한다.

 

 

S/W SPI 방식과 H/W SPI 방식을 사용해 봤는데 H/W SPI 방식을 사용해야 할것 같다.

S/W SPI 방식은 너무 느려서 동작중 자체 RESET 이 걸렸다. (내부 와치독 동작으로 인해 발생되는것으로 판단된다.)

 

참고 자료는 아래와 같다.

https://forum.arduino.cc/index.php?topic=443787.0

 

http://microcontrollerkits.blogspot.kr/2015/11/esp8266-wifi-tftlcd.html

 

 

사용된 Tft lcd 는 아래와 같다.

 

 

 

연결 회로는 아래와 같다.

 

 

연결된 PIN MAP을 좀더 정리 했다.

 

 

소스상 주의할것은 CLK 과 DATA 는 변경되어서는 안된다.

 

#define dSPI_HW_DEF 1 로 정의 할 경우 H/W SPI로 사용되고 0일 경우 S/W SPI로 사용된다.

 

-------------------------------- 소스 --------------------------------

 

#define dSPI_HW_DEF   1//1:hw spi , 0:sw spi

 

#if dSPI_HW_DEF
  #include <SPI.h>
#endif


#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h> // Hardware-specific library

#define OLED_PCLK     D5    //14
#define OLED_PDATA    D7    //13
#define OLED_PRESET   D1    //6
#define OLED_PCMD     D4    //2
#define OLED_PCS     D8     //15

 

 

#if dSPI_HW_DEF
  Adafruit_ST7735 tft = Adafruit_ST7735(OLED_PCS,  OLED_PCMD, OLED_PRESET);  //h/w: cs,dc,rst
#else
  Adafruit_ST7735  tft(OLED_PCS, OLED_PCMD, OLED_PDATA, OLED_PCLK, OLED_PRESET);  // s/w: cs,dc,sid,sclk,rst
#endif

 

 

float p = 3.1415926;

 

void setup() {

 

  Serial.begin(115200);
  delay(10);
 
  Serial.println("Start..");

 


  // Use this initializer if you're using a 1.8" TFT
  tft.initR(INITR_BLACKTAB);   // initialize a ST7735S chip, black tab
 
  uint16_t time = millis();
  tft.fillScreen(ST7735_BLACK);
  time = millis() - time;
  delay(500);

 


  // large block of text
  tft.fillScreen(ST7735_BLACK);
  testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. ", ST7735_WHITE);
  delay(500);

 

  // tft print function!
  tftPrintTest();
  delay(500);

 

  // a single pixel
  tft.drawPixel(tft.width()/2, tft.height()/2, ST7735_GREEN);
  delay(500);


  // optimized lines
  testfastlines(ST7735_RED, ST7735_BLUE);
  delay(500);

  testdrawrects(ST7735_GREEN);
  delay(500);

  testfillrects(ST7735_YELLOW, ST7735_MAGENTA);
  delay(500);


  tft.fillScreen(ST7735_BLACK);
  testfillcircles(10, ST7735_BLUE);
  testdrawcircles(10, ST7735_WHITE);
  delay(500);

 

  testroundrects();
  delay(500);

 

  testtriangles();
  delay(500);

 

  mediabuttons();
  delay(500);
}

 

 

void loop() {

}

 

void testlines(uint16_t color) {
  tft.fillScreen(ST7735_BLACK);
  for (int16_t x=0; x < tft.width(); x+=6) {
    tft.drawLine(0, 0, x, tft.height()-1, color);
  }
  for (int16_t y=0; y < tft.height(); y+=6) {
    tft.drawLine(0, 0, tft.width()-1, y, color);
  }

  tft.fillScreen(ST7735_BLACK);
  for (int16_t x=0; x < tft.width(); x+=6) {
    tft.drawLine(tft.width()-1, 0, x, tft.height()-1, color);
  }
  for (int16_t y=0; y < tft.height(); y+=6) {
    tft.drawLine(tft.width()-1, 0, 0, y, color);
  }

  tft.fillScreen(ST7735_BLACK);
  for (int16_t x=0; x < tft.width(); x+=6) {
    tft.drawLine(0, tft.height()-1, x, 0, color);
  }
  for (int16_t y=0; y < tft.height(); y+=6) {
    tft.drawLine(0, tft.height()-1, tft.width()-1, y, color);
  }

  tft.fillScreen(ST7735_BLACK);
  for (int16_t x=0; x < tft.width(); x+=6) {
    tft.drawLine(tft.width()-1, tft.height()-1, x, 0, color);
  }
  for (int16_t y=0; y < tft.height(); y+=6) {
    tft.drawLine(tft.width()-1, tft.height()-1, 0, y, color);
  }
}

 

 

void testdrawtext(char *text, uint16_t color) {
  tft.setCursor(0, 0);
  tft.setTextColor(color);
  tft.setTextWrap(true);
  tft.print(text);
}

 

 

void testfastlines(uint16_t color1, uint16_t color2) {
  tft.fillScreen(ST7735_BLACK);
  for (int16_t y=0; y < tft.height(); y+=5) {
    tft.drawFastHLine(0, y, tft.width(), color1);
  }
  for (int16_t x=0; x < tft.width(); x+=5) {
    tft.drawFastVLine(x, 0, tft.height(), color2);
  }
}

 

 

void testdrawrects(uint16_t color) {
  tft.fillScreen(ST7735_BLACK);
  for (int16_t x=0; x < tft.width(); x+=6) {
    tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color);
  }
}

 

 

void testfillrects(uint16_t color1, uint16_t color2) {
  tft.fillScreen(ST7735_BLACK);
  for (int16_t x=tft.width()-1; x > 6; x-=6) {
    tft.fillRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color1);
    tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color2);
  }
}

 

 

void testfillcircles(uint8_t radius, uint16_t color) {
  for (int16_t x=radius; x < tft.width(); x+=radius*2) {
    for (int16_t y=radius; y < tft.height(); y+=radius*2) {
      tft.fillCircle(x, y, radius, color);
    }
  }
}

 

 

void testdrawcircles(uint8_t radius, uint16_t color) {
  for (int16_t x=0; x < tft.width()+radius; x+=radius*2) {
    for (int16_t y=0; y < tft.height()+radius; y+=radius*2) {
      tft.drawCircle(x, y, radius, color);
    }
  }
}

 

 

void testtriangles() {
  tft.fillScreen(ST7735_BLACK);
  int color = 0xF800;
  int t;
  int w = tft.width()/2;
  int x = tft.height()-1;
  int y = 0;
  int z = tft.width();
  for(t = 0 ; t <= 15; t++) {
    tft.drawTriangle(w, y, y, x, z, x, color);
    x-=4;
    y+=4;
    z-=4;
    color+=100;
  }
}

 

 

void testroundrects() {
  tft.fillScreen(ST7735_BLACK);
  int color = 100;
  int i;
  int t;
  for(t = 0 ; t <= 4; t+=1) {
    int x = 0;
    int y = 0;
    int w = tft.width()-2;
    int h = tft.height()-2;
    for(i = 0 ; i <= 16; i+=1) {
      tft.drawRoundRect(x, y, w, h, 5, color);
      x+=2;
      y+=3;
      w-=4;
      h-=6;
      color+=1100;
    }
    color+=100;
  }
}

 

 

void tftPrintTest() {
  tft.setTextWrap(false);
  tft.fillScreen(ST7735_BLACK);
  tft.setCursor(0, 30);
  tft.setTextColor(ST7735_RED);
  tft.setTextSize(1);
  tft.println("Hello World!");
  tft.setTextColor(ST7735_YELLOW);
  tft.setTextSize(2);
  tft.println("Hello World!");
  tft.setTextColor(ST7735_GREEN);
  tft.setTextSize(3);
  tft.println("Hello World!");
  tft.setTextColor(ST7735_BLUE);
  tft.setTextSize(4);
  tft.print(1234.567);
  delay(1500);
  tft.setCursor(0, 0);
  tft.fillScreen(ST7735_BLACK);
  tft.setTextColor(ST7735_WHITE);
  tft.setTextSize(0);
  tft.println("Hello World!");
  tft.setTextSize(1);
  tft.setTextColor(ST7735_GREEN);
  tft.print(p, 6);
  tft.println(" Want pi?");
  tft.println(" ");
  tft.print(8675309, HEX); // print 8,675,309 out in HEX!
  tft.println(" Print HEX!");
  tft.println(" ");
  tft.setTextColor(ST7735_WHITE);
  tft.println("Sketch has been");
  tft.println("running for: ");
  tft.setTextColor(ST7735_MAGENTA);
  tft.print(millis() / 1000);
  tft.setTextColor(ST7735_WHITE);
  tft.print(" seconds.");
}

 

 

void mediabuttons() {
  // play
  tft.fillScreen(ST7735_BLACK);
  tft.fillRoundRect(25, 10, 78, 60, 8, ST7735_WHITE);
  tft.fillTriangle(42, 20, 42, 60, 90, 40, ST7735_RED);
  delay(500);
  // pause
  tft.fillRoundRect(25, 90, 78, 60, 8, ST7735_WHITE);
  tft.fillRoundRect(39, 98, 20, 45, 5, ST7735_GREEN);
  tft.fillRoundRect(69, 98, 20, 45, 5, ST7735_GREEN);
  delay(500);
  // play color
  tft.fillTriangle(42, 20, 42, 60, 90, 40, ST7735_BLUE);
  delay(50);
  // pause color
  tft.fillRoundRect(39, 98, 20, 45, 5, ST7735_RED);
  tft.fillRoundRect(69, 98, 20, 45, 5, ST7735_RED);
  // play color
  tft.fillTriangle(42, 20, 42, 60, 90, 40, ST7735_GREEN);
}

 

 

 

 

----------------------------------------------------------------------

 

 

 

 

 

 

 

 

 

oled 또다른 라이브러리를 넣어봤다.

라이브러리는 Adafruit 에서 만든 것인다.

 

참고 사이트 : https://learn.adafruit.com/monochrome-oled-breakouts/wiring-128x64-oleds

 

먼저 라이브러리를 설치 해야 한다. 라이브러리는 2가지를 설치 해야 한다.

 

Adafruit SSD1306 , Adafruit GFX Library

 

 

 

 

설치 완료후 다시 아두이노 실행하면 된다.

 

소스는 아래와 같다.

 

예제 소스와 동일 하기 때문에 예제 소스를 확인 해도 된다.

 

------------------------------  소스 --------------------------------------------

 

 

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

 

#define OLED_PCLK     D5
#define OLED_PDATA    D7
#define OLED_PRESET   D1
#define OLED_PCMD     D4
#define OLED_PCS     D8

 

Adafruit_SSD1306 display(OLED_PDATA, OLED_PCLK, OLED_PCMD, OLED_PRESET, OLED_PCS);   //MOSI, CLK, DC, RESET, CS

 

#define SSD1306_LCDHEIGHT  64
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
  
#define LOGO16_GLCD_HEIGHT 16 
#define LOGO16_GLCD_WIDTH  16 
static const unsigned char PROGMEM logo16_glcd_bmp[] =
  { B00000000, B11000000,
    B00000001, B11000000,
    B00000001, B11000000,
    B00000011, B11100000,
    B11110011, B11100000,
    B11111110, B11111000,
    B01111110, B11111111,
    B00110011, B10011111,
    B00011111, B11111100,
    B00001101, B01110000,
    B00011011, B10100000,
    B00111111, B11100000,
    B00111111, B11110000,
    B01111100, B11110000,
    B01110000, B01110000,
    B00000000, B00110000 };
  
#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

 

void setup() {

  Serial.begin(115200);
  delay(10);
 
  Serial.println("Start..");

 

  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  display.begin(SSD1306_SWITCHCAPVCC);
  // init done
 
  // Show image buffer on the display hardware.
  // Since the buffer is intialized with an Adafruit splashscreen
  // internally, this will display the splashscreen.
  display.display();
  delay(2000);

 

  // Clear the buffer.
  display.clearDisplay();

 

  // draw a single pixel
  display.drawPixel(10, 10, WHITE);
  // Show the display buffer on the hardware.
  // NOTE: You _must_ call display after making any drawing commands
  // to make them visible on the display hardware!
  display.display();
  delay(2000);

  display.clearDisplay();

 

  // draw many lines
  testdrawline();
  display.display();
  delay(2000);
  display.clearDisplay();

 

  // draw rectangles


  testdrawrect();
  display.display();
  delay(2000);
  display.clearDisplay();

 

  // draw multiple rectangles


  testfillrect();
  display.display();
  delay(2000);
  display.clearDisplay();

 

  // draw mulitple circles


  testdrawcircle();
  display.display();
  delay(2000);
  display.clearDisplay();

 

  // draw a white circle, 10 pixel radius


  display.fillCircle(display.width()/2, display.height()/2, 10, WHITE);
  display.display();
  delay(2000);
  display.clearDisplay();

  testdrawroundrect();
  delay(2000);
  display.clearDisplay();

  testfillroundrect();
  delay(2000);
  display.clearDisplay();

  testdrawtriangle();
  delay(2000);
  display.clearDisplay();
  
  testfilltriangle();
  delay(2000);
  display.clearDisplay();

 

  // draw the first ~12 characters in the font


  testdrawchar();
  display.display();
  delay(2000);
  display.clearDisplay();

 

  // draw scrolling text


  testscrolltext();
  delay(2000);
  display.clearDisplay();

 

  // text display tests


  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("Hello, world!");
  display.setTextColor(BLACK, WHITE); // 'inverted' text
  display.println(3.141592);
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.print("0x"); display.println(0xDEADBEEF, HEX);
  display.display();
  delay(2000);
  display.clearDisplay();

 

  // miniature bitmap display


  display.drawBitmap(30, 16,  logo16_glcd_bmp, 16, 16, 1);
  display.display();

 

  // invert the display


  display.invertDisplay(true);
  delay(1000);
  display.invertDisplay(false);
  delay(1000);
  display.clearDisplay();

 

  // draw a bitmap icon and 'animate' movement


  testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH);

}

 

void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
  uint8_t icons[NUMFLAKES][3];
 
  // initialize
  for (uint8_t f=0; f< NUMFLAKES; f++) {
    icons[f][XPOS] = random(display.width());
    icons[f][YPOS] = 0;
    icons[f][DELTAY] = random(5) + 1;
   
    Serial.print("x: ");
    Serial.print(icons[f][XPOS], DEC);
    Serial.print(" y: ");
    Serial.print(icons[f][YPOS], DEC);
    Serial.print(" dy: ");
    Serial.println(icons[f][DELTAY], DEC);
  }

  while (1) {
    // draw each icon
    for (uint8_t f=0; f< NUMFLAKES; f++) {
      display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, WHITE);
    }
    display.display();
    delay(200);
   
    // then erase it + move it
    for (uint8_t f=0; f< NUMFLAKES; f++) {
      display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, BLACK);
      // move it
      icons[f][YPOS] += icons[f][DELTAY];
      // if its gone, reinit
      if (icons[f][YPOS] > display.height()) {
        icons[f][XPOS] = random(display.width());
        icons[f][YPOS] = 0;
        icons[f][DELTAY] = random(5) + 1;
      }
    }
   }
}


void testdrawchar(void) {
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);

  for (uint8_t i=0; i < 168; i++) {
    if (i == '\n') continue;
    display.write(i);
    if ((i > 0) && (i % 21 == 0))
      display.println();
  }   
  display.display();
}

void testdrawcircle(void) {
  for (int16_t i=0; i<display.height(); i+=2) {
    display.drawCircle(display.width()/2, display.height()/2, i, WHITE);
    display.display();
  }
}

void testfillrect(void) {
  uint8_t color = 1;
  for (int16_t i=0; i<display.height()/2; i+=3) {
    // alternate colors
    display.fillRect(i, i, display.width()-i*2, display.height()-i*2, color%2);
    display.display();
    color++;
  }
}

void testdrawtriangle(void) {
  for (int16_t i=0; i<min(display.width(),display.height())/2; i+=5) {
    display.drawTriangle(display.width()/2, display.height()/2-i,
                     display.width()/2-i, display.height()/2+i,
                     display.width()/2+i, display.height()/2+i, WHITE);
    display.display();
  }
}

void testfilltriangle(void) {
  uint8_t color = WHITE;
  for (int16_t i=min(display.width(),display.height())/2; i>0; i-=5) {
    display.fillTriangle(display.width()/2, display.height()/2-i,
                     display.width()/2-i, display.height()/2+i,
                     display.width()/2+i, display.height()/2+i, WHITE);
    if (color == WHITE) color = BLACK;
    else color = WHITE;
    display.display();
  }
}

void testdrawroundrect(void) {
  for (int16_t i=0; i<display.height()/2-2; i+=2) {
    display.drawRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, WHITE);
    display.display();
  }
}

void testfillroundrect(void) {
  uint8_t color = WHITE;
  for (int16_t i=0; i<display.height()/2-2; i+=2) {
    display.fillRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, color);
    if (color == WHITE) color = BLACK;
    else color = WHITE;
    display.display();
  }
}
  
void testdrawrect(void) {
  for (int16_t i=0; i<display.height()/2; i+=2) {
    display.drawRect(i, i, display.width()-2*i, display.height()-2*i, WHITE);
    display.display();
  }
}

void testdrawline() { 
  for (int16_t i=0; i<display.width(); i+=4) {
    display.drawLine(0, 0, i, display.height()-1, WHITE);
    display.display();
  }
  for (int16_t i=0; i<display.height(); i+=4) {
    display.drawLine(0, 0, display.width()-1, i, WHITE);
    display.display();
  }
  delay(250);
 
  display.clearDisplay();
  for (int16_t i=0; i<display.width(); i+=4) {
    display.drawLine(0, display.height()-1, i, 0, WHITE);
    display.display();
  }
  for (int16_t i=display.height()-1; i>=0; i-=4) {
    display.drawLine(0, display.height()-1, display.width()-1, i, WHITE);
    display.display();
  }
  delay(250);
 
  display.clearDisplay();
  for (int16_t i=display.width()-1; i>=0; i-=4) {
    display.drawLine(display.width()-1, display.height()-1, i, 0, WHITE);
    display.display();
  }
  for (int16_t i=display.height()-1; i>=0; i-=4) {
    display.drawLine(display.width()-1, display.height()-1, 0, i, WHITE);
    display.display();
  }
  delay(250);

  display.clearDisplay();
  for (int16_t i=0; i<display.height(); i+=4) {
    display.drawLine(display.width()-1, 0, 0, i, WHITE);
    display.display();
  }
  for (int16_t i=0; i<display.width(); i+=4) {
    display.drawLine(display.width()-1, 0, i, display.height()-1, WHITE);
    display.display();
  }
  delay(250);
}

void testscrolltext(void) {
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(10,0);
  display.clearDisplay();
  display.println("scroll");
  display.display();
 
  display.startscrollright(0x00, 0x0F);
  delay(2000);
  display.stopscroll();
  delay(1000);
  display.startscrollleft(0x00, 0x0F);
  delay(2000);
  display.stopscroll();
  delay(1000);   
  display.startscrolldiagright(0x00, 0x07);
  delay(2000);
  display.startscrolldiagleft(0x00, 0x07);
  delay(2000);
  display.stopscroll();
}

 

 

----------------------------------------------------------------------------------

 

 

 

 

 

 

'공부 > arduino' 카테고리의 다른 글

nodeMCU tft LCD 라이브러리변경(Adafruit ->Ucglib)  (0) 2018.03.26
nodeMCU에 ST7735 Tft Lcd 연결  (0) 2018.03.26
nodeMCU oled 드라이브 U8g2  (0) 2018.03.23
nodeMCU web 따라하기 3  (0) 2018.03.12
nodeMCU Web 따라하기 2  (0) 2018.03.12

OLED 디스프레이를 위해서 구매를 했다.

 

인터넷을 검색해 보니 I2C 의 속도가 느려서 SPI를 추천한다고 해서 SPI 방식으로 구매했다.

 

구매사이트는 인터넷 가장 싼곳으로 당연히 메뉴얼도 존재 하지 않는 사이트...ㅠㅠ

 

일단 아두이노에 라이브러리를 선택 했다.

여러가지 라이브러리중 업그레이드가 가장 많이 된것 같은 U8G2를 선택 했다.

다른사람들 평에는 속도빠르고 버퍼를 작게 먹는 다고 되어 있어서 선택의 폭을 줄일수 있었다.

 

사이트는  : https://github.com/olikraus/u8g2

 

설치는 아래와 같은 방법으로 진행 했다.

 

 

 

 

케이블 연결을 위해 자료 조사를 진행 했다.

 

참고 사이트 :  https://github.com/jandelgado/arduino/wiki/SSD1306-based-OLED-connected-to-Arduino

 

참고로 사진상의 내용과 같이 저항 연결에 따라 I2C, SPI 모드 선택이 가능하다.

 

 

사이트에서 추천한 PIN 연결은 아래와 같았다.

 

 

 

하지만 위와 같이 연결할경우 기존에 사용중이던 소스에서 D0 (LED) 가 겹쳐서 해당 PIN 을 변경 했다.

처음 봤을때는 SPI를 하드웨어로 동작하는걸로 생각했는데 결국은 GPIO 제어가 되어야하는 것으로

보여서 아무생각없이 PIN MAP 을 변경 했다.

 

SSD1306

 

 

nodeMCU

특징

1

GND

 

GND

전원

2

VDD

 

3.3V

전원

3

SCK(D0)

 

D5(GPIO14)

CLOCK

4

SDA(D1)

 

D7(GPIO13)

DATA(MOSI)

5

RES

 

D1(GPIO5)

RESET

6

DC

 

D4(GPIO2)

DATA/COMMAND

7

CS

 

D8(GPIO15)

CHIP SELECT

 

 

연결 회로도는 아래와 같다.

 

 

참고고 OLED 회로도는 아래와 같다.

 

 

 

소스는 예제 소스 기준으로 작성 하였다. (기존 소스에 그대로 사용했다.)

 

좋은 점은  한글 출력이 가능 하다는 점이다.  ( setup에 테스트 코드만 넣어서 해당 코드만 올림)

 

------------------------  소스 --------------------------

 

#include <ESP8266WiFi.h>
#include <Ticker.h>

 

#include <Arduino.h>
#include <U8g2lib.h>
//#include <U8x8lib.h>


#define LED     D0    //LED PIN define
#define KEY_IN  D3    //Flash key pin define
#define ANALOG_IN A0  //analog in define

#define OLED_PCLK     D5
#define OLED_PDATA    D7
#define OLED_PRESET   D1
#define OLED_PCMD     D4
#define OLED_PCS     D8

 

//GIPO롤 출력하는 가장 기본 적인 설정

U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ OLED_PCLK, /* data=*/ OLED_PDATA, /* cs=*/ OLED_PCS, /* dc=*/ OLED_PCMD, /* reset=*/ OLED_PRESET);

 

 

// the setup function runs once when you press reset or power the board
void setup() {
  Serial.begin(115200);
  delay(10);
 
  Serial.println("Start..");

  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED, OUTPUT);
  pinMode(KEY_IN, INPUT);   // == pinMode(KEY_IN, INPUT);

  
  u8g2.begin();
 
  u8g2.clearBuffer();          // clear the internal memory
  u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
  u8g2.drawStr(0,10,"Hello World!");  // write something to the internal memory
  u8g2.sendBuffer();          // transfer internal memory to the display

  delay(1000);

 

  u8g2.clearBuffer();          // clear the internal memory
  u8g2.setFontDirection(0);
  u8g2.setFont(u8g2_font_inb24_mf);
  u8g2.drawStr(0, 30, "U");
 
  u8g2.setFontDirection(1);
  u8g2.setFont(u8g2_font_inb30_mn);
  u8g2.drawStr(21,8,"8");
     
  u8g2.setFontDirection(0);
  u8g2.setFont(u8g2_font_inb24_mf);
  u8g2.drawStr(51,30,"g");
  u8g2.drawStr(67,30,"\xb2");
 
  u8g2.drawHLine(2, 35, 47);
  u8g2.drawHLine(3, 36, 47);
  u8g2.drawVLine(45, 32, 12);
  u8g2.drawVLine(46, 33, 12);

  u8g2.sendBuffer();

 
  delay(1000);
 
  u8g2.clearBuffer();          // clear the internal memory

  u8g2.enableUTF8Print();    // enable UTF8 support for the Arduino print() function
  u8g2.setFont(u8g2_font_unifont_t_korean1); 
  u8g2.setFontDirection(0);

 

  //u8g2.firstPage();
  u8g2.setCursor(0, 15);
  u8g2.print("Hello World!");
  u8g2.setCursor(0, 35);
  u8g2.print("안녕 세상");    // Korean "Hello World"

  u8g2.setFont(u8g2_font_unifont_t_korean2); 
  u8g2.setFontDirection(0);

  u8g2.setCursor(0, 55);
  u8g2.print("안녕 세상");    // Korean "Hello World"

 

  u8g2.sendBuffer();

 
}

 

 

// the loop function runs over and over again forever
void loop() {
}

 

----------------------------------------------------------

 

 

출력 화면 예 입니다.

 

   

 

 

 

 

 

 

 

 

 

'공부 > arduino' 카테고리의 다른 글

nodeMCU에 ST7735 Tft Lcd 연결  (0) 2018.03.26
nodeMCU oled 드라이브 Adafruit  (0) 2018.03.26
nodeMCU web 따라하기 3  (0) 2018.03.12
nodeMCU Web 따라하기 2  (0) 2018.03.12
nodeMCU web 따라하기  (0) 2018.03.12

LED 제어 하고 상태 확인 가능하도록 수정 했다.

 

원본 소스

 

http://wglab.tk/221175139758

 

 

-------------------------- 소스 ----------------------------

#include <ESP8266WiFi.h>
#include <Ticker.h>

#define LED     D0    //LED PIN define
#define KEY_IN  D3    //Flash key pin define
#define ANALOG_IN A0  //analog in define


Ticker flipper1;
Ticker flipper2;


const char *ssid =  "WIFI";     // replace with your wifi ssid and wpa2 key
const char *pass =  "----";

WiFiClient client;

unsigned int prt_index = 0;
unsigned char led_flag = 0;


void flip_test();
void led_test();

WiFiServer server(80);

// the setup function runs once when you press reset or power the board
void setup() {
  Serial.begin(115200);
  delay(10);
 
  Serial.println("Start..");

  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED, OUTPUT);
  pinMode(KEY_IN, INPUT);   // == pinMode(KEY_IN, INPUT);

  Serial.println("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, pass);
 
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
 
  Serial.println("");
  Serial.println("WiFi connected");

  Serial.print("MAC: ");
  Serial.println(WiFi.macAddress());

  // Start the server
  server.begin();
  Serial.println("Server started");

  // Print the IP address
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");
 
  flipper1.attach(0.3, flip_test);    //start , ms
  //flipper2.attach(0.5, led_test);       //start , ms

  //flipper.detach(); //stop
}

// the loop function runs over and over again forever
void loop() {

  int buttonState = digitalRead(KEY_IN);
  if (buttonState == 0)
  {
    Serial.printf("button key input !! \n");
  }

  WiFiClient client = server.available();
  if (client)
  {
    Serial.println("new client");
    while(!client.available()){
    delay(1);
    }

    //요청을 읽는다.
    String request = client.readStringUntil('\r');
    Serial.println(request);
    client.flush();
 
    //사용자가 접속한 URL읽어서 판별
    if (request.indexOf("/ON") > 0) { //1이면
      Serial.println("LED ON");
      digitalWrite(LED, LOW);
    }
    if (request.indexOf("/OFF") > 0) { //0이면
      Serial.println("LED OFF");
      digitalWrite(LED, HIGH);
    }

    // Match the request
    int val1 = digitalRead(LED);;

    // Prepare the response
    int sensorReading = analogRead(ANALOG_IN);
    String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\n ";
    s += "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">";     //한글출력
    s += "<body>";   
    s += "<h1>LED is now = ";
    s += (val1)?"OFF<p>":"ON<p>";
    s += "Analog Value is now = ";
    s += (sensorReading);
    s += "</h1><p>";
   
    // Send the response to the client
    client.print(s);

    //-----
    client.println("<svg height='210' width='300'>");
    int val = analogRead(A0)/5;
    int y1 = 200-val;
    for(int i=1;i<300;i++){
      // 아나로그입력 생성(0-1023):1023=3.3V
      int x1 = (i-1);
      int x2 = i;
      int val = analogRead(A0)/5;
      int y2 = 200-val;
      client.println("<line x1='");
 
      client.println(x1);
      client.println("' y1='");
      client.println(y1);
      client.println("' x2='"); 
      client.println(x2);
      client.println("' y2='");
      client.println(y2);
      client.println("'");
      client.println("' style='stroke:rgb(255,0,0);stroke-width:2' />");
      client.println("Sorry, your browser does not support inline SVG.");
      y1 = y2;
    }

    client.println("</svg>");
    client.println("  </body>");
   
    client.println("<br><br>");   
    client.println("<a href=\"/ON\"\"><button>LED 점등 </button></a>");
    client.println("<a href=\"/OFF\"\"><button>LED 소등 </button></a><br />");
   
    client.println("<br><br>");
    client.println("<a href=\"/reflsh\"\"><button>Data Refresh </button></a><br />");          
    client.println("</html>");
    delay(1);
     
    Serial.println("Client disonnected");
  }

}

//-------------------
void flip_test()
{
  int inputA_val = analogRead(ANALOG_IN);
 
  prt_index ++;
  //Serial.printf("%d",prt_index);
  switch (prt_index % 4)
  {
    case 0:
      Serial.printf("^");
      break;

    case 1:
      Serial.printf("-");
      break;

    case 2:
      Serial.printf("^");
      break;

    case 3:
      Serial.printf("; , B: %d \n", inputA_val);
      break;
  }
}

//--------------------
void led_test()
{
  if (led_flag)
  {
    led_flag = 0;
    digitalWrite(LED, LOW);    // turn the LED off by making the voltage LOW
  }
  else
  {
    led_flag = 1;
    digitalWrite(LED, HIGH);   // turn the LED on (HIGH is the voltage level)
  }
}

-------------------------------------------------------------

 

--------------------------- 출력 ---------------------------

 

 

-------------------------------------------------------------

 

 

 

'공부 > arduino' 카테고리의 다른 글

nodeMCU oled 드라이브 Adafruit  (0) 2018.03.26
nodeMCU oled 드라이브 U8g2  (0) 2018.03.23
nodeMCU Web 따라하기 2  (0) 2018.03.12
nodeMCU web 따라하기  (0) 2018.03.12
nodeMCU wifi 연결  (0) 2018.03.12

nodeMCU Web 따라하기 2

 

원천 소스

http://blog.daum.net/ejleep1/332

 

기존소스와 현재 소스 합쳐서 만들었다.

 

-------------------------------- 소스 -----------------------------------

#include <ESP8266WiFi.h>
#include <Ticker.h>

#define LED     D0    //LED PIN define
#define KEY_IN  D3    //Flash key pin define
#define ANALOG_IN A0  //analog in define


Ticker flipper1;
Ticker flipper2;


const char *ssid =  "wifi";     // replace with your wifi ssid and wpa2 key
const char *pass =  "----";

WiFiClient client;

unsigned int prt_index = 0;
unsigned char led_flag = 0;


void flip_test();
void led_test();

WiFiServer server(80);

// the setup function runs once when you press reset or power the board
void setup() {
  Serial.begin(115200);
  delay(10);
 
  Serial.println("Start..");

  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED, OUTPUT);
  pinMode(KEY_IN, INPUT);   // == pinMode(KEY_IN, INPUT);

  Serial.println("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, pass);
 
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
 
  Serial.println("");
  Serial.println("WiFi connected");

  Serial.print("MAC: ");
  Serial.println(WiFi.macAddress());

  // Start the server
  server.begin();
  Serial.println("Server started");

  // Print the IP address
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");
 
  flipper1.attach(0.3, flip_test);    //start , ms
  flipper2.attach(0.5, led_test);       //start , ms

  //flipper.detach(); //stop
}

// the loop function runs over and over again forever
void loop() {

  int buttonState = digitalRead(KEY_IN);
  if (buttonState == 0)
  {
    Serial.printf("button key input !! \n");
  }

  WiFiClient client = server.available();
  if (client)
  {
    Serial.println("new client");
    while(!client.available()){
    delay(1);
    }

    // Read the first line of the request
    String req = client.readStringUntil('\r');
    Serial.println(req);
    client.flush();
 
    // Match the request
    int val1 = 0;
    /*if (req.indexOf("/gpio/0") != -1)
    val = 0;
    else if (req.indexOf("/gpio/1") != -1)
    val = 1;
    else {
    Serial.println("invalid request");
    client.stop();
    return;
    }
*/
    // Prepare the response
    int sensorReading = analogRead(ANALOG_IN);
    String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\n <body> <h1>GPIO2 is now = ";
    s += (val1)?"high<p>":"low<p>";
    s += "Analog Value is now = ";
    s += (sensorReading);
    s += "</h1><p>";
    //s += "<img src='https://lh4.ggpht.com/yPq0eEBNR4g530UHDfpbtwe-yiAMLVjUcnGCsjW9_K9VniuLr_YbeefSsd3uqYvZWJ8=w300'><p>";
    //s += "<iframe width='560' height='315' src='https://www.youtube.com/embed/ZicP4y-nFg4' frameborder='0' allowfullscreen></iframe>";
    //s += "</html>\n";
    // Send the response to the client
    client.print(s);

    //-----
    client.println("<svg height='210' width='300'>");
    int val = analogRead(A0)/5;
    int y1 = 200-val;
    for(int i=1;i<300;i++){
      // 아나로그입력 생성(0-1023):1023=3.3V
      int x1 = (i-1);
      int x2 = i;
      int val = analogRead(A0)/5;
      int y2 = 200-val;
      client.println("<line x1='");
 
      client.println(x1);
      client.println("' y1='");
      client.println(y1);
      client.println("' x2='"); 
      client.println(x2);
      client.println("' y2='");
      client.println(y2);
      client.println("'");
      client.println("' style='stroke:rgb(255,0,0);stroke-width:2' />");
      client.println("Sorry, your browser does not support inline SVG.");
      y1 = y2;
    }

    client.println("</svg>");
    //client.println("  </body>");
    client.println("<br><br>");
    client.println("<a href=\"/on\"\"><button>Data Refresh </button></a><br />");          
    client.println("</html>");
    delay(1);
    delay(1);
    Serial.println("Client disonnected");
  }
 
}

//-------------------
void flip_test()
{
  int inputA_val = analogRead(ANALOG_IN);
 
  prt_index ++;
  //Serial.printf("%d",prt_index);
  switch (prt_index % 4)
  {
    case 0:
      Serial.printf("^");
      break;

    case 1:
      Serial.printf("-");
      break;

    case 2:
      Serial.printf("^");
      break;

    case 3:
      Serial.printf("; , B: %d \n", inputA_val);
      break;
  }
}

//--------------------
void led_test()
{
  if (led_flag)
  {
    led_flag = 0;
    digitalWrite(LED, LOW);    // turn the LED off by making the voltage LOW
  }
  else
  {
    led_flag = 1;
    digitalWrite(LED, HIGH);   // turn the LED on (HIGH is the voltage level)
  }
}

--------------------------------------------------------------------------

 

-------------------------------- 출력 -----------------------------------

 

 

 

--------------------------------------------------------------------------

 

'공부 > arduino' 카테고리의 다른 글

nodeMCU oled 드라이브 U8g2  (0) 2018.03.23
nodeMCU web 따라하기 3  (0) 2018.03.12
nodeMCU web 따라하기  (0) 2018.03.12
nodeMCU wifi 연결  (0) 2018.03.12
nodeMCU analog input 업데이트  (0) 2018.03.10

+ Recent posts