esp32 + oled 보드에 한글과 web을 올리고 free rtos 를 사용했다.

 

컴파일을 하기위헤서는 라이브러리를 링크 해야 한다.

 

 

 

 

#include "Arduino.h"
#include <WiFi.h>

 

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

 

#include "ASCFont.h"
#include "KSFont.h"

 

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

 

#define OLED_PCLK     18
#define OLED_PDATA    23
#define OLED_PRESET   17
#define OLED_PCMD     16
#define OLED_PCS     5

#define LED 2

 

//----- Graphic define
#define NUMFLAKES 10
#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 };


byte HANFontImage[32] = {0, };

 

//HW SPI
Adafruit_SSD1306 display(OLED_PCMD, OLED_PRESET, OLED_PCS); //DC, RST, CS
String inputString;

 

//----- FreeRtos
QueueHandle_t queue;
int queueSize = 10;

 

QueueHandle_t xQueue;

 

typedef struct{
  int sender;
  int counter;
}Data;

 

// 세마포어 핸들을 선언합니다.->선언될때만 TASK 실행
SemaphoreHandle_t sem;


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

 

WiFiClient client;

WiFiServer server(80);

 

//The setup function is called once at startup of the sketch
void setup()
{
 // Add your initialization code here
 pinMode(LED, OUTPUT);

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

 

    //--------------------------------
    //OLED OUTPUT

    display.begin(SSD1306_SWITCHCAPVCC); //SPI


    display.display();  //diplay output
    delay(2000);
    display.clearDisplay(); // Clear the buffer.

 

    inputString="*--동작 시작--*" ;

    char paramChar[inputString.length()+1];
    inputString.toCharArray(paramChar,inputString.length()+1);
    matrixPrint(0,0,paramChar);
    display.display();  //diplay output

    //--------------------------------

    //Web init
    WiFi.begin(ssid, pass);

    while (WiFi.status() != WL_CONNECTED)
    {
      delay(500);
      Serial.print(".");
    }


    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("/");

 

    display.setTextSize(1);
    display.setTextColor(WHITE);
    display.setCursor(0,18);
    display.print("http://");
    display.print(WiFi.localIP());
    display.println("/");
    display.display();  //diplay output

 

    //---------------------------------
    Serial.println("Start..");

 

   //Free Rtos Q Set
   queue = xQueueCreate( queueSize, sizeof( int ) );
   if(queue == NULL){
     Serial.println("Error creating the queue");
   }

 

   xQueue = xQueueCreate(5, sizeof(Data));
   if(xQueue == NULL){
     Serial.println("Error creating the queue");
   }

 

   //세마포어를 초기화 합니다. 세마포어는 동시에 1개만 생성됩니다.
   sem = xSemaphoreCreateCounting(1, 0);


 //Free Rtos Task Set
 xTaskCreate(
     taskOne,          /* Task function. */
     "TaskOne",        /* String with name of task. */
     1024,            /* Stack size in words. 10000->1024*/
     NULL,             /* Parameter passed as input of the task */
     1,                /* Priority of the task. */
     NULL);            /* Task handle. */

 

 xTaskCreate(
     taskTwo,          /* Task function. */
     "TaskTwo",        /* String with name of task. */
     1024,            /* Stack size in words. */
     NULL,             /* Parameter passed as input of the task */
     1,                /* Priority of the task. */
     NULL);            /* Task handle. */

 

 xTaskCreate(
     taskWeb,          /* Task function. */
     "TaskWeb",        /* String with name of task. */
     1024,            /* Stack size in words. */
     NULL,             /* Parameter passed as input of the task */
     1,                /* Priority of the task. */
     NULL);            /* Task handle. */

 

 xTaskCreate(
     taskSAM,          /* Task function. */
     "taskSAM",        /* String with name of task. */
     1024,            /* Stack size in words. */
     NULL,             /* Parameter passed as input of the task */
     1,                /* Priority of the task. */
     NULL);            /* Task handle. */

}

 

// The loop function is called in an endless loop
void loop()
{
 delay(1000);

}


void taskOne( void * parameter )
{
  /* keep the status of sending data */
 BaseType_t xStatus;
 /* time to block the task until the queue has free space */
 const TickType_t xTicksToWait = pdMS_TO_TICKS(100);

 /* create data to send */
 Data data;

 /* sender 1 has id is 1 */
 data.sender = 1;
 data.counter = 1;

 for(;;){
  for( int i = 0;i<10;i++ ){

   Serial.println("Hello from task 1");
   digitalWrite(LED, 1);
   //digitalWrite(LED, 0);

   xQueueSend(queue, &i, portMAX_DELAY);

      xStatus = xQueueSendToFront( xQueue, &data, xTicksToWait );
      /* check whether sending is ok or not */
      if( xStatus == pdPASS ) {
        /* increase counter of sender 1 */
        data.counter = data.counter + 1;
      }

   delay(1000);
  }
 }
    Serial.println("Ending task 1");
    vTaskDelete( NULL );

}

 

 

void taskTwo( void * parameter)
{
 /* keep the status of receiving data */
 BaseType_t xStatus;
 /* time to block the task until data is available */
 const TickType_t xTicksToWait = pdMS_TO_TICKS(100);
 Data data;

 int element;

 for(;;){
  for( int i = 0;i<10;i++ ){

   xQueueReceive(queue, &element, portMAX_DELAY);
   Serial.print(element);
   Serial.print(" -> ");

      /* receive data from the queue */
      xStatus = xQueueReceive( xQueue, &data, xTicksToWait );
      /* check whether receiving is ok or not */
      if(xStatus == pdPASS){
        /* print the data to terminal */
        Serial.print("receiveTask got data: ");
        Serial.print("sender = ");
        Serial.print(data.sender);
        Serial.print(" counter = ");
        Serial.println(data.counter);
      }

   Serial.println("Hello from task 2");
   delay(1000);


  }
 }
    Serial.println("Ending task 2");
    vTaskDelete( NULL );

}

 

 

