Fads to Obsessions and Beyond...




Free domain for life, exceptional technical support, website transfer

ESP8266 Wi-Fi Module

A ESP8266 Wi-Fi module (ESP-07 breakout board version) is interfaced to a PIC18F248 microcontroller. The ESP8266 is used as a "slave" via AT commands to enable the PIC18F248 to act as a HTTP server and/or upload and download from Internet via local Wi-Fi hotspot/router. An Apache Server with MySQL (WAMP setup) is used as an example of using the PIC18F248 with ESP8266 to store sensor readings to a local database, which is accessible via the Internet.

While it may appear using the pre-installed AT command interpreter on the ESP8266 is superfluous (as it can be used as a stand-alone Wi-Fi solution, especially via programming using libraries supplied with the Arduino IDE), there is still the potential need for utilising the ESP8266 simply as a Wi-Fi bridge to PIC microcontrollers via serial port connection. This is for situations in which the ESP8266 (in the inexpensive breakout board version) does not provide sufficient on-board peripherals, I/O pins etc.

The use of the ESP8266 as a stand-alone Wi-Fi solution via the Arduino IDE/libraries will be the subject of a further project/investigation.


After having completed a number of DIY electronics projects, the number of sensors around the house proliferate over time. Water level and temperature sensor for the hydroponics, humidity sensor in the pantry, light sensor for LED Garden Lights etc. Often it is desirable to record the data produced from these sensors for later monitoring such as trend analysis or to review past performance.

Such storage can be done utilising EEPROM, SD-Card or even using an Android based smart phone for storage of collected data onto SD card/phone memory for later downloading to PC/desktop computer. However, it would be more satisfactory to have a method of allowing all such sensors around the house to report back to a central repository.

Bluetooth has limited range and generally is only between paired devices, rather than a network of multiple devices. Other wireless solutions such as the nRF24L01 are applicable in the DIY setting (i.e. relatively inexpensive components), but require a "bridge" (via Bluetooth, serial RS232, physical SD-card etc) in order to eventually store data to PC or be accessible via smart phone.

Now with the availability of the ESP8266 Wi-Fi module, the DIY hobbyist has the ability to not only automatically record sensor (and other data) using a centralised system, but to have centralised command and control of distributed electronic circuits providing various functions. The much lauded Internet of Things (IoT) is now within the reach of the humble hobbyist.

While the ability to add your own custom "denizen" to the Internet of Things "jungle" is attractive simply for the challenge, the IoT hype producing items such as dust-bins that can email when full and need emptying, see this article for further enlightening or disappointing examples depending on your point of view (1), should give pause.

The dangers of the IoT (other than the usual consumerism gone mad wasting the planet's resources) in my mind involve the loss of control and security (e.g., some hacker taking over your automated home and or some unscrupulous company selling your privacy/spying on your habits or holding you to 'ransom' by continual upgrades, back-end server fee's etc) that are traded for some perceived convenience or automation benefit. Of course, since the ESP8266 allows a DIY custom IoT "thing" such downside can be avoided (at least the unscrupulous company flogging your personal habits for money scenario) - the hacking, well that depends upon your ability (eyes wide shut!!).

So back on topic, another benefit of the ESP8266 is enabling a web interface and hence any device with a browser and Wi-Fi access to control DIY circuits. There are many situations in which the external environment (water, dust, temperature, physical locality etc) makes housing and mounting the control components of an electronics project (i.e., I/O devices such as switches, screens, keypads etc) problematic. In such situations it would be convenient that the circuity and associated components such as relays, motors, lights, sensors and other peripherals could be mounted in an appropriately sealed housing and controlled via Wi-Fi. Thus allowing easy and convenient location of the "user interface" while simultaneously potentially making housing other circuit components easier/less expensive.

This can be done with Bluetooth (for example see the Garden Light Project where Bluetooth connectivity enabled a convenient user interface with remote control via Android Smart Phone App of LEDs for lighting of a walking path) but the ESP8266 extends such capabilities and via suitably connected router, the user interface is available from anywhere in the World with Internet access.

