How to Get the MAC Address of an ESP-01
Materials Needed
- ESP-01 Module (Affiliate) – Buy on AliExpress
- USB ESP-01 Programming Adapter with a CH340G chip (Affiliate) – Buy on AliExpress
- Computer with Arduino IDE installed
Step 1: Setting Up the Arduino IDE for ESP8266
- Open Arduino IDE, go to File -> Preferences.
- In the Additional Boards Manager URLs field, enter: http://arduino.esp8266.com/stable/package_esp8266com_index.json and click OK.
- Go to Tools -> Board -> Boards Manager, search for ESP8266 and install it.
Selecting the correct ESP8266 board:
- Go to
Tools
>Board
. - Find and select your specific board that is the Generic Esp8266
Step 2: Setting Up the Hardware
To put the CH340G adapter in programming mode, follow these steps:
- Before plugging the USB ESP-01 programming adapter into a USB port on your computer, Press and hold the push button switch.
- Plug the USB ESP-01 programming adapter into a USB port on your computer with the button pressed.
- Release the button: After a few seconds, release the push button switch. The Esp-01 should be in programming mode, and you can upload code to the ESP-01 module using your preferred development environment.
If having trouble, go to my previous blog post. It explains with images: https://www.edgemicrotech.com/preparing-the-usb-esp-01-programming-adapter-a-step-by-step-guide/
Step 3: Code -> Version 1
This code will make the Mac address appear on the serial monitor only once.
- The code inside the IF statement will run only once because the boolean variable STOP is switched to false. The void loop function will continue to run but won’t do anything else.
#include <ESP8266WiFi.h> boolean stop= true; void setup() { } void loop() { delay(1000); if (stop == true) { Serial.begin(115200); delay(1000); Serial.println(); Serial.print("MAC address: "); Serial.println(WiFi.macAddress()); } stop = false; }
Step 3: Code -> Version 2 (Beginners should use this version)
This code will make the mac address appear on the serial monitor every approx. 2 seconds.
#include <ESP8266WiFi.h> void setup() { } void loop() { delay(1000); Serial.begin(115200); delay(1000); Serial.println(); Serial.print("MAC address: "); Serial.println(WiFi.macAddress()); }
Step 4: Uploading the Code and Getting the MAC Address
After the programming of the board is successful, remove the adapter from the USB port and insert it again (without pressing the button). Pay attention to the serial monitor; the Mac address should appear.
Troubleshooting
- No MAC address is printed to the serial monitor: Make sure the baud rate of the serial monitor matches the baud rate specified in the Serial.begin() function in your code (115200 in the example code). Try using the Version 2 of the code.
- The code fails to upload to the ESP-01: Make sure the correct board (Generic ESP8266 Module) and PORT are selected in the Tools menu. If you are using the adapter, follow the steps of the previous blog post to put it in programming mode: https://www.edgemicrotech.com/preparing-the-usb-esp-01-programming-adapter-a-step-by-step-guide/
Conclusion