void taskWeb( void * parameter)
{
 for(;;){

  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);
      int sensorReading = 100;

      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");

      //세마포어를 전달합니다.
      xSemaphoreGive(sem);

  }

 }

    Serial.println("Ending task Web");
    vTaskDelete( NULL );
}

 

 

void taskSAM( void * parameter)
{
   while (1) {

     //세마포어를 받을때까지 스레드는 계속 기다리게 됩니다.
     xSemaphoreTake(sem, portMAX_DELAY);

     Serial.println(">>> Semaphore Run!");

   }

}

 

 

//한글 라이브러리 처리
void matrixPrint(int XPOS,int YPOS,char *pChar){
  //byte rg = 3;   //<b1> red, <b0> green
  byte *pFs;
  //byte i, b;
  byte c, c2, c3;

  while(*pChar){
    c = *(byte*)pChar++;

    //---------- �ѱ� ---------
    if(c >= 0x80){
      c2 = *(byte*)pChar++;
      c3 = *(byte*)pChar++;
      //Serial.print(c,DEC);
      //Serial.print(c2,DEC);
      //Serial.print(c3,DEC);
      pFs = getHAN_font(c, c2, c3);
      display.drawBitmap(XPOS, YPOS,  pFs, 16, 16, 1);
      XPOS = XPOS+16;
      if(XPOS > 128){
        XPOS = 0;
        YPOS = YPOS+16;
      }
    }
    //---------- ASCII ---------
    else{
      pFs = (byte*)ASCfontSet + ((byte)c - 0x20) * 16;
      display.drawBitmap(XPOS, YPOS,  pFs, 8, 16, 1);
      XPOS = XPOS+8;
      if(XPOS > 128){
        XPOS = 0;
        YPOS = YPOS+16;
      }
    }
  }
}


/*=============================================================================
한글 font 처리부분  "주의 : 파일 형식을 UTF-8 로 꼭 사용해야 한다.
  =============================================================================*/
uint16_t utf16_d;

byte *getHAN_font(byte HAN1, byte HAN2, byte HAN3)
{

  const byte cho[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 3, 3, 1, 2, 4, 4, 4, 2, 1, 3, 0 };
  const byte cho2[] = { 0, 5, 5, 5, 5, 5, 5, 5, 5, 6, 7, 7, 7, 6, 6, 7, 7, 7, 6, 6, 7, 5 };
  const byte jong[] = { 0, 0, 2, 0, 2, 1, 2, 1, 2, 3, 0, 2, 1, 3, 3, 1, 2, 1, 3, 3, 1, 1 };


  byte first, mid, lastcode;
  byte firstType, midType;
  byte last_Type = 0 ;
  byte i;
  byte *pB, *pF;

  /*------------------------------
    UTF-8 -> UTF-16 change
    UTF-8 1110xxxx 10xxxxxx 10xxxxxx
  */------------------------------

  utf16_d = (uint16_t)((HAN1 & 0x0f) << 12) | (uint16_t)((HAN2 & 0x3f) << 6) | (uint16_t)(HAN3 & 0x3f);

  /*------------------------------
    초,중,종성 코드를 분리해 낸다.

    unicode = {[(초성 * 21) + 중성] * 28}+ 종성 + 0xAC00

          0   1  2  3  4  5  6  7  8  9  10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
    초성 ㄱ   ㄲ ㄴ ㄷ ㄸ ㄹ ㅁ ㅂ ㅃ ㅅ ㅆ ㅇ ㅈ ㅉ ㅊ ㅋ ㅌ ㅍ ㅎ
    중성 ㅏ   ㅐ ㅑ ㅒ ㅓ ㅔ ㅕ ㅖ ㅗ ㅘ ㅙ ㅚ ㅛ ㅜ ㅝ ㅞ ㅟ ㅠ ㅡ ㅢ ㅣ
    종성 없음 ㄱ ㄲ ㄳ ㄴ ㄵ ㄶ ㄷ ㄹ ㄺ ㄻ ㄼ ㄽ ㄾ ㄿ ㅀ ㅁ ㅂ ㅄ ㅅ ㅆ ㅇ ㅈ ㅊ ㅋ ㅌ ㅍ ㅎ
  ------------------------------*/
  utf16_d -= 0xac00;
  lastcode = utf16_d % 28;
  utf16_d /= 28;
  mid = utf16_d % 21;
  first = utf16_d / 21;

  first++;
  mid++;

  /*------------------------------
    초,중,종성 해당 폰트 타입(벌)을 결정한다.
  ------------------------------*/

  /*
   초성 19자:ㄱㄲㄴㄷㄸㄹㅁㅂㅃㅅㅆㅇㅈㅉㅊㅋㅌㅍㅎ
   중성 21자:ㅏㅐㅑㅒㅓㅔㅕㅖㅗㅘㅙㅚㅛㅜㅝㅞㅟㅠㅡㅢㅣ
   종성 27자:ㄱㄲㄳㄴㄵㄶㄷㄹㄺㄻㄼㄽㄾㄿㅀㅁㅂㅄㅆㅇㅈㅊㅋㅌㅍㅎ

   초성
      초성 1벌 : 받침없는 'ㅏㅐㅑㅒㅓㅔㅕㅖㅣ' 와 결합
      초성 2벌 : 받침없는 'ㅗㅛㅡ'
      초성 3벌 : 받침없는 'ㅜㅠ'
      초성 4벌 : 받침없는 'ㅘㅙㅚㅢ'
      초성 5벌 : 받침없는 'ㅝㅞㅟ'
      초성 6벌 : 받침있는 'ㅏㅐㅑㅒㅓㅔㅕㅖㅣ' 와 결합
      초성 7벌 : 받침있는 'ㅗㅛㅜㅠㅡ'
      초성 8벌 : 받침있는 'ㅘㅙㅚㅢㅝㅞㅟ'

   중성
      중성 1벌 : 받침없는 'ㄱㅋ' 와 결합
      중성 2벌 : 받침없는 'ㄱㅋ' 이외의 자음
      중성 3벌 : 받침있는 'ㄱㅋ' 와 결합
      중성 4벌 : 받침있는 'ㄱㅋ' 이외의 자음

   종성
      종성 1벌 : 중성 'ㅏㅑㅘ' 와 결합
      종성 2벌 : 중성 'ㅓㅕㅚㅝㅟㅢㅣ'
      종성 3벌 : 중성 'ㅐㅒㅔㅖㅙㅞ'
      종성 4벌 : 중성 'ㅗㅛㅜㅠㅡ'

  */
  if(!lastcode){  //��ħ ���� ���
    firstType = cho[mid];
    if(first == 1 || first == 24) midType = 0;
    else midType = 1;
  }
  else{       //��ħ �ִ� ���
    firstType = cho2[mid];
    if(first == 1 || first == 24) midType = 2;
    else midType = 3;
    last_Type = jong[mid];
  }
  memset(HANFontImage, 0, 32);

  //�ʼ�
  pB = HANFontImage;
  pF = (byte*)KSFont + (firstType*20 + first)*32;
  i = 32;
  while(i--) *pB++ = pgm_read_byte(pF++);

  //�߼�
  pB = HANFontImage;
  pF = (byte*)KSFont + (8*20 + midType*22 + mid)*32;
  i = 32;
  while(i--) *pB++ |= pgm_read_byte(pF++);

  //����
  if(lastcode){
    pB = HANFontImage;
    pF = ((byte*)KSFont) + ((8*20) + (4*22) + (last_Type*28) + lastcode)*32;
    i = 32;
    while(i--) *pB++ |= pgm_read_byte(pF++);
  }

  return HANFontImage;
}


