Introduction: STM32F103: Esp8266 NodeMCU Getting Started [using Mbed.h]
In this tutorial, I will show you how to make internet connection, Send a GET request and receive responce using esp8266 (v1) NodeMCU and mbed.h.
This tutorial is divided into following parts:
- Making Hardware Connections.
- Writting Code
- Visualizing the output
If you haven't yet flashed NodeMCU onto your esp8266, please first flash it as shownHERE.
Step 1: Making Hardware Connections
Connect esp8266 to your Nucleo Board as Stated below:
- esp8266 Vcc ------>Nucleo +3.3V
- esp8266 CH_PD -> Nucleo +3.3V
- esp8266 GND ----> Nucleo GND
- esp8266 Tx -------> Nucleo D2
- esp8266 Rx -------> Nucleo D8
- esp8266 RESET -> Nucleo D3
- I am Using esp8266 v1. For other version you may need to connect some other pins to Vcc/GND.
- DON'T Connect to +5V
- As you have to connect two pins to single +3.3V output, make sure that both pins are connected!
Step 2: Writting Code
I have written some code on mbed compiler. You can get it directly from there and make changes as you like.
To get code, Click HERE. Now, Click on Import this Program (blue button) to import this to your compiler.
What our code will do is that it will send a GET request to Adafruit's testWifi page and will display the response. Using same procedure we can send GET and POST request to any website/API and read the response. In other words, we can easily send our sensor values to any remote server or API.
Now, Compile and Download/Copy the .bin file onto your Nucleo Board.
Step 3: Visualizing the Output
In order to visualize the output, you will need to install the a Software that can read from Serial Port. We will be using Putty, most widely used software. I have attached the .exe file. You can download it from here, or you can from elsewhere.
- Run putty.exe.
- Select Serial.
- Enter the COMport onto which your Nucleo is attached.
- Set Baud Rate to 115200.
- Click OPEN or press Enter.
Now, you should be able to see the connection status on your putty screen. When you will be successful, you will see a output like shown in image attached.
- Hardware intialization failed? Please make sure that you have made connection as stated before.
- Hardware intialization failed? Have you have flashed NodeMCU on esp8266? Please Note that by default it runs on AT Command firmware.
- Hardware intialization failed? What is BaudRate of your NodeMCU? Default BaudRate is 9600. If you haven't changed it explicitly then it must be 9600. Try Changing the BaudRate in Code (where we created object of esp8266)
- Not Connecting to your Network? Please Make sure that you have entered your SSID name and password correclt.
5 years ago
Thank you for the nice work, I keep getting "connection fail!..." on my putty.
I suspect that it is coming from this block of code:
_ip[ip_len] = 0;
if (strcmp(_ip, "nil") != 0)
if (timer.read_ms() > _timeout)
I couldnt not debug this par because I dont know why did you set a timer? or what could be the bug.
I kindly seek your help. Thank you
Reply 5 years ago
By the way, I have already completed the Flashing tutorial successfully and was able to connect to the API server.
6 years ago
Please I need you help,I have entered my ssid and password correctly
but the connection was failed:(
What should I do?
Please help me
6 years ago
Please I need your help,
I have entered my SSID name and password correctly but the connection is failed :(
How can I solve this problem,please help me.