Start Back Next End
  
ZBasic System Library
ZBasic Microcontrollers
2
This simple application outputs the "Hello, world!" message on UART0 every second and also
toggles the specified pin, in this case A.2 which is GPIO2 on the ESP8266.  Notice, particularly, that the
Main() routine is a straight line of execution that performs some simple operations and then invokes the
Sleep() routine for 1 millisecond. before returning.  The 1 second timing is achieved by counting the
number of times that Main() is invoked and outputting the message on one in a thousand passes.  This
simple application could be expanded to perform various other operations on any of the other 999
passes.
Note, also, the use of the compiler directive Option UserPostInit, which is specific to the ESP8266,
to specify an initialization routine.  In this particular application the initialization could just as well have
been omitted but it was included to demonstrate how that is done.
Building an application for the ESP8266 using the ZBasic IDE is essentially the same as for any other
ZBasic target.  The target device is selected using  "Device Options" dialog, available via the
"Options|Device Options..." menu item.  If the ESP8266 target is not already present in the Target Device
dropdown, it can be added by clicking the "Edit Target List..." button.  In the resulting dialog, two lists are
presented: one with devices that are to be shown in the Target Device dropdown (on the previous dialog)
and one with devices that are to be omitted.  One or more devices can be moved from one list to the
other by selecting the device of interest and then clicking one of the "arrow" buttons appearing between
the list to effect the move in one direction or the other.
A subsequent section of this document describes the process of downloading the application to the
ESP8266.
ESP8266 Pin Mapping
ESP8266 devices are available in many different forms including the ESP-01 and the ESP-12.  Each of
the available devices has a different set of pins available, different size of Flash memory, etc.  ZBasic
doesn't have an awareness of the different forms of the ESP8266.  Rather, it is up to you as the
application programmer to write the application with the capabilities of your target device in mind.
The ESP chip itself has 17 I/O pins denoted as GPIO0 through GPIO16.  The I/O pins can be referred to
by their ordinal numbers 1 through 17.  Additionally, GPIO0 through GPIO15 may be referred to as A.0
through A.15 and GPIO16 may be referred to as B.0.  On most ESP8266 boards, GPIO6 through GPIO11
are dedicated for controlling the serial Flash chip and are, therefore, not available to applications.  This
information, and other details, are summarized in the table below. The shaded rows indicate pins that are
generally not available to an ESP8266 application.
ESP8266 Pin Naming and Special Functions 
GPIO Pin
ZBasic Name
Special Functions
GPIO0
A.0 or 1
Boot signal
GPIO1
A.1 or 2
UART0 TxD
GPIO2
A.2 or 3
UART1 TxD
GPIO3
A.3 or 4
UART0 RxD
GPIO4
A.4 or 5
GPIO5
A.5 or 6
GPIO6
A.6 or 7
Flash control - SCK
GPIO7
A.7 or 8
Flash control - D0
GPIO8
A.8 or 9
Flash control - D1
GPIO9
A.9 or 10
Flash control - D2
GPIO10
A.10 or 11
Flash control - D3
GPIO11
A.11 or 12
Flash control - CS
GPIO12
A.12 or 13
GPIO13
A.13 or 14
GPIO14
A.14 or 15
GPIO15
A.15 or 16
GPIO16
B.0 or 17
Previous page Top Next page