static byte c1;  // Last character buffer
byte utf8ascii(byte ascii) {
    if ( ascii<128 )   // Standard ASCII-set 0..0x7F handling
    {   c1=0;
        return( ascii );
    }

    // get previous input
    byte last = c1;   // get last char
    c1=ascii;         // remember actual character

    switch (last)     // conversion depnding on first UTF8-character
    {   case 0xC2: return  (ascii);  break;
        case 0xC3: return  (ascii | 0xC0);  break;
        case 0x82: if(ascii==0xAC) return(0x80);       // special case Euro-symbol
    }

    return  (0);                                     // otherwise: return zero, if character has to be ignored
}

String utf8ascii(String s)
{
        String r="";
        char c;
        for (int i=0; i<s.length(); i++)
        {
                c = utf8ascii(s.charAt(i));
                if (c!=0) r+=c;
        }
        return r;
}
void utf8ascii(char* s)
{
        int k=0;
        char c;
        for (int i=0; i<strlen(s); i++)
        {
                c = utf8ascii(s[i]);
                if (c!=0)
                        s[k++]=c;
        }
        s[k]=0;
}

 

 

 

 

      

 

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

ESP32 DAC를 이용한 사운드 출력  (0) 2019.06.25
esp32 ble test  (0) 2018.04.12
esp32 free rtos 사용  (0) 2018.04.12
esp32 oled 한글 올리기  (0) 2018.04.12
esp32 아두이노 라이브러리 업그레이드  (0) 2018.04.12

ESP32의  "Arduino.h"  의 내용을 살펴보면

기본적으로 아래의 내용이 포함되어 있었다.

 

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"

 

즉 freertos 를 사용할수 있는 것이다.

테스트를 진행 했다.

 

#include "Arduino.h"
#include <Wire.h>
#include <SPI.h>

 

#include "ASCFont.h"
#include "KSFont.h"

 

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

 

#define OLED_PCLK     18
#define OLED_PDATA    23
#define OLED_PRESET   17
#define OLED_PCMD     16
#define OLED_PCS     5

#define LED 2
 

//----- FreeRtos
QueueHandle_t queue;
int queueSize = 10;

 

QueueHandle_t xQueue;

 

typedef struct{
  int sender;
  int counter;
}Data;

// 세마포어 핸들을 선언합니다.->선언될때만 TASK 실행
SemaphoreHandle_t sem;

//The setup function is called once at startup of the sketch
void setup()
{
 // Add your initialization code here
 pinMode(LED, OUTPUT);

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

 //---------------------------------
 Serial.println("Start..");

 

 //Free Rtos Q Set
 queue = xQueueCreate( queueSize, sizeof( int ) );

 if(queue == NULL){
   Serial.println("Error creating the queue");
 }

 

 xQueue = xQueueCreate(5, sizeof(Data));

 if(xQueue == NULL){
   Serial.println("Error creating the queue");
 }

 

 //세마포어를 초기화 합니다. 세마포어는 동시에 1개만 생성됩니다.
 sem = xSemaphoreCreateCounting(1, 0);

 


 //Free Rtos Task Set
 xTaskCreate(
     taskOne,          /* Task function. */
     "TaskOne",        /* String with name of task. */
     1024,            /* Stack size in words. 10000->1024*/
     NULL,             /* Parameter passed as input of the task */
     1,                /* Priority of the task. */
     NULL);            /* Task handle. */

 

 xTaskCreate(
     taskTwo,          /* Task function. */
     "TaskTwo",        /* String with name of task. */
     1024,            /* Stack size in words. */
     NULL,             /* Parameter passed as input of the task */
     1,                /* Priority of the task. */
     NULL);            /* Task handle. */

 

 xTaskCreate(
     taskSAM,          /* Task function. */
     "taskSAM",        /* String with name of task. */
     1024,            /* Stack size in words. */
     NULL,             /* Parameter passed as input of the task */
     1,                /* Priority of the task. */
     NULL);            /* Task handle. */

 

}

// The loop function is called in an endless loop
void loop()
{
 delay(1000);

}

 

