About Me Banner
BUY AMERICAN! ESP8266 NodeMCU

 

Interesting ESP8266 NodeMCU Videos

 

 

NodeMCU is an open source IoT platform. It includes firmware which runs on the ESP8266 Wi-Fi SoC from Espressif Systems, and hardware which is based on the ESP-12 module. The term "NodeMCU" by default refers to the firmware rather than the development kits. The firmware can be programmed using the Arduino IDE.

 

ESP8266 NodeMCU

 

There are a number of variations on the NodeMCU type. In my case I use the ESP8266 NodeMCU 0.9 DevKit as shown above. I bought these a few years ago and since then, newer versions have come out. BUt it still remains a great little development tool for creating IoT applications. For my application, I created code that will switch my Kenwood TM-D700 Dual band radio between normal TNC mode and CrossBand mode so I can use my HT to talk with my friends. The following will walk you through the programming I had to do to set up my application.

 

There are a number of steps you must take to set up the NodeMCU before you can just use the Arduino IDE and upload your application. I will briefly run through the steps here but you can also find them at this Instructables webpage.

 

Make sure you are using the lastest Arduino IDE release. Open the IDE.

 

To set up the ESP8266 NodeMCU in the IDE, you must include the library. To get there, we must first set the Preferences. Open File and click on the Preferences as shown in the figure to the right.

Click image to enlarge

We need to add the ESP8266 Board Manager. In the Additional Boards Manager enter below URL.

http://arduino.esp8266.com/stable/package_esp8266com_index.json

 

As highlighted in the figure and enter OK.

Click image to enlarge

Now open the tools. Select Board: “Arduino/Genuino Uno” and click on the Boards Manager as shown in the figure to the right.

Click image to enlarge

The Boards Manager window opens. You can either scroll the window page down till you see the module with the name ESP8266. Or you can enter ESP8266 in the filter window to show you the option as shown in the images to the right.

 

Click images to enlarge

Once we get it, select the module by clicking it, select version as shown by the arrow, then click on the Install button. When it is installed it shows installed in the module. You can then close the window.

Click image to enlarge

To run the ESP8266 NodeMCU with the vArduino IDE,we have to select the board. Open the tools. Select Board: “Arduino/Genuino Uno”. To the right will be a list of boards to choose from. You may need to scroll down by using the down arrow in the window to find the board you need. In my case I selected the NodeMCU 0.9 (ESP-12 Module). You may have to select a different ESP8266 module depending on what you have .

Click image to enlarge

You can plug in your ESP8266 module at this point into the USB port on your computer. You'll likley have to go into your device manager to determine which Com port the module was installed in, as shown in the image to the right.

Click image to enlarge

In the Arduino IDE, select Tools. You should now see your board listed along with a number of parameters. Make sure that you set the Com port the port you saw in device manager. Once you set the port, you might want to click on Get Board Info just to make sure the IDE is communicating with the ESP8266 board.

 

If everything installed properly, you're now ready to start creating your IoT script!

 

I encourage you to review some of the example programs to get a feel for how you program the ESP8266 board. You might want to watch some of the videos at the top of the page as well to help get started.

Click image to enlarge

 

For my project, I wanted to create an IoT script to control my Kenwood TM-D700 Dual Band radio so I can switch between Crossband repeater mode and a TNC mode the works with my APRS system. The script I wrote is below. The script is well commented and should be easy to follow. I used code that came from a number of the examples provided. The end result is a web served page that looks like the following:

 

 

Here is my script. Note that you will have to enter in your own 'ssid', 'password', and IP address, submask, and gateway if you choose to do so.

 

/*
* Kenwood TM-D700 Web Control Sketch
* Experimental code to control the TMD700 using the ESP8266 and the NodeMCU DevKit 0.9
* Uses Pins 13 and 15 for Rx & Tx , respectively
*/

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <SoftwareSerial.h>

const char* ssid = "your wifi network";
const char* password = "your password";

SoftwareSerial mySerial(13, 15);                // RX, TX

// Update these with values suitable for your network.
IPAddress ip(192,168,xxx,xxx);  //Node static IP
IPAddress gateway(192,168,xxx,xxx);
IPAddress subnet(255,255,255,0);

