RaspberryPi/RP2040

RP2040 SSM EVM - W5500 DCHP 테스트

nexp 2021. 2. 3. 04:36

Raspvery Pi Pico(RP2040) 을 이용하여 이더넷 테스트를 하기위한 테스트를 좀더 진행해 보자.우선 W5500 을 이용하여 DHCP로 IP를 할당 받고 SSD1306 OLED에 IP정보를 표시 하는 예제를 작성해 보자.

 

 

W5500 에서 DHCP로 할당받기 위해서는 초기화시 mac만 설정 해 주면 된다.

void setup()
{
    pinMode(25, OUTPUT);

    Serial.begin(115200);
    while (!Serial)
    {
        ; // wait for serial port to connect. Needed for Leonardo only
    }
    Serial.println("W5500 DHCP Test");

    // start the Ethernet connection and the server:
    Ethernet.w5500_cspin =  W5500_CS_PIN;
    
    // Ethernet.begin(mac, ip);
    Ethernet.begin(mac);

    Serial.print("My IP address: ");
    Serial.println(Ethernet.localIP());
}

 

코드 수정해여 실행하면 시리얼 포트로 아래와 같이 W5500에서 DHPC로 할당 받은 IP를 확인 할 수 있다.

W5500 DHCP Test
My IP address: 192.168.1.145

 

 

 

이제 SSD1306 OLED에 DHCP로 할당 받은 IP를 표시 하는 코드를 작성하면 된다.

#include <Arduino.h>
#include <SPI.h>
#include <Ethernet2.h>

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

#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)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

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

#define W5500_CS_PIN          17
#define Led1On() digitalWrite(25, 1)
#define Led1Off() digitalWrite(25, 0)

byte mac[] = {
    0x00, 0x08, 0xDC, 0x00, 0x00, 0x00};

// IPAddress ip(192, 168, 1, 177);


void DisplayIp(arduino::IPAddress ip)
{
    #define YELLOW 0xFFE0
    char cnt = 0;
    void loop() {
    char buf[32];

    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(ip);
	display.display();
}


void setup()
{
    pinMode(25, OUTPUT);

    Serial.begin(115200);
    while (!Serial)
    {
        ; // wait for serial port to connect. Needed for Leonardo only
    }
    Serial.println("W5500 DHCP Test");

    // start the Ethernet connection and the server:
    Ethernet.w5500_cspin = W5500_CS_PIN;
    
    // Ethernet.begin(mac, ip);
    Ethernet.begin(mac);

    Serial.print("My IP address: ");
    Serial.println(Ethernet.localIP());
    
    DisplayIp(Ethernet.localIP());
}

void loop()
{
    Led1On();
    delay(1000);

    Led1Off();
    delay(1000);
}

 

 

 

 

 

반응형