void taskOne( void * parameter )
{
  /* keep the status of sending data */
 BaseType_t xStatus;
 /* time to block the task until the queue has free space */
 const TickType_t xTicksToWait = pdMS_TO_TICKS(100);

 /* create data to send */
 Data data;

 /* sender 1 has id is 1 */
 data.sender = 1;
 data.counter = 1;

 for(;;){
  for( int i = 0;i<10;i++ ){

   Serial.println("Hello from task 1");
   digitalWrite(LED, 1);
   //digitalWrite(LED, 0);

   xQueueSend(queue, &i, portMAX_DELAY);

      xStatus = xQueueSendToFront( xQueue, &data, xTicksToWait );
      /* check whether sending is ok or not */
      if( xStatus == pdPASS ) {
        /* increase counter of sender 1 */
        data.counter = data.counter + 1;
      }

   delay(1000);
  }
 }
    Serial.println("Ending task 1");
    vTaskDelete( NULL );

}

 

void taskTwo( void * parameter)
{
 /* keep the status of receiving data */
 BaseType_t xStatus;
 /* time to block the task until data is available */
 const TickType_t xTicksToWait = pdMS_TO_TICKS(100);
 Data data;

 int element;

 for(;;){
  for( int i = 0;i<10;i++ ){

   xQueueReceive(queue, &element, portMAX_DELAY);
   Serial.print(element);
   Serial.print(" -> ");

      /* receive data from the queue */
      xStatus = xQueueReceive( xQueue, &data, xTicksToWait );
      /* check whether receiving is ok or not */
      if(xStatus == pdPASS){
        /* print the data to terminal */
        Serial.print("receiveTask got data: ");
        Serial.print("sender = ");
        Serial.print(data.sender);
        Serial.print(" counter = ");
        Serial.println(data.counter);
      }

   Serial.println("Hello from task 2");
   delay(1000);


  }
 }
    Serial.println("Ending task 2");
    vTaskDelete( NULL );

}

void taskSAM( void * parameter)
{
   while (1) {

     //세마포어를 받을때까지 스레드는 계속 기다리게 됩니다.
     xSemaphoreTake(sem, portMAX_DELAY);

     Serial.println(">>> Semaphore Run!");

   }

}

 

 

 

 

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

esp32 ble test  (0) 2018.04.12
esp32 freertos web 올리기  (0) 2018.04.12
esp32 oled 한글 올리기  (0) 2018.04.12
esp32 아두이노 라이브러리 업그레이드  (0) 2018.04.12
esp32 spi OLED 돌리기  (0) 2018.04.09

esp32 oled 한글 올리기

 

Adafruit_GFX 에서 한글 올린 소스가 있다.

 

홈페이지 : http://orasman.tistory.com/341

홈페이지 소스 공개 파일 :

BT_IN_hangel_ssd1360_minimize_DUE.zip
다운로드

 

해당 소스를 그대로 사용 했다.

주의 사항으로는 아두이노 파일에 특성을 utf-8 로 변경 해야 한다.

 

 

 

 

#include "Arduino.h"

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

 

#include "ASCFont.h"
#include "KSFont.h"

 

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

#define OLED_PCLK     18
#define OLED_PDATA    23
#define OLED_PRESET   17
#define OLED_PCMD     16
#define OLED_PCS     5

#define LED 2

 

 

//----- Graphic define
#define NUMFLAKES 10
#define DELTAY 2

byte HANFontImage[32] = {0, };

 

 

//HW SPI
Adafruit_SSD1306 display(OLED_PCMD, OLED_PRESET, OLED_PCS); //DC, RST, CS
String inputString;

//The setup function is called once at startup of the sketch
void setup()
{
 // Add your initialization code here
 pinMode(LED, OUTPUT);

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

 

    //--------------------------------
   //OLED OUTPUT

   display.begin(SSD1306_SWITCHCAPVCC); //SPI


   display.display();  //diplay output
   delay(2000);
   display.clearDisplay(); // Clear the buffer.

 

    inputString="*--동작 시작--*" ;

    char paramChar[inputString.length()+1];
    inputString.toCharArray(paramChar,inputString.length()+1);
    matrixPrint(0,0,paramChar);
    display.display();  //diplay output

}

// The loop function is called in an endless loop
void loop()
{
 delay(1000);


}

//한글 라이브러리 처리
void matrixPrint(int XPOS,int YPOS,char *pChar){
  //byte rg = 3;   //<b1> red, <b0> green
  byte *pFs;
  //byte i, b;
  byte c, c2, c3;

  while(*pChar){
    c = *(byte*)pChar++;

    //---------- �ѱ� ---------
    if(c >= 0x80){
      c2 = *(byte*)pChar++;
      c3 = *(byte*)pChar++;
      //Serial.print(c,DEC);
      //Serial.print(c2,DEC);
      //Serial.print(c3,DEC);
      pFs = getHAN_font(c, c2, c3);
      display.drawBitmap(XPOS, YPOS,  pFs, 16, 16, 1);
      XPOS = XPOS+16;
      if(XPOS > 128){
        XPOS = 0;
        YPOS = YPOS+16;
      }
    }
    //---------- ASCII ---------
    else{
      pFs = (byte*)ASCfontSet + ((byte)c - 0x20) * 16;
      display.drawBitmap(XPOS, YPOS,  pFs, 8, 16, 1);
      XPOS = XPOS+8;
      if(XPOS > 128){
        XPOS = 0;
        YPOS = YPOS+16;
      }
    }
  }
}


/*=============================================================================
한글 font 처리부분  "주의 : 파일 형식을 UTF-8 로 꼭 사용해야 한다.
  =============================================================================*/
uint16_t utf16_d;