ESP8266WebServer server(8001);          // Create a webserver object that listens for HTTP request on port 80

const int led = 2;

void setup(void){
    Serial.begin(115200);                // Start the Serial communication to send messages to the computer
    delay(10);
    Serial.println('\n');

    Serial.println("Connecting SoftwareSerial Port");

    // set the data rate for the SoftwareSerial port
    mySerial.begin(19200);
    while (!mySerial) {
    ;                                         // wait for serial port to connect.
    }
    Serial.println("SoftwareSerial Port connected");

    pinMode(led, OUTPUT);                       // Using the blue LED to indicate Crossband mode on

    WiFi.begin(ssid, password);
    WiFi.config(ip, gateway, subnet);

    Serial.println("Connecting ...");
    int i = 0;
    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }
    Serial.println('\n');
    Serial.print("Connected to ");
    Serial.println(WiFi.SSID());              // Tell us what network we're connected to
    Serial.print("IP address:\t");
    Serial.println(WiFi.localIP());           // Send the IP address of the ESP8266 to the computer


    // Call the 'handleRoot' function when a client requests URI "/"
    server.on("/", HTTP_GET, handleRoot);

    // Call the 'handleCrossband' function when a POST request is made to setup Crossband mode    
    server.on("/Crossband", HTTP_POST, handleCrossband);

    // Call the 'handleTNC function when a Post request is made to setup TNC mode
    server.on("/TNC", HTTP_POST, handleTNC);       

    // When a client requests an unknown URI (i.e. something other than "/"), call function "handleNotFound"
    server.onNotFound(handleNotFound);       

    server.begin();                           // Actually start the server
    Serial.println("HTTP server started");
}


void loop(void){
    server.handleClient();                    // Listen for HTTP requests from clients
}


void handleRoot() {                         // When URI / is requested, send a web page with buttons to change mode
    server.send(200, "text/html",

                   "<h2>Kenwood TM-D700 Control Center</h2>Powered by NodeMCU Devkit 0.9 ESP8266"
                   "<form action='/Crossband' method='POST'><p><input type='hidden' name='mode' value='1'>"
                   "<input type='submit' value='Crossband Mode'/></form>"
                   "<form action='/TNC' method='POST'><p><input type='hidden' name='mode' value='2'>"
                   "<input type='submit' value='TNC Mode'/></form>");
}


void handleCrossband() {                    // If a POST request is made to URI /Crossband
    digitalWrite(led,0);                      // Change the state of the LED

    // Send commands to TMD-700
    mySerial.write("\r\nTNC 0\r\n"); Serial.println("TNC 0");
    mySerial.write("\r\nBC 1,1\r\n"); Serial.println("BC 1,1");
    mySerial.write("\r\nMC 1,014\r\n"); Serial.println("MC 1,014");                    
    mySerial.write("\r\nREP 2\r\n"); Serial.println("REP 2");

    // Add a header to respond with a new location for the browser to go to the home page again
    server.sendHeader("Location","/");

    // Send it back to the browser with an HTTP status 303 (See Other) to redirect      
    server.send(303);                        
    Serial.println("Now in Crossband mode.....");
}


void handleTNC() {                          // If a POST request is made to URI /TNC
    digitalWrite(led,1);                      // Change the state of the LED

    // Send commands to TMD-700
    mySerial.write("\r\nREP 0\r\n"); Serial.println("REP 0 0");
    mySerial.write("\r\nMC 1,013\r\n");  Serial.println("MC 1,013");                    
    mySerial.write("\r\nBC 0,0\r\n"); Serial.println("BC 0,0");
    mySerial.write("\r\nTNC 1\r\n"); Serial.println("TNC 1");

    // Add a header to respond with a new location for the browser to go to the home page again
    server.sendHeader("Location","/");

    // Send it back to the browser with an HTTP status 303 (See Other) to redirect      
    server.send(303);                        
    Serial.println("Now in TNC mode.....");
}

void handleNotFound(){
    // Send HTTP status 404 (Not Found) when there's no handler for the URI in the request
    server.send(404, "text/plain", "404: Not found");
}

 

Back to top of page


© 2018, Jonathan Tucker N8MDP. All Rights Reserved. Powered by cPanel.