Installation procedure for adding ESP8266 board in arduino IDE is very simple with latest versions of Arduino IDE.
Follow these steps Step 1: Open Arduino IDE Go to File >> Preferences Add additional board manager URLs: http://arduino.esp8266.com/stable/package_esp8266com_index.json Figure 1.2: Preferences Step 2: Open Board Manager Go to Tools >> Board >> Board Manager Figure 1.3: Board Manager Step 3: Install ESP8266 Board Search for ESP8266 and then click install button. Note: If Step 1 URL is not added then it will not find ESP8266 board. Figure 1.4: Install ESP8266 Step 4: After clicking install. Installation progress is shown in bottom. Once it is installed open Tools>>Boards and look for ESP8266.
1.2.2 Checking Installation is working
To check installation is working or not.
Test LED blink program. Step 1: Select ESP8266 Generic Board or NodeMCU 1.0 Generic ESP8266 Module, Works for all boards so I prefer this board. Figure 1.5: Board Selection Step 2: Open LED Blink Example of ESP8266 Figure 1.6: Open Blink Example Step 3: Modify or Write New Program to make GPIO2 LED blinking. NodeMCU is having two on board LEDs as shown in Figure 1.1. We use LED connected to GPIO2 for this example #define LED 2 void setup () { pinMode ( LED , OUTPUT ) ; //Define pin as output } void loop () { //LED off. LED is connected in reverse digitalWrite ( LED , HIGH ) ; delay ( ) ; digitalWrite ( LED , LOW ) ; //LED on delay ( ) ; } Step 4: Uploading Program to NodeMCU Select your boards com port.
Make sure that you have installed drivers for your board. NodeMCU uses CP2102 as USB to Serial converter. Install drivers for CP2102 if not installed. Figure 1.7: Communication Port Selection When you click on upload button press and hold FLASH button of NodeMCU which is present near USB connection, Once upload is started ( blue led blinks at faster rate ) you can release it. Pressing of FLASH button is not required if selected board is NodeMCU 1.0. Step 5: Once uploading is successful, check LED is blinking.
Now your setup is ready to go for further. 2. Serial Communication The first and basic most communication that is required for most of the devices and program debugging is serial communication. Its simple but important to know. Serial communication is used to make ESP communicate with PC and serial communication devices. ESP8266 RX TX line uses 3.3V logic.
All IO lines and supply voltage for ESP8266 is 3.3V. Do not connect any IO line with 5V logic
2.1 Serial Communication
ESP8266 Serial works the same way as on a regular Arduino. Apart from hardware FIFO (128 bytes for TX and RX) Serial has additional 256-byte TX and RX buffers. Both transmit and receive is interrupt-driven. Write and read functions only block the sketch execution when the respective FIFO/buffers are full. Serial uses UART0, which is mapped to pins GPIO1 (TX) and GPIO3 (RX).
Example 1: Serial Data Transmission Program to send Hello World message to serial void setup () { Serial . begin ( 115200 ) ; } void loop () { Serial . println ( " Hello World " ) ; delay ( ) ; } Upload above program and open serial monitor to see transmitted data. Figure 2.1: Serial output Serial may be remapped to GPIO15 (TX) and GPIO13 (RX) by calling Serial.swap() after Serial.begin . Calling swap again maps UART0 back to GPIO1 and GPIO3. Example 2: Remapping Serial to use GPIO15 (TX) and GPIO13 (RX) Remapping serial can be used to make interface of two serial devices.
But only one serial device is get connected to ESP8266 at a time. This is useful for interfacing RF ID reader, GPS, GSM device. void setup () { Serial . begin ( 115200 ) ; Serial . swap () ; //Remap RX TX to GPIO13(Rx) and GPIO15(Tx) } void loop () { Serial . println ( " Hello World " ) ; delay ( ) ; } Serial1 uses UART1, TX pin is GPIO2.
UART1 cannot be used to receive data because normally its RX pin is occupied for flash chip connection. To use Serial1, call Serial1.begin(baudrate) . Example 3: Using Serial-1 (Only TX) After uploading program you will see blue led flashes due to data is getting sent on GPIO2(TX). void setup () { Serial1 . begin ( 115200 ) ; } void loop () { Serial1 . void setup () { Serial . begin ( 115200 ) ; Serial . set_tx ( ) ; //Remap TX pin to GPIO2 } void loop () { Serial . println ( " Hello World " ) ; delay ( ) ; } After uploading program you will see blue led flashes due to data is getting sent on GPIO2(TX). println ( " Hello World " ) ; delay ( ) ; } After uploading program you will see blue led flashes due to data is getting sent on GPIO2(TX).