byte *getHAN_font(byte HAN1, byte HAN2, byte HAN3)
{

  const byte cho[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 3, 3, 1, 2, 4, 4, 4, 2, 1, 3, 0 };
  const byte cho2[] = { 0, 5, 5, 5, 5, 5, 5, 5, 5, 6, 7, 7, 7, 6, 6, 7, 7, 7, 6, 6, 7, 5 };
  const byte jong[] = { 0, 0, 2, 0, 2, 1, 2, 1, 2, 3, 0, 2, 1, 3, 3, 1, 2, 1, 3, 3, 1, 1 };


  byte first, mid, lastcode;
  byte firstType, midType;
  byte last_Type = 0 ;
  byte i;
  byte *pB, *pF;

  /*------------------------------
    UTF-8 -> UTF-16 change
    UTF-8 1110xxxx 10xxxxxx 10xxxxxx
  */------------------------------

  utf16_d = (uint16_t)((HAN1 & 0x0f) << 12) | (uint16_t)((HAN2 & 0x3f) << 6) | (uint16_t)(HAN3 & 0x3f);

  /*------------------------------
    초,중,종성 코드를 분리해 낸다.

    unicode = {[(초성 * 21) + 중성] * 28}+ 종성 + 0xAC00

          0   1  2  3  4  5  6  7  8  9  10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
    초성 ㄱ   ㄲ ㄴ ㄷ ㄸ ㄹ ㅁ ㅂ ㅃ ㅅ ㅆ ㅇ ㅈ ㅉ ㅊ ㅋ ㅌ ㅍ ㅎ
    중성 ㅏ   ㅐ ㅑ ㅒ ㅓ ㅔ ㅕ ㅖ ㅗ ㅘ ㅙ ㅚ ㅛ ㅜ ㅝ ㅞ ㅟ ㅠ ㅡ ㅢ ㅣ
    종성 없음 ㄱ ㄲ ㄳ ㄴ ㄵ ㄶ ㄷ ㄹ ㄺ ㄻ ㄼ ㄽ ㄾ ㄿ ㅀ ㅁ ㅂ ㅄ ㅅ ㅆ ㅇ ㅈ ㅊ ㅋ ㅌ ㅍ ㅎ
  ------------------------------*/
  utf16_d -= 0xac00;
  lastcode = utf16_d % 28;
  utf16_d /= 28;
  mid = utf16_d % 21;
  first = utf16_d / 21;

  first++;
  mid++;

  /*------------------------------
    초,중,종성 해당 폰트 타입(벌)을 결정한다.
  ------------------------------*/

  /*
   초성 19자:ㄱㄲㄴㄷㄸㄹㅁㅂㅃㅅㅆㅇㅈㅉㅊㅋㅌㅍㅎ
   중성 21자:ㅏㅐㅑㅒㅓㅔㅕㅖㅗㅘㅙㅚㅛㅜㅝㅞㅟㅠㅡㅢㅣ
   종성 27자:ㄱㄲㄳㄴㄵㄶㄷㄹㄺㄻㄼㄽㄾㄿㅀㅁㅂㅄㅆㅇㅈㅊㅋㅌㅍㅎ

   초성
      초성 1벌 : 받침없는 'ㅏㅐㅑㅒㅓㅔㅕㅖㅣ' 와 결합
      초성 2벌 : 받침없는 'ㅗㅛㅡ'
      초성 3벌 : 받침없는 'ㅜㅠ'
      초성 4벌 : 받침없는 'ㅘㅙㅚㅢ'
      초성 5벌 : 받침없는 'ㅝㅞㅟ'
      초성 6벌 : 받침있는 'ㅏㅐㅑㅒㅓㅔㅕㅖㅣ' 와 결합
      초성 7벌 : 받침있는 'ㅗㅛㅜㅠㅡ'
      초성 8벌 : 받침있는 'ㅘㅙㅚㅢㅝㅞㅟ'

   중성
      중성 1벌 : 받침없는 'ㄱㅋ' 와 결합
      중성 2벌 : 받침없는 'ㄱㅋ' 이외의 자음
      중성 3벌 : 받침있는 'ㄱㅋ' 와 결합
      중성 4벌 : 받침있는 'ㄱㅋ' 이외의 자음

   종성
      종성 1벌 : 중성 'ㅏㅑㅘ' 와 결합
      종성 2벌 : 중성 'ㅓㅕㅚㅝㅟㅢㅣ'
      종성 3벌 : 중성 'ㅐㅒㅔㅖㅙㅞ'
      종성 4벌 : 중성 'ㅗㅛㅜㅠㅡ'

  */
  if(!lastcode){  //��ħ ���� ���
    firstType = cho[mid];
    if(first == 1 || first == 24) midType = 0;
    else midType = 1;
  }
  else{       //��ħ �ִ� ���
    firstType = cho2[mid];
    if(first == 1 || first == 24) midType = 2;
    else midType = 3;
    last_Type = jong[mid];
  }
  memset(HANFontImage, 0, 32);

  //�ʼ�
  pB = HANFontImage;
  pF = (byte*)KSFont + (firstType*20 + first)*32;
  i = 32;
  while(i--) *pB++ = pgm_read_byte(pF++);

  //�߼�
  pB = HANFontImage;
  pF = (byte*)KSFont + (8*20 + midType*22 + mid)*32;
  i = 32;
  while(i--) *pB++ |= pgm_read_byte(pF++);

  //����
  if(lastcode){
    pB = HANFontImage;
    pF = ((byte*)KSFont) + ((8*20) + (4*22) + (last_Type*28) + lastcode)*32;
    i = 32;
    while(i--) *pB++ |= pgm_read_byte(pF++);
  }

  return HANFontImage;
}


static byte c1;  // Last character buffer
byte utf8ascii(byte ascii) {
    if ( ascii<128 )   // Standard ASCII-set 0..0x7F handling
    {   c1=0;
        return( ascii );
    }

    // get previous input
    byte last = c1;   // get last char
    c1=ascii;         // remember actual character

    switch (last)     // conversion depnding on first UTF8-character
    {   case 0xC2: return  (ascii);  break;
        case 0xC3: return  (ascii | 0xC0);  break;
        case 0x82: if(ascii==0xAC) return(0x80);       // special case Euro-symbol
    }

    return  (0);                                     // otherwise: return zero, if character has to be ignored
}

String utf8ascii(String s)
{
        String r="";
        char c;
        for (int i=0; i<s.length(); i++)
        {
                c = utf8ascii(s.charAt(i));
                if (c!=0) r+=c;
        }
        return r;
}
void utf8ascii(char* s)
{
        int k=0;
        char c;
        for (int i=0; i<strlen(s); i++)
        {
                c = utf8ascii(s[i]);
                if (c!=0)
                        s[k++]=c;
        }
        s[k]=0;
}

 

 

 

 

