ESPRESSIF/ESP32-C6

[ESP32-C6 SSM] WiFi 테스트 - SSD1306 OLED 에 IP출력하기

nexp 2024. 10. 5. 16:51

ESP32-C6를 이용하여 간단히 WiFi 를 테스트 해보자.

가장 간단히 테스트 할 수 있는것이 무엇일까 고민하다 기존에 테스트 했던 코드 중에 WiFi AP에 접속하여 IP를 받아오고 할당 받은 IP를 OLED에 출력 하는 예제를 테스트 해 보았다.

 

 

기존의 코드를 이용해서 컴퍼일하고 다운로드 하니 정상동작 하지 않는다.

간단히 기존 코드로 쉽게 테스트 해 보려고 했는데... Arduino IDE에서 몇번 수정하고 다운로드 하는데 시간이 너무 오래 걸린다.

 

Arduino코드를 동일하게 사용고 컴파일 속도도 빠른 PIO(PlatformIO) 환경에서 테스트 해볼까?

하지만 아직 PIO에서 공식적으로 지원하지 않는다. 그래서 먼저 PIO에서 ESP32C6를 테스트 할 수 있는 환경을 구축했다.

 

기존 테스트 했던 코드에서  SSD1306제어를 위한 I2C 핀맵을 [ESP32-C6 SSM] 보드에 맞게 수정해 주어야 한다. 

  Wire.end();
  Wire.setPins(19,20);
  Wire.begin();

 

 

그리고 platformio.ini 파일에서 라이브러리를 추가 해주어야 한다.

lib_deps =
  Adafruit BusIO
  Adafruit GFX Library
  Adafruit SSD1306

 

 

 

간단하게 ESP32C6에서 WiFi 동작 여부를 테스트 해보려고 했는데 간단하지 않게 되어 버렸지만 보드가 새로 나올때 마다 여러가지 테스트 하고 새로운 환경에 적응하는 측면에서는 좋은 경험 있었던 것 같다.

 

EP32C6에서 WiFi AP에 접속하고 IP를 할당받아 OLED에 출력하는 테스트 예제

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

#define LED1_PIN       14 
#define LED2_PIN       15 

#define Led1On()       digitalWrite(LED1_PIN, 0) 
#define Led1Off()      digitalWrite(LED1_PIN, 1) 

#define Led2On()       digitalWrite(LED2_PIN, 0) 
#define Led2Off()      digitalWrite(LED2_PIN, 1) 


#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)


#define NUMFLAKES     10 // Number of snowflakes in the animation example

#include <WiFi.h>

const char *ssid = "ssid";
const char *password = "****";
WiFiServer server(80);

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

void setup() {

  Wire.end();
  Wire.setPins(19,20);
  Wire.begin();
 
  Serial.begin(115200);

  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { 
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }


  // Show initial display buffer contents on the screen --
  // the library initializes this with an Adafruit splash screen.
  display.display();
  delay(2000); // Pause for 2 seconds

  // Clear the buffer
  display.clearDisplay();

  // Draw a single pixel in white
  display.drawPixel(10, 10, WHITE);

  // Print local IP address and start web server
  Serial.println("");
  Serial.println("WiFi connected.");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

#define YELLOW 0xFFE0
char cnt = 0;
void loop()
{
    display.clearDisplay();
    display.setTextSize(1);
    display.setTextColor(WHITE);
    display.setCursor(0,0);
    display.println("nexp.tistopry.com");
    display.println(" ");
    display.setTextColor(INVERSE);
    display.setTextSize(2);
    display.println("SSD1306");
    display.println(" ");
    display.println(WiFi.localIP());

    display.display();
    delay(250);
}

 

 

 

 

반응형