WiFi adapter for ATMega computer

Hardware

After some first projects with the ESP8266 (add WiFi to a cheap Roomba cleaning robot, virtual wall for the Roomba), I decided that my ATMega based home computer should get a connection to the outside world. So I built this cheap WiFi adapter using the ESP8266. Communication between the ATMega and the ESP8266 is realized using the SPI interface. Because SPI is also used by the home computer to communicate with the SD Card, the ATMega has to be the SPI master. For the Chip Select Signal I chose pin PD1 of the ATMega (not used up to now). A Logic Level Converter is needed to do the level shifting (5V for ATMega signals, 3.3 V for ESP8266 signals). Up to now I use the NodeMCU V3 development board.

At startup of the ATMega home computer the SPI interface for the ESP8266 is deactivated (PD1 high). On the other hand, if the ESP is booting while the select line of the master is high, the ESP8266 will fail to boot (see note in the SPISlave class). It is therefore necessary to boot the ESP8266 *before* the home computer is switched on or to activate the SPI interface before booting the ESP8266 using the ATMega home computer command spilo. In this case, after the ESP8266 has booted, the ATMega home computer command spihi must be executed to deactivate the SPI interface again.

Software

This time I used the Arduino Development Environment to program the ESP8266.

The most useful feature of having access to the WLAN from the home computer is the exchange of files (exchange of files using the SD card can be tedious during development of a program). So I decided to install an FTP server on the ESP8266. Additionally, I wrote a simple telnet client for the home computer.

The class SimpleTelnetClient handles the negotiation with the server and sends resp. receives messages from the server to the home computer resp. from the home computer to the server.

Fortunately there is already a FTP server class available: https://github.com/gallegojm/Arduino-Ftp-Server/tree/master/FtpServer. This class writes directly to the internal flash storage of the ESP8266 using the FatFs library. I adapted this class by simply replacing the FatFs calls with corresponding calls of my "file abstraction class" R162ESPSPI (and marking a lot of "less important" FTP commands as "not supported").

The class R162ESPSPI on its part uses the SPISlave class ( https://github.com/esp8266/Arduino/tree/master/libraries/SPISlave ) for the communication between ATMega (master) and ESP8266 (slave).

The class SPISlave (running on ESP8266) communicates with the program ftpsrv resp. telnet running on the "ATMega based home computer" (written in 6502 assembler code).

A set of "functions" (open, close, read, write, writeconsole, checkRC, getRCData etc.) are made available to the ESP8266 by implementing a "high level" SPI communication protocol (the purpose of the R162ESPSPI class).

The SPISlave class provides methods to send / receive 4 bytes (setStatus(), onStatus()) resp. 32 bytes (setData(), onData()) in one call. The methods onStatusSent() and onDataSent() are called after the master has read the sent message.

The following table shows the "high level" SPI communication protocol for the provided "functions".

Actually primarily the ftp commands put and get are provided by the server. Additionally it is possible to activate / deactivate logging on the home computer by invoking the command quote SITE R162LOG.