AT Setup & Test

The AT Command firmware is no longer actively supported - we moved to the ESP+SPI solution for a better experience and more security. However, this code does work and there may be some community improvements

OK once that is done, you can finally use your freshly-programmed module to connect to the 'net. You can remove miniesptool and the firmware files from your Express' CIRCUITPY drive..

Download and install the ESP AT control library onto your CircuitPython board.

Since there are many steps, it's best to run full examples by saving them to code.py on your board rather than interacting with the REPL. That said, you really want to have a serial connection open to see what's going on.

ESP Wiring

We'll be using a Feather M4 to demonstrate. Wire up the ESP8266 module as shown:

  • VBat from ESP8266 to VBat on Feather M4 (if your board doesn't have a Battery power pin, skip this)
  • Vin from ESP8266 to VUSB on Feather M4 - use whatever 5V (no higher!) power source you have
  • GND to GND
  • ESP8266 Reset to D5 (you can use any pin)
  • ESP8266 RX to UART TX
  • ESP8266 TX to UART RX
  • ESP8266 GPIO13 to D6 (you can use any pin)  (NOT shown on fritzing diagram -- yet..)

Note the UART pins are 'cross wired' - RX to TX. We don't use GPIO 0 but if you want you can keep it connected so that you can go back and upload firmware if you need.

Test wiring & WiFi with AP Scan

Create a secrets.py file containing settings for your local WiFi router. See the example template below. Change the values to match the name of your wireless network and its password. Copy this file to your CIRCUITPY drive.

There are several examples in the GitHub repo for the library, available here.

It is suggested you start with the esp_atcontrol_simpletest.py program. Save the example below to your board as code.py or save it by another name and execute it manually at the REPL.

Download: file
# secrets.py

secrets = {
    "ssid" : "MY SSID",
    "password" : "MY PASSWORD"
}
import time
import board
import busio
from digitalio import DigitalInOut
from adafruit_espatcontrol import adafruit_espatcontrol



# Get wifi details and more from a secrets.py file
try:
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise

# With a Metro or Feather M4
uart = busio.UART(board.TX, board.RX, timeout=0.1)
resetpin = DigitalInOut(board.D5)
rtspin = DigitalInOut(board.D6)

# With a Particle Argon
"""
RX = board.ESP_TX
TX = board.ESP_RX
resetpin = DigitalInOut(board.ESP_WIFI_EN)
rtspin = DigitalInOut(board.ESP_CTS)
uart = busio.UART(TX, RX, timeout=0.1)
esp_boot = DigitalInOut(board.ESP_BOOT_MODE)
from digitalio import Direction
esp_boot.direction = Direction.OUTPUT
esp_boot.value = True
"""


print("ESP AT commands")
esp = adafruit_espatcontrol.ESP_ATcontrol(uart, 115200,
                                          reset_pin=resetpin, rts_pin=rtspin, debug=False)
print("Resetting ESP module")
esp.hard_reset()

first_pass = True
while True:
    try:
        if first_pass :
            print("Scanning for AP's")
            for ap in esp.scan_APs():
                print(ap)
            print("Checking connection...")
            # secrets dictionary must contain 'ssid' and 'password' at a minimum
            print("Connecting...")
            esp.connect(secrets)
            print("Connected to AT software version ", esp.version)
            print("IP address ", esp.local_ip)
            first_pass = False
        print("Pinging 8.8.8.8...", end="")
        print(esp.ping("8.8.8.8"))
        time.sleep(10)
    except (ValueError,RuntimeError, adafruit_espatcontrol.OKError) as e:
        print("Failed to get data, retrying\n", e)
        print("Resetting ESP module")
        esp.hard_reset()
        continue

If you did not set the SSID/password in your secrets.py file you will get an error on connection

Update those lines and try again! On success the connection will be reported  and the program will Ping IP address (8.8.8.8) every 30 seconds

This guide was first published on Dec 16, 2018. It was last updated on Dec 16, 2018. This page (AT Setup & Test) was last updated on Sep 23, 2019.