20190515 up>

 

font를 변경하고자 다른 곳에서 여러 내용을 검색해 보았다.

 

아래 사이트에서 KSX1001_FontEdit.zip을 다운로드 받았다.  

 

https://lifeiseggs.tistory.com/393 

 

실행해보면 조합형 폰트를 설정해서 C 소스로 출력해 준다.

 

x1 , 폰트명 , 일반폰트 , 조합형한글 -> 작성   소스가 생성 되는데 예제서 사용하는 폰트와 동일하다.

 

다운로드는  : 

KSX1001_FontEdit.zip
다운로드

 

 

 

 

 

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

esp32 freertos web 올리기  (0) 2018.04.12
esp32 free rtos 사용  (0) 2018.04.12
esp32 아두이노 라이브러리 업그레이드  (0) 2018.04.12
esp32 spi OLED 돌리기  (0) 2018.04.09
ttgo Esp32 보드 sloeber 에서 돌리기  (0) 2018.04.09

esp32 초기 설정 이후 git 허브에 들어가 보니 업그레이가 진행 되어있다.

전체 확인을 해서 다시 다운받으려니 너무 답답하다.

 

드래서 git GUI 를 이용해 업그래이드를 진행 했다.

 

해당 관련 내용은 아래 유튜브 내용을 확인 하면 된다.

 

 

기존 다운로드한 파일과 Git 허브 비교후 업데이트  

 

 

다운폴더에서 git.exe 실행

 

 

확인해보니 업데이트 안되어 있네~ 뭘한건지~

 

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

esp32 free rtos 사용  (0) 2018.04.12
esp32 oled 한글 올리기  (0) 2018.04.12
esp32 spi OLED 돌리기  (0) 2018.04.09
ttgo Esp32 보드 sloeber 에서 돌리기  (0) 2018.04.09
esp32 ttgo 보드  (0) 2018.04.06

esp32 spi OLED 돌리기

 

Esp32 Dev 에 SPI OLED 를 연결했다.

 

H/W 연결을 위해 보드 pin map 을 정했다.

 

 

위 pin map 을 아래와 같이 연결 했다.

 

 

참고 : 내부의 정의된 pin map

 

 

static const uint8_t SS    = 5;

static const uint8_t MOSI  = 23;

static const uint8_t MISO  = 19;

static const uint8_t SCK   = 18;

 

 

사용된 SOURCE

 

#include "Arduino.h"

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

 

//PIN define

#define OLED_PCLK     18
#define OLED_PDATA    23
#define OLED_PRESET   17
#define OLED_PCMD     16
#define OLED_PCS     5

#define LED 2

 

//Graphic define
#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 };


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


//HW SPI : (DC, RST, CS)
Adafruit_SSD1306 display(OLED_PCMD, OLED_PRESET, OLED_PCS); 

 

//The setup function is called once at startup of the sketch

void setup()
{
 // Add your initialization code here
 pinMode(LED, OUTPUT);

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

 

 // display.begin(SSD1306_SWITCHCAPVCC, 0x3D); //I2C

 display.begin(SSD1306_SWITCHCAPVCC); //SPI


 display.display();  //diplay output
 delay(2000);
 display.clearDisplay(); // Clear the buffer.

 

 Serial.println("Start..");
}

 

 

// The loop function is called in an endless loop
void loop()
{
 //Add your repeated code here
 digitalWrite(LED, 1);
 delay(1000);
 Serial.println("LED OFF");

 digitalWrite(LED, 0);
 delay(1000);
 Serial.println("LED ON");
}

 

 

 

 

 

 

ttgo esp32 보드를 sloeber 에서 돌렸다.

 

기존에 esp32 sloeber 에서 설정한 내용이 있다. 참고 해야 한다.

 

http://bigwavek.tistory.com/entry/Esp32-%ED%99%98%EA%B2%BD-Sloeber-Eclipse-Arduino-%EC%98%B4%EA%B8%B0%EA%B8%B0?category=742263

 

1. 환경 구축 1

 Arduino > Preferences 에서 라이브러리를 다운받아야 한다.

 

 

 

 

Adafrult GFX Library , Adafrult SSD1306 을 설치 한다.

 

2. 환경구축 2

 Arduino > Add Select the Arduino libraries 에 해당 라이브러리를 사용하도록 선택 한다.

 주의) Project Explorer 창에서 메뉴에 진입 해야 한다.

 

 

 

3. 소스 입력

#include "Arduino.h"

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

//The setup function is called once at startup of the sketch

//Pin map define
//SDA = pin 4, SCL = pin 15, RESET = pin 16

//internal led is on pin 2

#define OLED_RESET 16
#define LED 2

 

//Graphic define
#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 };


Adafruit_SSD1306 display(OLED_RESET);

 

void setup()
{
 // Add your initialization code here
 pinMode(LED, OUTPUT);

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

 

 // initialize with the I2C addr 0x3D (for the 128x64)
 // initialize with the I2C addr 0x3C (for the 128x32)
 display.begin(SSD1306_SWITCHCAPVCC, 0x3C);


 display.display();  //diplay output
 delay(2000);
 display.clearDisplay(); // Clear the buffer.

 //drawPixel
 display.drawPixel(10, 10, WHITE);
 display.display();  //diplay output
 delay(2000);
 //display.clearDisplay(); // Clear the buffer.

 Serial.println("Start..");

}

 

// The loop function is called in an endless loop
void loop()
{
 //Add your repeated code here
 digitalWrite(LED, 1);
 delay(1000);
 Serial.println("LED OFF");

 digitalWrite(LED, 0);
 delay(1000);
 Serial.println("LED ON");
}

 

위와 같이 수정해서 입력 했다.

주의 사항은 OLDE 가 128x32 의 해상도이기 때문에

display.begin(SSD1306_SWITCHCAPVCC, 0x3C) 로 선언해야한다.

 

 

 

4. pins_arduino.h 수정

ttgo 보드가 기본 pin map을 따르지 않기 때문에 pin map 을 수정해야 하는데 이 부분을

