This is only a preview of the April 2018 issue of Silicon Chip. You can view 47 of the 96 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Items relevant to "230VAC Thermopile-based Heater Controller":
Items relevant to "Low cost, Arduino-based 3-Axis Seismograph":
Articles in this series:
Items relevant to "The Clayton’s “GPS” time signal generator":
Items relevant to "El Cheapo Modules 15: ESP8266-based WiFi module":
Purchase a printed copy of this issue for $10.00. |
ESP8266 Features
WiFi – 802.11b/g/n
32-bit RISC CPU
512KB-16MB flash memory
HTTP & FTP
IPv4
TCP/UDP
17 GPIO pins
SPI
I2S and Software I2C
10-bit ADC
Fig.1: block diagram of the ESP8266 IC. The left-hand side of the diagram contains
the RF sections while the right-hand side is the baseband and CPU section.
team led by radio astronomer Dr John
O’Sullivan.
The IEEE 802.11 protocol was first
released in 1997 and has since been
revised and updated numerous times.
802.11 is a set of MAC (media access control) and PHY (physical layer) specifications for implementing
WLAN (wireless local area network)
data communication in the 2.4GHz,
3.6GHz, 5GHz, 5.9GHz and 60GHz
frequency bands.
There are many different versions
of the 802.11 protocol. Those that are
most popular for WiFi are 802.11a,
802.11b/g/n and 802.11ac. These
mainly differ in terms of their PHY
specifications, as shown in Table 1.
The ESP8266 chip
The ESP8266 is a self-contained
WiFi networking transceiver and
microprocessor, packaged in a single 32-pin QFN SMD chip measuring
only 5 x 5mm. It operates in the internationally unlicensed 2.4-2.5GHz
ISM (Industrial, Scientific and Medical) band and is compatible with the
802.11b/g/n protocols.
The downside to the 2.4-2.5GHz
band is that it is also used by Bluetooth
devices, microwave data transceivers
using the Nordic nRF24L01+ chip and
also plagued with various sources of
noise like microwave ovens. So this is
a somewhat noisy band, and becoming noisier all the time.
The block diagram of Fig.1 shows
what’s inside the ESP8266. On the
left are the RF sections, including the
transmitting and receiving sections,
the T/R switch, an LNA (low noise
amplifier) and an RF balun for connecting to one or two antennas.
On the right is the baseband section
which includes an integrated 32-bit
siliconchip.com.au
RISC CPU, a memory controller with
both ROM and SRAM, all of the registers and sequencers for implementing
a full TCP/IP stack and interfaces for
SDIO (SD cards), SPI (serial peripheral
interface), GPIO and I2C communication with external MCUs and/or external flash memory.
Incidentally, the RF output power
in 802.11b mode is +19.5dBm, or just
under 100mW. When this output is
being provided in transmit mode the
chip’s current drain from the 3.3V
supply is 215mA, corresponding to
around 710mW.
In receive mode with 1024-byte
packets, the current drops to around
60mA (<200mW). The chip also has
two power saving modes: standby
mode, where only the RTC and watchdog remain active (current <1mA) and
deep sleep mode where only the RTC
remains active and the current falls to
below 12µA. The chip can be woken
up to transmit packets in less than 2ms.
The ESP-01 module
The ESP-01 module is quite small,
measuring only 25 x 14.5mm, including the PCB track antenna and the
8-pin interface connector.
Fig.2 shows the complete circuit
for the latest version (V2) of the ESP01 module and there’s very little in
it apart from the ESP8266EX chip itself, a tiny 26MHz crystal and a 25Q80
1MB flash memory chip. There are two
LEDs, one to indicate when the module is powered up (LED1) and the other
to indicate when serial data is being
transmitted (LED2).
All of the connections to and from
the external micro are made via CON1
at upper left.
The module is designed to operate
from 3.3V and should not be connected
Celebrating 30 Years
The ESP8266 is a low-power, selfcontained WiFi chip.
The main use of the ESP8266 is to
provide a WiFi interface for other
microcontroller devices.
However, the ESP8266 IC is powerful enough to be used as a low-power
computer, combined with being able
to flash the firmware with your own
program code using a bootloader.
It has an extensive API provided on
ROM which implements various timer,
hash (MD5 & SHA1), WiFi and TCP/
UDP functions etc.
A list of API functions can be found at:
siliconchip.com.au/link/aaj4
siliconchip.com.au/link/aaj5
Some potential uses include:
Remote file manager
Web server
Ad-hoc network
Data logger
Baby monitor
What is it?
April 2018 77
Fig.2: complete circuit diagram for version 2 of the ESP-01 module. The PCB track antenna has a range of approximately
300m under good conditions with line of sight and possibly 10m at best indoors.
to a 5V supply. The logic inputs of the
ESP8266EX are not tolerant of 5V, so if
your external micro operates from 5V
the interconnections need to be made
via logic level translation circuitry. We
have read that applying 5V to its input pins does no harm but this is an
undocumented feature and we don’t
suggest you rely on it.
Another point to note is that the
ESP8266EX chips used in the latest
versions of the ESP-01 module (V2) are
programmed to communicate with an
external PC or micro at a default rate of
115,200 bps (baud), while earlier versions were set up for 9600 bps. This
can cause complications when you try
to use the newer ESP-01 modules with
an Arduino Uno or equivalent.
in most versions of Windows, Linux
and macOS.
Note that although the popular USB/
UART bridge modules also provide a
3.3V output, this is generally only capable of supplying 100mA or so. That’s
why you need to use an additional LDO regulator, like the LM1117T
shown, to provide for the higher current levels needed by the ESP8266
when it’s transmitting data packets.
Your PC will be able to communicate with the ESP8266 and hook up to
a local WiFi router and network, using
a standard communications terminal
program like Tera Term. Note that this
won’t give your PC direct access to the
wireless network, since it won’t have a
network driver that understands how
to communicate with the ESP8266.
Programming it directly
While you can use the ESP-01 module purely as a wireless “bridge”, it’s
also possible to program the ESP8266
directly, ie, to run some code without
a separate micro. That’s because the
ESP8266 does have a built-in CPU
of its own, together with RAM and
EEPROM.
In fact, ESP8266/Arduino enthusiasts have come up with a nifty
Connecting to a PC
Interfacing the ESP-01 module with
a computer is quite easy. All that’s
needed is a USB-UART bridge module
to provide a communications link with
the computer (via a USB port) and also
to derive power from the computer via
a 5V-3.3V LDO (low-dropout) regulator
to reduce the supply voltage to 3.3V.
The basic circuit needed is shown in
Fig.3, although we’ve shown two versions of the USB-UART bridge module
– one with a micro USB socket and the
other with a type A socket. Both use
the popular CP2102 chip, for which
there’s a VCP (virtual COM port) driver
78
Silicon Chip
Fig.3: if you want to connect the ESP-01 module to a computer, all that’s needed
is a USB-UART bridge like the CP2102 and LDO regulator to reduce the USB
port’s 5V supply voltage to 3.3V.
Celebrating 30 Years
siliconchip.com.au
Arduino board package which allows
the ESP8266 to be programmed via
sketches written in the Arduino IDE,
using standard Arduino functions
and libraries. Information about this
Arduino “core” is available at https://
github.com/esp8266/Arduino
Using it with an Arduino
Connecting the ESP-01 module to an
Arduino is a little more complex than
you might expect, mainly because of
the need to power the module with its
own 5V-3.3V LDO regulator and also
because logic level translation circuitry is needed to interface between the
module and an Arduino’s I/O pins.
The easiest way to do this is to use
a WiFi module interface shield like
the Freetronics ESP1SH, as shown in
Fig.4. The shield mounts on the top
of an Arduino and provides an 8-pin
header socket for plugging in an ESP01 module and an LD1117 3.3V LDO
to power the module plus logic level
translation circuitry for the TX and
RX data lines.
There’s also a pushbutton switch
(S2) for reprogramming the ESP-01’s
flash memory, another pushbutton
switch (S1) to reset both the ESP-01
and the Arduino together and most
importantly, an 8-way-by-3 header
strip which allows you to link the level
shifted ESP-01 TX and RX lines to one
of eight possible pins on the Arduino.
An enlarged
view of the latest
ESP-01 module.
It features a few
SMD components
including a 26MHz
crystal and 1MB
of flash memory.
The GND pin is at
the top-right of the
PCB, while Vcc is
at the bottom-left.
Link header
That link header on the ESP1SH
shield is important because of the
point mentioned earlier, about the
latest ESP-01 modules being programmed to communicate at 115,200
bps. This a problem with the Arduino
Uno and its clones because the ATmega328 CPU used in these modules
has only one hardware UART, which
is normally used for communication
with the PC via the onboard serial/
USB bridge.
To communicate with another serial
device like the ESP-01, you need to use
a software-driven serial port with a different pair of pins for the TX and RX
lines. But these software-driven serial
ports can only operate at a maximum
speed of 38,400 bps.
But there is a workaround. First,
you download a do-nothing sketch
to the Arduino and set it running, so
that it ignores the hardware UART
temporarily.
Then connect your ESP-01 module
siliconchip.com.au
An enlarged photo of the silicon die and metal layers of an ESP8266 (a variant of
the ESP8089). The RF section is at upper left and takes up a larger portion of the
chip. The area below and right is memory while the I/O pads are along the edges.
https://zeptobars.com/en/read/Espressif-ESP8266-wifi-serial-rs232-ESP8089-IoT
Celebrating 30 Years
April 2018 79
Fig.4: connecting the ESP01 module to an Arduino
via the Freetronics ESP1SH
shield. The benefit of
using this shield is that it
provides a 8-pin header
to plug the module into,
handles the level shifting
from 5V to 3.3V, and logic
level translation circuitry
for the transmit and receive
pins.
However, this of course is
not the only way to connect
the ESP8266 to an Arduino.
to the same hardware UART RX and
TX pins (D0 and D1). You can then
reprogram the ESP-01 directly from
the PC so that it defaults to a data rate
of 38,400bps or less, making it compatible with the software serial port.
Then reconnect the ESP-01 TX and
RX lines to a different pair of pins on
the Arduino and set those up as a software serial port.
Alternatively, you could simply use
the hardware TX and RX pins to communicate with the ESP-01 with the
limitation that you must disconnect
it when re-programming the Arduino
board. This will limit your use of the
Serial Monitor for debugging, though.
Things are a lot easier if you use an
Arduino Mega, Mega 2560R, Freetronics EtherMega or the Duinotech
Mega, because these all use either the
ATmega1280 or 2560 processors, both
80
Silicon Chip
of which have a larger flash memory
plus an additional three UARTs. Each
of these can provide a serial port which
operates at 115,200 bps or more.
The ESP1SH shield’s header strip
allows you to link up the ESP-01’s TX
and RX lines to any serial port you
wish, without the need for reprogramming. In the case of the Mega2560R,
all you need to do is connect the ESP01 TX line to pin 19 (RX1) and the
RX line to pin 18 (TX1) using a pair
of short male-to-female jumper leads.
This is shown in both Fig.4 and the
photo at right.
We’ll look at what’s involved in programming an Arduino Mega to use the
ESP-01 module for WiFi communication shortly. In the meantime, let’s
look at how the ESP-01 can be linked
to a Micromite.
Connecting a Micromite?
How to connect an ESP-01 module
Celebrating 30 Years
to a Micromite is shown in Fig.5. Note
that we still need to use an LM1117T
LDO regulator to provide 3.3V to the
ESP-01, since its current drain is somewhat higher than that available from
the Micromite’s own 3.3V regulator.
But the TX and RX lines from the ESP01 can be directly connected to the RX
and TX pins of the Micromite, since
no level translation is needed.
There’s no problem with data rates
either, providing you use the connections shown, which use the Micromite’s hardware UART port (COM1).
This can operate at 115,200 bps without any problems, provided you are
running the Micromite at a clock
frequency of 40MHz (the default),
50MHz, 30MHz or even 20MHz.
WiFi via the ESP-01
Because the ESP8266 chip in the
ESP-01 module is designed to communicate via standard Hayes AT modem
siliconchip.com.au
Fig.5: when connecting the ESP-01 to
a Micromite you still need a 5V-3.3V
LDO regulator. However, no level
translation is needed so the data pins
can be connected directly.
text commands, using it to add WiFi
capabilities to your microcontroller
project is relatively easy. All your Arduino sketch or MMBasic program
needs to do is set up the ESP8266 chip
using the appropriate AT commands,
and then respond to the data it gets
back from the ESP8266.
If this sounds a bit daunting, you can
find a list of all the commands here:
siliconchip.com.au/link/aaj7
If you want to use the ESP-01 module with a Micromite, you’ll get a lot
of help and guidance by studying a
program that Micromite guru Geoff
Graham wrote to accompany his article published in the December 2014
issue of Silicon Chip. The program is
called “WEBServer.bas” and can be
downloaded for free from siliconchip.
com.au/Shop/6/2890
You’ll also find that Geoff Graham’s
article in the December 2014 issue
has a listing of the main AT commands needed to communicate with
the ESP-01/ESP8266 (page 33, www.
siliconchip.com.au/Article/8194).
The ESP1SH shield makes most
of the connections between the ESP01 and the Arduino Mega, when you
plug it in.
The only additional connections
you need to make are between the
level translated TX and RX lines of
the ESP-01 (the uppermost and lowermost rows of pins on the shield’s 8x3
programming header) and the IO19/
RX1 and IO18/TX1 pins of the Ar-
duino Mega. As shown in the photo
below and in Fig.4, these added connections are made by short male-tofemale jumper leads.
Just remember to remove the
jumper shunts which come with the
ESP1SH shield, because these can
only be used to connect the ESP-01’s
TX and RX lines to the Mega’s IO0/
RX0 and IO1/TX0 hardware UART (or
to pins IO2-IO7 for using a software
serial port).
The jumper lead from one of the uppermost TX pins of the shield’s 8x3
header needs to be connected to the
Mega’s IO19/RX1 socket (blue lead in
Fig.4), while the lowermost RX pins
on the header should be connected to
the Mega’s IO18/TX1 socket (red lead
in Fig.4). If you get these two connections swapped, your Mega won’t be
able to communicate with the ESP01 module.
Programming the Mega for WiFi
communication via the ESP-01 is fairly
easy. You’ll find quite a few Arduino
sketches on the web which illustrate
how you can use the ESP8266, and
there’s also a WiFi Library available on
the main Arduino website (see www.
arduino.cc/en/Reference/Libraries).
To get you started, I’ve adapted
a simple pass-through sketch that I
found on one of the websites so that
it’s capable of running straight away
on the Mega/ESP1SH/ESP-01 setup.
The sketch makes the Mega behave
as a relay station or mirror between
All that’s needed extra when
using the Freetronics ESP1SH is
two jumper leads to connect the
transmit and receive lines.
www.freetronics.com.au/products/
esp-01-wifi-module-shield
With an Arduino Mega
As mentioned earlier, the easiest
Arduino to connect with the ESP-01
module is the Mega. It’s especially
easy if you use a WiFi shield like the
Freetronics ESP1SH to interface between the two, as shown in the adjacent photo.
siliconchip.com.au
Celebrating 30 Years
April 2018 81
ing with the Mega and ESP8266 at
115,200 baud (bps).
Why not try programming the ESP01 WiFi module yourself?
// Sample program from Fig.6.
void setup() {
Serial.begin(115200);
Serial1.begin(115200);
}
void loop() {
if (Serial.available())
Serial1.write(Serial.read());
if (Serial1.available())
Serial.write(Serial1.read());
}
Loading your own code onto
the ESP8266
Fig.6: the sample serial passthrough program running on an Arduino Mega.
This program merely repeats data to and from the ESP-01 module.
your computer and the ESP-01 and
its ESP8266.
So any AT commands sent from your
computer via the Arduino IDE’s Serial Monitor utility are relayed to the
ESP8266, and any responses from the
ESP8266 are relayed back to the IDE’s
Serial Monitor. This makes it easy to
try sending various AT commands to
the ESP-01 and to see its responses.
The sketch is listed at the end of this
section and you can also download it
from the Silicon Chip website.
The screen grab shown in Fig.6
shows how this works. The lines underlined in red are those with the
AT commands sent to the ESP-01/
ESP8266, while those without any underlining show the responses coming
back from it. The first AT command
is basically just an enquiry to see if
the ESP8266 is awake, with it returning OK if it is.
Similarly, the command AT+GMR
resets the ESP8266 and also gets it to
respond with information concerning
its firmware.
Then the command AT+CWMODE=1
directs the ESP8266 to assume WiFi
client mode, as opposed to access
point mode (mode 2) or client/access
point mode (mode 3).
The additional command shown
in Fig.6 is AT+CWLAP which asks
the ESP8266 to list any WiFi access
points currently available within its
range. Of the three lines you can see
in Fig.6, the last line corresponds to
my office network router, while the
other two are routers or peripherals
in nearby homes.
The other point to note from Fig.6
is that the Arduino Mega I was using
at the time had been allocated to virtual COM port 20 (top left), while the
IDE Serial Monitor was communicat-
The WeMos D1 R2, which is based around the ESP8266,
was used in the Water Tank Level Meter project (Feb 18).
82
Silicon Chip
If you do this, you will lose the AT
command set capabilities, since these
are provided by the default code loaded into the ESP8266 processor. But it
does allow the ESP-01 to become an
independent module without the need
for many external components.
The best demonstration of this is in
our NTP Clock project article on page
58, where we turned an ESP-01 into
a device which pretends to be a GPS
module, supplying NMEA data from
its serial port and a 1pps signal but it
actually gets the time, date and location data from NTP and location servers on the internet. This allows you
to use a GPS-synchronised clock in
a location where a GPS signal is not
available.
So we won’t go into great detail
about how to program the ESP8266
yourself here, as you can refer to that
article on page 60 and examine its
source code (which can be downloaded from the Silicon Chip website)
to see how it works.
SC
Links for using the ESP-01/ESP8266:
https://espressif.com
www.siliconchip.com.au/link/aaj6
https://forum.arduino.cc/index.php?board=11.0
http://bbs.espressif.com
www.electrodragon.com/w/Wi07c
www.siliconchip.com.au/link/aaj7
www.sparkfun.com/products/13678
https://en.wikipedia.org/wiki/ESP8266
www. siliconchip.com.au/link/aaj8
https://github.com/espressif
https://github.com/esp8266/Arduino
https://github.com/tttapa/ESP8266
https://github.com/acrobotic/Ai_Docs
https://github.com/espressif/esp8266_mp3_decoder/
Celebrating 30 Years
siliconchip.com.au
|