STM32F103: Esp8266 NodeMCU Getting Started [using Mbed.h]

10K136

Intro: 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:

  1. Making Hardware Connections.
  2. Writting Code
  3. Visualizing the output
Note:

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:

  1. esp8266 Vcc ------>Nucleo +3.3V
  2. esp8266 CH_PD -> Nucleo +3.3V
  3. esp8266 GND ----> Nucleo GND
  4. esp8266 Tx -------> Nucleo D2
  5. esp8266 Rx -------> Nucleo D8
  6. esp8266 RESET -> Nucleo D3
Note:
  1. I am Using esp8266 v1. For other version you may need to connect some other pins to Vcc/GND.
  2. DON'T Connect to +5V
  3. 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.

  1. Run putty.exe.
  2. Select Serial.
  3. Enter the COMport onto which your Nucleo is attached.
  4. Set Baud Rate to 115200.
  5. 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.

NOTE:

  1. Hardware intialization failed? Please make sure that you have made connection as stated before.
  2. Hardware intialization failed? Have you have flashed NodeMCU on esp8266? Please Note that by default it runs on AT Command firmware.
  3. 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)
  4. Not Connecting to your Network? Please Make sure that you have entered your SSID name and password correclt.

*

4 Comments

Salam Abdulrahman,

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)

return true;

if (timer.read_ms() > _timeout)

return false;

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

By the way, I have already completed the Flashing tutorial successfully and was able to connect to the API server.

Hi,

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

but

Hi,

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.

Tank you