기존 아두이노 스케치면 수정하기가 어려웠을것 같다.

 

아래와 같이 수정했다.

 

//TTGO
static const uint8_t SDA = 4;
static const uint8_t SCL = 15;

//orignal
//static const uint8_t SDA = 21;
//static const uint8_t SCL = 22;

 

 

5. 다운로드

sloeber  가 기존 아두이노 스케치와 다른 부분이 스케치에서는 Upload 를 누르면 컴파일과정을 한후

진행이 되는데 sloeber 는 컴파일을 하지 않는다. 꼭 수정후 Verify 과정을 진행해 컴파일을 해야한다.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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

esp32 아두이노 라이브러리 업그레이드  (0) 2018.04.12
esp32 spi OLED 돌리기  (0) 2018.04.09
esp32 ttgo 보드  (0) 2018.04.06
Esp32 환경 Sloeber Eclipse Arduino 옴기기  (0) 2018.04.05
arduino Eclipse 에서 사용하기  (0) 2018.04.05

esp32 ttgo 보드 관련 정보..

 

 

pin map

 

 

 

 

TTGO 제품중 LORA 가 들어간 제품에 대한 github

https://github.com/osresearch/esp32-ttgo

 

 

TTGO 제품중 LORA 가 들어간 제품에 대한  제품정보에 대한 다운로드 link :

https://drive.google.com/file/d/1L8ll-DeAC2SATBZn0-KbSaZsrinbnXkF/view

https://eyun.baidu.com/s/3hsiTNgg

 

 

LORA 참고 소스

 

 ## Hint

Sometimes to program ESP32 via serial you must keep GPIO0 LOW during the programming process

 

For example One

(1)LoRaSender

#include <SPI.h>

#include <LoRa.h>

#include<Arduino.h>

// GPIO5  -- SX1278's SCK

// GPIO19 -- SX1278's MISO

// GPIO27 -- SX1278's MOSI

// GPIO18 -- SX1278's CS

// GPIO14 -- SX1278's RESET

// GPIO26 -- SX1278's IRQ(Interrupt Request)

 

#define SS      18

#define RST     14

#define DI0     26

#define BAND    433E6  

int counter = 0;

 

void setup() {

  pinMode(25,OUTPUT); //Send success, LED will bright 1 second

  

  Serial.begin(115200);

  while (!Serial); //If just the the basic function, must connect to a computer

  

  SPI.begin(5,19,27,18);

  LoRa.setPins(SS,RST,DI0);

//  Serial.println("LoRa Sender");

 

  if (!LoRa.begin(BAND)) {

    Serial.println("Starting LoRa failed!");

    while (1);

  }

  Serial.println("LoRa Initial OK!");

}

 

void loop() {

  Serial.print("Sending packet: ");

  Serial.println(counter);

 

  // send packet

  LoRa.beginPacket();

  LoRa.print("hello ");

  LoRa.print(counter);

  LoRa.endPacket();

 

  counter++;

  digitalWrite(25, HIGH);   // turn the LED on (HIGH is the voltage level)

  delay(1000);                       // wait for a second

  digitalWrite(25, LOW);    // turn the LED off by making the voltage LOW

  delay(1000);                       // wait for a second

  

  delay(3000);

}

 

For example Two

(2)LoRaReceiver

#include <SPI.h>

#include <LoRa.h>

 

 

// GPIO5  -- SX1278's SCK

// GPIO19 -- SX1278's MISO

// GPIO27 -- SX1278's MOSI

// GPIO18 -- SX1278's CS

// GPIO14 -- SX1278's RESET

// GPIO26 -- SX1278's IRQ(Interrupt Request)

 

#define SS      18

#define RST     14

#define DI0     26

#define BAND    433E6

 

void setup() {

  Serial.begin(115200);

  while (!Serial); //if just the the basic function, must connect to a computer

  delay(1000);

  

  Serial.println("LoRa Receiver");

  

  SPI.begin(5,19,27,18);

  LoRa.setPins(SS,RST,DI0);

  

  if (!LoRa.begin(BAND)) {

    Serial.println("Starting LoRa failed!");

    while (1);

  }

}

 

void loop() {

  // try to parse packet

  int packetSize = LoRa.parsePacket();

  if (packetSize) {

// received a packet

    Serial.print("Received packet '");

 

    // read packet

    while (LoRa.available()) {

      Serial.print((char)LoRa.read());

    }

 

    // print RSSI of packet

    Serial.print("' with RSSI ");

    Serial.println(LoRa.packetRssi());

  }

}

 

 

For example three

(3)LoRaReceiverCallback

#include <SPI.h>

#include <LoRa.h>

 

 

 

// GPIO5  -- SX1278's SCK

// GPIO19 -- SX1278's MISO

// GPIO27 -- SX1278's MOSI

// GPIO18 -- SX1278's CS

// GPIO14 -- SX1278's RESET

// GPIO26 -- SX1278's IRQ(Interrupt Request)

 

#define SS      18

#define RST     14

#define DI0     26

#define BAND    433E6

 

void setup() {

  Serial.begin(115200);

  while (!Serial); //if just the the basic function, must connect to a computer

 

  SPI.begin(5,19,27,18);

  LoRa.setPins(SS,RST,DI0);

  

  Serial.println("LoRa Receiver Callback");

 

  if (!LoRa.begin(BAND)) {

    Serial.println("Starting LoRa failed!");

    while (1);

 }

 

  // register the receive callback

  LoRa.onReceive(onReceive);

 

  // put the radio into receive mode

  LoRa.receive();

}

 

void loop() {

  // do nothing

}

 

void onReceive(int packetSize) {

  // received a packet

  Serial.print("Received packet '");

 

  // read packet

  for (int i = 0; i < packetSize; i++) {

    Serial.print((char)LoRa.read());

  }

 

  // print RSSI of packet

  Serial.print("' with RSSI ");

  Serial.println(LoRa.packetRssi());

}

For example four

#include <Wire.h>  // Only needed for Arduino 1.6.5 and earlier

