D1 Mini Pro - EN
D1 Mini Pro - EN
Thank you for purchasing our AZ-Delivery D1 Mini Pro. On the following
pages, we will introduce you to how to use and set-up this handy device.
Have fun!
Table of Contents
Introduction....................................................................................................3
Specifications................................................................................................4
The pin headers.............................................................................................5
Features........................................................................................................6
The pinout.....................................................................................................7
Digital I/O pins...............................................................................................8
PWM (Pulse width modulation)..................................................................9
Analog input...............................................................................................9
Serial ports.................................................................................................9
The I2C interface.....................................................................................10
The SPI interface.....................................................................................10
D1 Mini Pro module - Software....................................................................11
Digital I/O pins..........................................................................................11
Analog input pin.......................................................................................12
Serial communication...............................................................................13
Sharing CPU time with the RF part..........................................................14
How to set-up Arduino IDE..........................................................................15
Additional setup.......................................................................................19
Sketch examples.....................................................................................21
Blink sketch example...............................................................................21
Software PWM sketch example...............................................................22
Serial communication sketch example.....................................................23
-2-
Introduction
There are different ways to program the D1 Mini Pro module: using Arduino
IDE, official ESP SDK for C programming, MicroPython firmware, etc.
-3-
Specifications
The D1 Mini Pro module has an on-board LED. The LED is internally
connected to the GPIO2 port.
The D1 Mini Pro module has a connector for external antenna which is used
to extend the antenna strenght and the WiFi range. Before it can be used
small modification has to be made. The modification information is on the
next page.
-4-
Antenna connector mod
-5-
The pin headers
The D1 Mini Pro module comes unsoldered with one pair of eight pin male
headers, one pair of eight pin female headers and a pair of eight pin female
headers with extra long legs (so-called stacking headers).
-6-
Features
• 802.11 b/g/n
• Integrated low power 32-bit MCU
• Integrated 10-bit ADC
• Integrated TCP/IP protocol stack
• Integrated TR switch, balun, LNA, power amplifier and matching network
• Integrated PLL, regulators, and power management units
• Supports antenna diversity
• Wi-Fi 2.4 GHz, support WPA/WPA2
• Supports STA/AP/STA+AP operation modes
• Supports Smart Link Function for both Android and iOS devices
• SDIO 2.0, (H) SPI, UART, I2C, I2S, IRDA, PWM, GPIO
• STBC, 1x1 MIMO, 2x1 MIMO
• A-MPDU & A-MSDU aggregation and 0.4s guard interval
• Deep sleep power <10uA, power down leakage current < 5uA
-7-
The pinout
The D1 Mini Pro module has two rows of eight pins (sixteen pins in total).
The pinout is shown on the following image:
Note: The D1 Mini Pro module has a 5V voltage output pin to power the
external electronic devices connected to it, but it is not 5V tolerant! The 5V
pin is power output pin, which outputs power from the microUSB port.
Note: The D1 Mini Pro module also has a 3.3V voltage output pin for
powering external electronic devices. This is regulated 3.3V from the on-
board 3.3V voltage regulator.
-8-
Digital I/O pins
Just like any Atmega328p board, the D1 Mini Pro module has digital
input/output pins or GPIO - General Purpose Input/Output pins. As the
name implies, it can be used as digital input to read a digital voltage, or as
digital output to output either 0V or 3.3V.
The maximum current that can be drawn from a single GPIO pin is 12mA!
NOTE: The pins of the D1 Mini Pro module are not 5V tolerant,
applying more than 3.6V on any pin could damage the chip!
GPIO1 and GPIO3 are used as TX and RX of the hardware Serial port
(UART), so in most cases, these two can not be used as a normal I/O while
sending/receiving serial data.
The D1 Mini Pro module has one built-in LED connected to the GPIO2 pin.
-9-
PWM (Pulse width modulation)
Unlike most Atmel chips (Atmega328p), the D1 Mini Pro module does not
support hardware PWM. However, software PWM is supported on all digital
pins. The default PWM range is 10bits at 1kHz, but this can be changed (up
to 14 bits at 1kHz).
Analog input
The D1 Mini Pro module has a single analog input, with an input voltage
range of 0V-3.0V. If more than 3.3V is applied, the chip could be damaged.
The analog to digital converter (ADC) has a resolution of 10bits.
Serial ports
The D1 Mini Pro module has two hardware UARTS (Serial ports):
UART0 on pins 1 and 3 (TX0 and RX0 respectively), and UART1 on pins 2
and 8 (TX1 and RX1 respectively). However, GPIO8 is used to connect the
flash chip. This means that UART1 can only transmit data. In most cases
only one UART port is more than enough.
UART0 also has hardware flow control on pins 15 and 13 (RTS0 and CTS0
respectively). These two pins can also be used as an alternative for TX0
and RX0 pins.
- 10 -
The I2C interface
The D1 Mini Pro module does not have a hardware I2C (TWI - Two Wire
Interface), but it is implemented in software. This means that any two digital
pins can be used as the I2C pins. By default, the I2C library uses GPIO4 as
SDA and GPIO5 as SCL. The maximum speed of the I2C clock is
approximately 450kHz.
The D1 Mini Pro module has one SPI connection available to the user,
referred to as HSPI. It can be used in both Slave and Master mode (in
software!).
It uses:
- GPIO14 as a clock - CLK,
- GPIO12 as MISO,
- GPIO13 as MOSI and
- GPIO15 as Slave Select - SS.
- 11 -
Digital I/O pins
Just like with a regular Atmega328p board, the pin function can be set using
the following line of code:
pinMode(pin, mode)
where pin is the name of GPIO pin, and mode can be either INPUT (which
is the default), or OUTPUT, or INPUT_PULLUP to enable the built-in pull-up
resistors for pins GPIO0-15. To enable the pull-down resistor for GPIO16
use INPUT_PULLDOWN_16.
To set an output pin HIGH (3.3V) or LOW (0V), use the following line of code:
digitalWrite(pin, value)
where pin is the name of GPIO pin, and value either 1 or 0 (or HIGH and
LOW).
- 12 -
To enable PWM on a certain pin, use the following line of code:
analogWrite(pin, value)
where pin is the name of GPIO pin, and value is a number between 0 and
1023.
The range of the PWM output can be changed by using the following line of
code: analogWriteRange(new_range)
The frequency of PWM can be changed by using the following line of code:
analogWriteFreq(new_frequency)
where new_frequency should be between 100Hz and 1000Hz.
The D1 Mini Pro module can also use the ADC to measure the supply
voltage (VCC). To do this, include ADC_MODE(ADC_VCC) at the top of the
sketch, and use ESP.getVcc() to actually get the voltage.
- 13 -
Serial communication
To use UART0 (TX=GPIO1, RX=GPIO3), use the Serial object, just like on
an Atmega328p board: Serial.begin(baud_reate)
- 14 -
Sharing CPU time with the RF part
One thing to keep in mind while writing programs for the D1 Mini Pro
module (ESP8266) is that the sketch has to share resources (CPU time and
memory) with the Wi-Fi and TCP-stacks (the software that runs in the
background and handles all Wi-Fi and IP connections). If the code takes too
long to execute, and do not let the TCP stacks do their thing, the program
might crash, or the data could be lost. It is better to keep the execution time
of the loop under a couple of hundreds of milliseconds. Every time the main
loop is repeated, a sketch yields to the Wi-Fi and TCP to handle all WiFi
and TCP requests. If the loop takes longer than this, the CPU time have to
explicitly be given to the Wi-Fi/TCP stacks, by using including delay(0) or
yield(). If this is not done, network communication will not work as
expected, and if it is longer than 3 seconds, the soft WDT (Watchdog Timer)
resets the ESP. If the soft WDT is disabled, after a little over 8 seconds, the
hardware WDT resets the chip. From the perspective of microcontroller
however, 3 seconds is a very long time (240 million clock cycles), so unless
some extremely heavy number crunching is done, or sending extremely
long strings over serial, the sketch will not be affected by this. Just keep in
mind to add the yield() inside the for or while loops that could take
longer than, say 100ms.
- 15 -
How to set-up Arduino IDE
If the Arduino IDE is not installed, follow the link and download the
installation file for the operating system of choice. The Arduino IDE version
used for this eBook is 1.8.13.
For Windows users, double click on the downloaded .exe file and follow
the instructions in the installation window.
- 16 -
For Linux users, download a file with the extension .tar.xz, which has to
be extracted. When it is extracted, go to the extracted directory and open
the terminal in that directory. Two .sh scripts have to be executed, the first
called arduino-linux-setup.sh and the second called install.sh.
To run the first script in the terminal, open the terminal in the extracted
directory and run the following command:
sh arduino-linux-setup.sh user_name
user_name - is the name of a superuser in the Linux operating system. A
password for the superuser has to be entered when the command is
started. Wait for a few minutes for the script to complete everything.
The second script, called install.sh, has to be used after the installation
of the first script. Run the following command in the terminal (extracted
directory): sh install.sh
After the installation of these scripts, go to the All Apps, where the Arduino
IDE is installed.
- 17 -
Almost all operating systems come with a text editor preinstalled (for
example, Windows comes with Notepad, Linux Ubuntu comes with
Gedit, Linux Raspbian comes with Leafpad, etc.). All of these text
editors are perfectly fine for the purpose of the eBook.
- 18 -
If the Arduino IDE is used on Windows, port names are as follows:
- 19 -
Additional setup
In order to use D1 Mini Pro with Arduino IDE, follow few easy steps. Before
setting the Arduino IDE, the driver for the USB to Serial communication has
to be installed. If the driver is not installed automatically, there is a support
page that contains the drivers for Windows/Mac or Linux and can be chosen
depending on which one is used. Drivers can be downloaded from the
following link.
Next, to install support for the ESP8266 platform, open Arduino IDE and go
to: File > Preferences, and find Additional URLs field.
- 20 -
Paste this link in the Additional URLs field. If one or more links are inside
this field, just add one comma after the last link, paste new link after comma
and click the OK button.
To upload the sketch code to the D1 Mini Pro, first select port to which the
board is connected. Go to: Tools > Port > {port name}
- 21 -
Sketch examples
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
digitalWrite(LED_BUILTIN, LOW); // Active LOW turns the LED ON
delay(1000);
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
}
- 22 -
Software PWM sketch example
void setup() {
}
void loop() {
// increase the LED brightness
for (int dutyCycle = 0; dutyCycle < 1023; dutyCycle++) {
// changing the LED brightness with PWM
analogWrite(LED_BUILTIN, dutyCycle);
delay(2);
}
- 23 -
Serial communication sketch example
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println("D1 Mini Pro Serial Communication");
delay(1000);
}
Upload the sketch to the D1 Mini Pro module and open the Serial Monitor
(Tools > Serial Monitor). The result should look like the on the following
image:
- 24 -
Now it is the time to learn and make your own projects. You can do that with
the help of many example scripts and other tutorials, which can be found on
the Internet.
https://az-delivery.de
Have Fun!
Impressum
https://az-delivery.de/pages/about-us
- 25 -