---
title: "Rewrite the MAC address of W5500 from the terminal"
url: "https://maker.wiznet.io/teju/projects/rewrite-the-mac-address-of-w5500-from-the-terminal/"
markdown_url: "https://maker.wiznet.io/teju/projects/rewrite-the-mac-address-of-w5500-from-the-terminal/md"
type: "UCC: User Created Content"
author: "T-Oda-BTO"
author_url: "https://qiita.com/T-Oda-BTO/items/4354e26e6b78b4a76696"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "T-Oda-BTO"
original_url: "https://qiita.com/T-Oda-BTO/items/4354e26e6b78b4a76696"
published: "2022-12-05"
language: "en"
hardware: ["WIZnet W5100 ethernet shield"]
likes: 2
views: 560
comments: 1
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# Rewrite the MAC address of W5500 from the terminal

> There is an Ethernet controller IC from WIZnet called W5500. It is also used in the official Arduino Ethernet shield, making it a very conve

Original author: T-Oda-BTO (source: https://qiita.com/T-Oda-BTO/items/4354e26e6b78b4a76696)

## Components

- **WIZnet W5100 ethernet shield** x 1 ([docs](https://www.wiznet.hk/en/open-source-hardware/102-w5100s-ethernetshield.html?search_query=W5100+ethernet+shield&results=84))
- Software: **Arduino IDE** ([docs](https://www.arduino.cc/en/software))

## Article

## **Introduction**

There is an Ethernet controller IC from WIZnet called W5500.
It is also used in the official Arduino Ethernet shield, making it a
very convenient chip for prototyping with a browser.

I have to pass the MAC address, IP address, subnet, etc. from the microcomputer to the W5500, but since the
sample code assumes direct input of the source, it is quite difficult to get out of the realm of prototyping.

Therefore, I wrote a code that stores the MAC address, IP, etc. in the EEPROM inside the Arduino and can be rewritten from a terminal such as TeraTerm, so I
will share it. Please for your reference.

## **Code (excerpt)**

Environment: Arduino Leonardo, Ethernet Shield 2

```plaintext
#include <SPI.h>
#include <Ethernet2.h>//Ver.1.0.4
#include <EEPROM.h>

byte mac[] = {EEPROM[0x00], EEPROM[0x01], EEPROM[0x02], EEPROM[0x03], EEPROM[0x04], EEPROM[0x05]};
byte ip[] = {EEPROM[0x06], EEPROM[0x07], EEPROM[0x08], EEPROM[0x09]};

IPAddress subnet{EEPROM[0x0A], EEPROM[0x0B], EEPROM[0x0C], EEPROM[0x0D]};
IPAddress gateway{EEPROM[0x0E], EEPROM[0x0F], EEPROM[0x10], EEPROM[0x11]};
IPAddress dnsServer{EEPROM[0x12], EEPROM[0x13], EEPROM[0x14], EEPROM[0x15]};

// ***********割愛***********

void loop()
{

// ***********割愛***********
  Serial_setting();//何か入力があればSettingモードへ
}
void Serial_setting() {
  if (Serial.read() != -1) {
    String scan_string;
    scan_string = Serial.read();
    scan_string = "";
    Serial.println();
    Serial.println(F("Setting Mode"));
    Serial.println(F("TIME OUT 20s_EOL:LF"));
    
    Serial.println();
    Serial.println(F("Num?"));
    Serial.println(F("1:MAC"));
    Serial.println(F("2:IP"));
    Serial.println(F("3:subnet"));
    Serial.println(F("4:gateway"));
    Serial.println(F("5:dnsServer"));
    Serial.println(F("X:Exit"));

    while (!Serial.available()); //入力があるまで待機
    scan_string = Serial.readStringUntil('\n');
    scan_string.trim();
    Serial.print(F(">>"));
    Serial.println(scan_string);

    //***選択肢1***MACアドレス書き換えモードへ(6バイトの配列)*/
    if (scan_string.equals("1")) {
      Serial.println(F("NEW_MAC_address?"));
      Serial.println(F(">>"));
      while (!Serial.available()); //入力があるまで待機
      scan_string = Serial.readStringUntil('\n');//入力内容の表示
      scan_string.trim();
      Serial.print(F(">>"));
      Serial.println(scan_string);

      if (scan_string.length() == 12) { //文字数がOKか
        Serial.println(F("update!"));

        //12文字のHEXを表している文字列を2文字ずつ結合しEEPROMへ格納
        String i_string;
        char char_buf[5];
        i_string = "0x";
        i_string += scan_string[0];
        i_string += scan_string[1];
        i_string.toCharArray(char_buf, 5);
        EEPROM[0x00] = strtol(char_buf, NULL, 16);

        i_string = "0x";
        i_string += scan_string[2];
        i_string += scan_string[3];
        i_string.toCharArray(char_buf, 5);
        EEPROM[0x01] = strtol(char_buf, NULL, 16);

        i_string = "0x";
        i_string += scan_string[4];
        i_string += scan_string[5];
        i_string.toCharArray(char_buf, 5);
        EEPROM[0x02] = strtol(char_buf, NULL, 16);

        i_string = "0x";
        i_string += scan_string[6];
        i_string += scan_string[7];
        i_string.toCharArray(char_buf, 5);
        EEPROM[0x03] = strtol(char_buf, NULL, 16);

        i_string = "0x";
        i_string += scan_string[8];
        i_string += scan_string[9];
        i_string.toCharArray(char_buf, 5);
        EEPROM[0x04] = strtol(char_buf, NULL, 16);

        i_string = "0x";
        i_string += scan_string[10];
        i_string += scan_string[11];
        i_string.toCharArray(char_buf, 5);
        EEPROM[0x05] = strtol(char_buf, NULL, 16);

        //EEPROMからMAC_addressを読む
        for (int i = 0; i < 6; i++) {
          if (EEPROM[i] <= 16 )Serial.print("0"); //16以下(1桁)であれば0埋め
          Serial.print(EEPROM.read(i), HEX);
          if (i < 5)Serial.print(":");//区切り文字表示
        }
        Serial.println();

      } else {                         //文字数が合わなければエラー
        Serial.println(F("length_Error!"));
      }



// ***********割愛***********

    } else {//***選択肢以外***抜ける
      Serial.println(F("Setting Mode Exit"));
    }
    Serial.println(F("Please reboot for the settings to take effect"));
    Serial.println(F("bye.Resume after 5 seconds"));
    Serial.println();
    delay(5000);

  }
}
```

## **How it works**

Please pay attention to the line feed code setting on the terminal side
[![image.png](https://qiita-user-contents.imgix.net/https%3A%2F%2Fqiita-image-store.s3.ap-northeast-1.amazonaws.com%2F0%2F2605138%2F5310d79b-cdc8-98d4-d96b-0e91fc067dbc.png?ixlib=rb-4.0.0&auto=format&gif-q=60&q=75&s=ba3d02361f22ded47674173d795806cb)](https://camo.qiitausercontent.com/01839b377ec6d5e66ccd552816a7b15a4ad4e595/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f323630353133382f35333130643739622d636463382d393864342d643936622d3065393166633036376462632e706e67)
[![image.png](https://qiita-user-contents.imgix.net/https%3A%2F%2Fqiita-image-store.s3.ap-northeast-1.amazonaws.com%2F0%2F2605138%2F1407ae5c-1506-bf0b-b120-aa94e3c59716.png?ixlib=rb-4.0.0&auto=format&gif-q=60&q=75&s=9f7046d9ce995ec00f4a90867c99b073)](https://camo.qiitausercontent.com/7339e45696948c82ef968e5d2b198564b71081d5/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f323630353133382f31343037616535632d313530362d626630622d623132302d6161393465336335393731362e706e67)

## **in conclusion**

This source code was written for the browser switch DIO of our product.
Due to open source hardware, the code omitted above is also published on github.
<https://github.com/bit-trade-one/ADBSDIO_BrowserSwitchDIO>

---

Source: https://maker.wiznet.io/teju/projects/rewrite-the-mac-address-of-w5500-from-the-terminal/