#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"`

#include "images.h"

 

//OLED pins to ESP32 0.96OLEDGPIOs via this connecthin:

//OLED_SDA -- GPIO4

//OLED_SCL -- GPIO15

//OLED_RST -- GPIO16

 

SSD1306  display(0x3c, 4, 15);

 

#define DEMO_DURATION 3000

typedef void (*Demo)(void);

int demoMode = 0;

int counter = 1;

 

void setup() {

  pinMode(16,OUTPUT);

  digitalWrite(16, LOW);    // set GPIO16 low to reset OLED

  delay(50);

  digitalWrite(16, HIGH); // while OLED is running, must set GPIO16 in high

  

  Serial.begin(115200);

  Serial.println();

  Serial.println();

 

 

  // Initialising the UI will init the display too.

  display.init();

 

  display.flipScreenVertically();

  display.setFont(ArialMT_Plain_10);

 

}

 

void drawFontFaceDemo() {

    // Font Demo1

    // create more fonts at http://oleddisplay.squix.ch/

    display.setTextAlignment(TEXT_ALIGN_LEFT);

    display.setFont(ArialMT_Plain_10);

    display.drawString(0, 0, "Hello world");

    display.setFont(ArialMT_Plain_16);

    display.drawString(0, 10, "Hello world");

    display.setFont(ArialMT_Plain_24);

    display.drawString(0, 26, "Hello world");

}

 

void drawTextFlowDemo() {

    display.setFont(ArialMT_Plain_10);

    display.setTextAlignment(TEXT_ALIGN_LEFT);

    display.drawStringMaxWidth(0, 0, 128,

      "Lorem ipsum\n dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore." );

}

 

void drawTextAlignmentDemo() {

    // Text alignment demo

display.setFont(ArialMT_Plain_10);

 

  // The coordinates define the left starting point of the text

  display.setTextAlignment(TEXT_ALIGN_LEFT);

  display.drawString(0, 10, "Left aligned (0,10)");

 

  // The coordinates define the center of the text

  display.setTextAlignment(TEXT_ALIGN_CENTER);

  display.drawString(64, 22, "Center aligned (64,22)");

 

  // The coordinates define the right end of the text

  display.setTextAlignment(TEXT_ALIGN_RIGHT);

  display.drawString(128, 33, "Right aligned (128,33)");

}

 

void drawRectDemo() {

      // Draw a pixel at given position

    for (int i = 0; i < 10; i++) {

      display.setPixel(i, i);

      display.setPixel(10 - i, i);

    }

    display.drawRect(12, 12, 20, 20);

 

    // Fill the rectangle

    display.fillRect(14, 14, 17, 17);

 

    // Draw a line horizontally

    display.drawHorizontalLine(0, 40, 20);

 

    // Draw a line horizontally

    display.drawVerticalLine(40, 0, 20);

}

 

void drawCircleDemo() {

  for (int i=1; i < 8; i++) {

    display.setColor(WHITE);

    display.drawCircle(32, 32, i*3);

    if (i % 2 == 0) {

      display.setColor(BLACK);

    }

    display.fillCircle(96, 32, 32 - i* 3);

  }

}

void drawProgressBarDemo() {

  int progress = (counter / 5) % 100;

  // draw the progress bar

  display.drawProgressBar(0, 32, 120, 10, progress);

 

  // draw the percentage as String

  display.setTextAlignment(TEXT_ALIGN_CENTER);

  display.drawString(64, 15, String(progress) + "%");

}

 

void drawImageDemo() {

    // see http://blog.squix.org/2015/05/esp8266-nodemcu-how-to-create-xbm.html

    // on how to create xbm files

    display.drawXbm(34, 14, WiFi_Logo_width, WiFi_Logo_height, WiFi_Logo_bits);

}

 

Demo demos[] = {drawFontFaceDemo, drawTextFlowDemo, drawTextAlignmentDemo, drawRectDemo, drawCircleDemo, drawProgressBarDemo, drawImageDemo};

int demoLength = (sizeof(demos) / sizeof(Demo));

long timeSinceLastModeSwitch = 0;

 

void loop() {

  // clear the display

  display.clear();

  // draw the current demo method

  demos[demoMode]();

 

  display.setTextAlignment(TEXT_ALIGN_RIGHT);

  display.drawString(10, 128, String(millis()));

  // write the buffer to the display

  display.display();

 

  if (millis() - timeSinceLastModeSwitch > DEMO_DURATION) {

    demoMode = (demoMode + 1)  % demoLength;

    timeSinceLastModeSwitch = millis();

  }

  counter++;

  delay(10);

}

 

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

 

관련 : 아두이노는 아니고 esp32 를 이용한 블루투스 스피커

https://github.com/kodera2t/ESP32_OLED_webradio

 

 

기존 esp8266 소스를 esp32 ttgo 로 변경시 pin map 변경 내용

https://gist.github.com/gabonator/402e09eb1b5afce1e7be228483138071

 

 

 

 

 

 

 

TR FET 안전하게 사용하는 방법에 대한 웹사이트 공유 합니다.

 

https://www.rohm.co.kr/electronics-basics/transistors/tr_what6

 

 

https://www.rohm.co.kr/electronics-basics/transistors/tr_what5

 

 

 

캡쳐한 PDF 파일 입니다.

 

 

MOSFET의 특성 _ 전자 기초 지식 _ 로옴 주식회사 - ROHM Semiconductor - korea - Rohm.com.pdf

 

 

안전하게 사용하기 위한 선정 방법 _ 전자 기초 지식 _ 로옴 주식회사 - ROHM Semiconductor - korea - Rohm.com.pdf

 

 

'공부 > 전자회로_부품' 카테고리의 다른 글

SSR 관련 참고 문서  (0) 2018.03.05
광전송으로 구현한 OPAMP  (0) 2015.04.03
Metrix LED 드라이버 IC  (0) 2015.04.03
AC 용 isolated ADC  (0) 2015.03.26
Magnetic Buzzer  (0) 2015.03.26

+ Recent posts