The Circuit Details Section provides information about physical connection of the ESP8266 to a PIC18F248 microcontroller. There are also details about using the ESP8266 with a USB-TTL converter, so that a ESP8266 module can be tested using the pre-installed AT command interpreter and a terminal emulation programme on a connected PC. A number of peripherals (LM-35 temperature sensor via ADC, LED's and a 12V fan controlled by PWM for speed control) are also connected to the PIC18F248 to provide test cases for control via the ESP8266 and web-based applications/interfaces. Wiring connections are given in the Schematics Section.

The Testing/Experimental Results Section discusses the various steps used in testing the integration of Wi-Fi with the PIC18F248 via the ESP8266. The majority of the effort was determining the correct sequence of AT commands to send the ESP8266 in order to set the ESP8266 into server mode etc (and the corresponding text stream replies from the ESP8266 indicating success or otherwise of the various steps - unfortuantely, this appears to change with ESP8266 firmware version). The firmware required by the PIC18F248 (CCS C compiler) consists largely of text and string manipulation necessary to send appropriate series of AT commands to the ESP8266 and receive/parse the text stream response (and forming/parsing HTTP headers and HTML page code).

While the ESP8266 can be used as a stand-alone Wi-Fi solution (especially via programming using libraries supplied with the Arduino IDE), there is still the potential need for utilising the ESP8266 simply as a Wi-Fi serial bridge to PIC microcontroller, for situations in which the ESP8266 (in the inexpensive breakout board version) does not provide sufficient on-board peripherals, I/O pins etc. The use of the ESP8266 as a stand-alone Wi-Fi solution, via the Arduino IDE/libraries will be the subject of a further project/investigation.


The circuit consists largely of the usual minimum requirements for a PIC (PIC18F248 dealt with here) that is, power supply, oscillator (external crystal oscillator - 40MHz) and in-circuit serial programming (ICSP). A number of "peripherals" are attached to provide test-cases for the ESP8266 to send sensor derived data via Wi-Fi and suitably connected router to web based databases.

These include a number of LED's, a LM35 temperature sensor via the PIC on-board analog to digital convertor (ADC), and pulse-width-modulation (PWM) control of the speed of an attached 12V fan.

The majority of the circuit is based upon the DIY PIC Development Board.

Circuit Operation

A "wall wart" power supply was chosen rather than constructing a dedicated DC power supply dropping/converting from an AC wall socket. Surplus chargers from laptops are readily available (in this case supplying 16-24V with 65W max) which provide not only a safer option (compared to construction from a suitable transformer, rectifier, connection to AC etc) but also a much more economical option (generally zero cost for a surplus charger, compared to ten's of dollars for a suitable transformer, let alone cost of ancillary circuitry, PCB etc).

The surplus laptop charger requires a suitable socket connection and a voltage regulator, in this case a LM317T, to provide the regulated 5V generally required by PIC microcontrollers. The power supply circuit is given in the Schematics Section. The LM317T circuit is the standard design direct from the datasheet, with input and output capacitors to provide smoothing and the resistor/potentiometer to provide selection of output voltage.

The ESP8266 module (ebay purchased breakout board versions may vary, so check your particular component) is a 3.3V device (a ESP-07 version breakout board was used). Since the DIY PIC Development Board has a 3.3V source (from LM1086 regulator), this was used to power the ESP8266. A simple voltage divider is used to convert the 5V output from the PIC TX pin to 3.3V suitable for input to the ESP8266 RX pin. It was found that the 3.3V output from the ESP8266 TX pin was sufficient for the PIC input RX pin, so not voltage conversion from 3.3V to 5V was necessary.

The LM35 temperature sensor is powered by 5V and connected to the PIC ADC in order to record temperature to provide a real-time signal for the PIC micrcontroller to transmit to web based applications via the ESP8266 Wi-Fi. A 5V voltage reference is provide by a LM336 to provide a standard, stable voltage signal to the PIC ADC module.

A IRF540N n-channel MOSFET is controlled via pulse width modulation (PWM) to power and enable speed control of an attached 12V fan. A number of LED's are connected to the PIC output pins in order to provide a further test case for Wi-Fi/Web-based control.

A MAX232 is used to enable RS-232 communication between the PIC microcontroller and an attached PC.


Software/Firmware

The ESP8266 module provides all the necessary components to enable Wi-Fi communication using a serial port protocol (AT commands). This means that any firmware for the PIC microcontroller simply treats the ESP8266 as if it was a "normal" RS-232 communications device. The ESP8266 provides TX and RX pins (3.3V) which are simply connected to the RX and TX pins of the microcontroller, and then standard C compiler USART functions used to send and receive data. This "basic" functionality assumes that the default ESP8266 settings (baud rates etc) are suitable and that the ESP8266 will act in "slave" mode. Also, it is assumed that the ESP8266 module has the AT command interpreter pre-installed in firmware (which should be the case).

The ESP8266 is capable of accepting AT commands in order to change baud rates, device ID, etc and for setting the module to perform various Wi-Fi functions such as web server etc. The control of the ESP8266 can also be done via a USB-RS232 TTL converter allowing a Windows PC serial terminal program (or equivalent for non Windows PC platform) to send AT commands via a serial COM port.

This enables simple configuration of the ESP8266 without complicating the firmware necessary for the PIC microcontroller. The communications instructions between PC and the ESP8266 (for changing ESP8266 settings and checking basic module functionality) and between PIC microcontroller and ESP8266 (for serial Wi-Fi transfer of data) are detailed in the Testing/Experimental Results Section below.

The ESP8266 is envisaged for use initially to provide Wi-Fi serial communications in slave mode, thus enabling a PIC microcontroller to act as a web server or similar. This again makes the PIC microcontroller firmware relatively straight forward, with the ESP8266 module handling the Wi-Fi transmission and TCP/IP stack protocols etc. The development of the software for custom web based GUI, data transmission and storage etc (via HTML, PHP and MySQL) is outlined in the Testing/Experimental Results Section below.

This means a web based application (running on a suitable browser) can be used as a "terminal" for a PIC microcontroller based circuit enabling control of peripherals, data logging and storage.


Note: Image loading can be slow depending on server load.

  • ESP8266 SchematicESP8266 Schematic

    Silver Membership registration gives access to full resolution schematic diagrams.

    ESP8266 Schematic

  • USB-TTL Converter to ESP8266 SchematicUSB-TTL Converter to ESP8266 Schematic

    Silver Membership registration gives access to full resolution schematic diagrams.

    USB-TTL Converter to ESP8266 Schematic

This project did not require a PCB.

The construction was done using prototyping board. See the photographs and schematic diagram sections.

Qty Schematic Part-Reference Value Notes
Resistors
2R1,R610K1/4W, 10% 
1R21k1/4W, 10% 
1R33h1/4W, 10% 
1R42k1/4W, 10% 
1R51501/4W, 10% 
3R7-R93301/4W, 10% 
Capacitors
2C1,C222pFCeramic 
1C30.33uF 
1C40.1uF 
5C5-C91uF 
Diodes
2D1,D31N-4001 
1D2LM336-2V52.5V voltage reference IC
3D4-D6LEDRed, Green, Yellow LED
Integrated Circuits
1U1PIC18F248PIC microcontroller  datasheet
1U27805Linear Voltage Regulator  datasheet
1U4MAX232ERS232 Driver/Receiver datasheet
1U6LM35Temperature Sensor datasheet
Miscellaeous
1J1CONN-H55-pin connector for ICSP
1SW1SW-SPDT 
1X110MHzCrystal Oscillator
1Z1ESP8266Wi-Fi Module datasheet
Description Downloads
ESP8266 - Bill of Materials Text File Download

Testing of the ESP8266 Bluetooth module consisted of a number of stages. Initially, a USB-TTL converter was used to provide connection of the ESP8266 to a PC via USB cable. This enabled using a Windows PC terminal program to send AT commands to the ESP8266. Therefore, basic operation of the ESP8266 (i.e., did it power up correctly and return device ID etc) could be checked before moving on to custom circuitry and software. This is important as the quality of ESP8266 boards from ebay suppliers can sometimes be low (although I have experienced no trouble to date with the ESP8266's purchased).

Secondly, the ESP8266 is then tested within a circuit interfaced to a PIC18F248 (via USART hardware serial port) and the PIC18F248 in turn is connected to PC via a USB-TTL serial connection. The dual serial port connections with the PIC18F248 enable control of the ESP8266 while "debugging" and ongoing status information can be output to PC/terminal programme. The ESP8266 is connected to the hardware PIC18F248 USART serial port to enable the highest baud rate (115400) with the Wi-Fi module. Whereas, since the PIC18F248 only has a single hardware USART serial port, software emulation (baud rate 38400) was used for the serial connection via USB-TTL to the PC/terminal programme.

This enables testing of the firmware within the PIC18F248 that data can be sent and received via Wi-Fi to the PIC microcontroller, controlling the ESP8266 in the various modes available via AT commands.

Finally, custom designed and implemented web based apps (running in the Google Chrome browser) were produced to send and receive data from the PIC18F248 via Wi-Fi. This staged process allowed the development and testing to proceed smoother in that errors and bugs could be isolated to the current phase.

Initial Testing with USB-TTL converter

The ESP8266 accepts AT commands (when the AT command interpreter firmware is installed - which is the default when the module is purchased) which is useful to test if the module is powering up correctly in the first instance. A USB-TTL converter (I used a $2 converter purchased from ebay) makes it convenient to connect the ESP8266 to a PC via USB (see the Schematics Section for the simply wiring required). The USB-TTL converter takes power from the USB socket (no other power supply necessary), and the particular converter I had also output 3.3V which again is convenient to power-up the ESP8266.

The initial step with the USB-TTL converter is to downloaded the necessary USB drivers (if using Windows) which I sourced from the Prolific Technology Inc site (2) which at the time of download was a file titled "PL2303_Prolific_ DriverInstaller_v1.12.0.zip". Unzip the file, click the installer and follow the usual steps for installing the driver software. When the USB-TTL converter is then connected to the USB port of the PC, Windows should do the usual driver installation steps.

The next step is to use a suitable serial port (COM) terminal emulation program to send commands to the ESP8266 via the USB-TTL converter. I used "Terminal" which is very useful for debugging serial communication and is available for free (3) (download the zip file, unzip, and use the installer as usual for a Windows program).

The ESP8266 is connected to the USB-TTL converter as per the second schematic in the Schematics Section. This enables connection to a PC and the send/receipt of AT commands by the ESP8266. The ESP8266 is a 3V device, but if using a USB-TTL convertor that has 3V output,the USB-TTL converter can also be used for the power supply, otherwise would need a seperate 3V supply. Note that the RX pin on the ESP8266 is not 5V tolerant (expects 3V). Since using a USB-TTL with a 3V output this was not a problem, but if interfacing with non-3V device/bus, will need voltage conversion for the ESP8266 RX pin (voltage divider or similar). The steps for booting/powering-up the ESP8266 in AT command mode are as follows:

  • Connect ESP8266 as per second schematic
  • Use Terminal (or similar) as serial comms Application on PC
    • COM port 3, baud rate 115200, 8 bits, no parity, 1 stop bit
  • Connect USB-TTL to PC USB port with suitable cable
    • Red LEDS on the ESP8266 and the USB-TTL both illuminate, showing power on
    • There will be an initial flash from the blue LED on the ESP8266
  • With Terminal (App on PC), click the CONNECT button, now should be in communications with ESP8266
    • In the SEND command line, type AT (ensure CR+LF is selected) and then click SEND. The ESP8266 should respond with “OK” (which is displayed on the terminal window). The command AT tests the setup of the ESP8266 wireless module and connection via USB-TTL
  • Now ready for sending AT commands to the ESP8266 from the PC

The following are some useful AT commands to test the ESP8266 module, a full list of AT commands is available here (4).

The command "AT+GMR" is used to return the version of the AT command ESP8266 firmware installed and SDK that is expected. The response I received for the ESP-07 version modules was:

the output

The command "AT+CWMODE_CUR?" queries the ESP8266 for the current Wi-Fi mode. The response I received for the ESP-07 version modules was:

the output

The response from the ESP8266 is a numeric code, 1 = station, 2=softAP, 3=station+softAP. The mode needs to be either 1 or 3 in order to enable retrieval of access point details. To change ESP8266 Wi-Fi mode, use the "AT+CWMODE_CUR=3" command.

The command "AT+CWLAP" will list the details about the various Wi-Fi access points currently in range. The response I received for the ESP-07 version modules was:

the output

Using the above commands, this is sufficient to test that the ESP8266 is responding correctly via the USB-TTL/serial port (therefore the initial circuit is OK, and the ESP8266 module is OK) and that the Wi-Fi can see/access local access points (via local routers etc).

Testing PIC18F248/ESP8266 - PC terminal sending AT commands

When the ESP8266 has been checked to be operational (see previous section detailing testing with USB-TTL converter and serial port emulation program), the module can be interfaced to the PIC microcontroller and Wi-Fi communications checked.

The Schematics Section details the wiring connections necessary to interface the ESP8266 to the microcontroller USART I/O pins (use the hardware USART serial port to enable the highest baud rate to be used for the Wi-Fi communications). The firmware for the microcontroller (using CCS C compiler) is relatively straight forward as the ESP8266 "looks like" a normal RS-232 serial communications port. The following code snippet 1 demonstrates basic functionality for the PIC microcontroller to send and receive data (AT commands and the subsequent responses) and then echo the received data to PC via RS-232.

Code Snippet 1:



   				

The above code snippet,

The following code snippet 2 demonstrates

Code Snippet 2:



   				

The Downloads Section at the bottom of Testing/Experimental Results has the full CCS C source code used for communication with the PIC micrcontroller via the HC-05 bluetooth module to control LED's, speed of a DC fan motor and receive data from a LM35 temperature sensor (with a real time graph of the data on the Android phone app) as demonstrated working in the Video Section.


Custom Developed Web App's

Text


Downloads

Description Downloads
Example PIC code with PIC18F248/ESP8266 Wi-Fi interface, as demonstrated in the Video Section: CCS C Source Code Download
Header File Source Code Download

As a general precauation double check polarity of power connections etc before powering up the various IC's and or circuit. Also, note that the ESP8266 is 3V device if interfacing to other circuitry (e.g. "typically" PIC microncontrollers are 5V).

As discusssed in the Testing/Experimental Results Section, the use of a USB-TTL converter to provide connection of the ESP8266 to a PC via USB cable is useful for initial testing of the ESP8266 module. This enables using a Windows PC terminal program to send AT commands to the ESP8266 to test basic operation. This is very useful if there are any doubts about the quality of the ESP8266 module and or if it has been powered up with incorrect polarity and or voltage etc.


No video's available for this component.

Comments/Questions

No comments yet.

Add Comment/Question

Only Logged-In Members can add comments

"If we could sell our experiences for what they cost us, we'd all be millionaires".

Please donate any amount to help with hosting this web site.

If you subscribe (only $2/annum) you can view the site without advertisements and get emails abouts updates etc.

X

Sorry!

Only logged-in users with correct Membership Level can download.


Membership starts at only $2, so join now!