ESP8266-01

From SpecNext official Wiki
Revision as of 15:06, 30 April 2019 by Daz (talk | contribs)
Jump to: navigation, search

A Wi-Fi module and Real Time Clock (RTC) were optional additions to the full cased Spectrum Next at the time of the original Kickstarter. They can be added to development boards and units that don't already have them. Although the RTC requires soldering components to the board, but the Wi-Fi module is a push-fit component.

Hardware Requirements

Adding Wi-Fi to a board requires only a ESP8266 ESP-01 module. This supports 802.11 b/g/n at 2.5 Ghz including the WPA and WPA2 security protocols. The mounting point for the module is just behind the VGA port.

ESP modules have an updatable firmware. In general the standard firmware, should work out of the box with the Spectrum Next. If you're buying a module, check it has a standard firmware.

The Wi-Fi makes use of the on-board UART (Universal Asynchronous Receiver-Transmitter) of the Spectrum Next (you can use this without a WiFi module for serial connections as as well.) The UART on the Next board (built inside the FPGA logic) can control the RX/TX lines from 2400 bps up to 115200 bps (the default speed). The ESP module uses the "AT instruction set" of a typical modem and the official PDF is available here: https://www.espressif.com/sites/default/files/documentation/4a-esp8266_at_instruction_set_en.pdf

Software Support

This information relates to TBBlue SD Distribution 2.00.26 and later (2019-01-27).

The distribution contains dot commands (including "UART") and the "TERMINALS.BAS" program for working with the Wi-Fi module.

.UART is a simple DOT command that works in NextZXOS (and ESXDOS) to allow you to talk to a connected device which could be a Wi-Fi module. Due to the limitations of the 512 byte hardware buffer ,it can only be used for small amounts of data and is mainly intended to allow diagnosis. It does include a simple CIPSEND mode that allows connections to be made with an ESP Wi-Fi module.

UART.DRV is an interrupt driven driver (NextZXOS only) which can provide a 16K software buffer which means much less incoming data is lost. There is both a simple demo IUDEMO and a terminal program (not a DOT command) that provides an alternative to .UART that can handle much more data. This is intended for users of the port without the Wi-Fi module really but can be used to setup the ESP.

The TERMINAL.BAS program is much better than .UART and you will have better results following through some of the examples below.

You can also begin to play with the real feature of the Internet Toolbox which is the ESPAT driver for BASIC (again NextZXOS only). It can be used with the BASIC ESPTERM program to chat over an IP link and the ESPHTTP sample program shows how a web page can be retrieved from BASIC (but not rendered.)

The Source code to the IRQ stub is provided to allow the ESPAT code to be used in games that take over the machine, providing a gaming API.

Be sure to check out NXTel the Viewdata (Prestel/Teletext) terminal that allows the Next to connect and get news pages from Viewdata servers already online.

.UART

Key mapping

Spectrum key PS/2 Key Action
EDIT SHIFT+1 Cycle output mode
CAPS LOCK SHIFT+2 On/off toggle (on by default)
TRUE VIDEO SHIFT+3 Debug mode for CIPSEND on/off (silent)
INV VIDEO SHIFT+4 CIPSEND mode on/off, also does an ATE0
GRAPHICS SHIFT+9 Change BAUD rate
DELETE SHIFT+0
Exit Program Symbol Shift and Space together.

Basic Connection

Run the .UART command, or better LOAD "TERMINAL.BAS" and RUN it.

First of all when you press ENTER you should get 'ERROR' because you didn't send a valid command to the ESP module. If you don't then it may be a number of things:

  • You are using the TBU and firmware BEFORE 0.8 and NextOS 1.92 - if so this will only work at 3.5Mhz so slow the machine down and restart .UART.
  • You are using a TBU and firmware with a Core .29 or greater, with an OLD copy of the .UART program which wrote the BAUD rate differently - if so when you cycle through the speeds (EDIT/SHIFT+1) you will find it may 'work' at 38400 - it is actually a fluke as the old value for that rate is quite close to the value needed for 115200 on the new system.
  • Your module may have come with a default baud rate other than the 115200 of the Next. Using GRAPHICS (SHIFT+9) you can cycle through each option pressing ENTER until you see "ERROR!" (If you can physically see the module then many have a little blue light that flashes when receiving.)

Once you have that you should be able to type 'AT' and press ENTER. That should give "OK".

Probably the first thing you want to do is tell the module to use the default speed of the next so type:

AT+UART=115200,8,1,0,0 

and press ENTER.

You now need to use GRAPHICS (SHIFT+9) to go back around to 115200 so that ENTER gives ERROR and AT ENTER gives OK again....

We just used one of the AT commands:

AT+UART=<baudrate>,<databits>,<stopbits>,<parity>,<flow control>

Getting on the Network

Now to connect to a Wi-Fi access point:

First let's check that the system is in STAtion mode:

AT+CWMODE=?  

This will give 1,2 or 3 (where STA=1, AP=2, Both=3). Mode 1 or 3 is fine but, more config is needed in mode 2.

Set the mode:

AT+CWMODE=1

List Access Points:

AT+CWLAP

To join an Access Point:

AT+CWJAP="wifinetwork","password"

Note that the module will retain the Wi-Fi connection and you can just do an AT+RST which will reset the module and give a CONNECTED and GOT IP.

Here are some more common AT commands:

AT+CIFSR Echo the current IP address on the network
AT+GMR Echo the current versions of the software on your module
AT+CWQAP Forget the WiFi network and password



Other Hardware

In addition to controlling the ESP-01 Wi-Fi module, the .UART command also provides facilities to use the serial connection port, either directly through some form of serial converter (e.g. a USB to TTL serial) or standard RS232 module (probably based on the MAX232).

A USB serial connection allows you to do all sorts of clever things - it is possible to connect up to a PC like this for transferring data. In fact if you were an early purchaser you probably bought one with your ESP-01 as it is the one needed to program it.

If you use one of the easy to get TTL modules then you can communicate with PC's and other older machines - E.g. a real Spectrum with Interface 1... KevB is using one for his PC - see article on the forum at https://www.specnext.com/forum/viewtopic.php?f=6&t=895

It should be possible just to hook up to an external Raspberry PI for example and use a serial console connection allowing you to use the ZX Next as the keyboard... as the voltages match it should be fine just to connect the UART RX/TX and GND to the PI's PIN's 4/5/6 GND/TXD0-GPIO14/RXD0-GPIO15. See https://elinux.org/RPi_Serial_Connection

There is a diagram of the GPIO header here: https://elinux.org/RPi_Low-level_peripherals

Be aware of the differences with a Pi 3.


Further Reading

For further information, see "The Next on the Network" at SpecNext.com and in the TBBlue Distribution the file "\docs\extra-hw\wifi\WIFIand UARTReadME1st.txt"