WiFi and the Raspberry Pi

How to Install the AT Command Firmware

It was tricky to find the AT command firmware and install it on the ESP8266 Huzzah board. However, the drivers for the Huzzah (AI-Thinker module) can be found online [5]. I'm using the 0.9.5.2 firmware.

First, you should get rid of the spaces in the file name. Second, download and install the esptool.py package to get ready to flash the ESP8266 [6]. You can install the software with the command

git clone https://github.com\
  /themadinventor/esptool.git

and then use the following esptool.py command. Note that your USB port name will be different. If you are on the Raspberry Pi using an FTDI cable, it will probably be /dev/ttyUSB0/.

You also need to install a serial terminal such as Minicom [7] or Picocom (my favorite) using the command:

apt-get install picocom

Use the following esptool.py command:

python ./esptool.py \
  --port /dev/tty.usbserial-A50482MX \
  write_flash 0x00000 v0.9.5.2ATFirmware.bin

Now you have the AT command set firmware in the ESP8266. Type the following command to test it:

picocom --baud 115200 /dev/ttyUSB0

Type AT then Enter-Ctrl+J, and you will get an OK.

Testing the AT Command Setup

Put the code shown in Listing 1 into a Python file, and give it the name testSerialESP8266.py.

Listing 1

testSerialESP8266.py

01 import serial, sys
02 import time
03
04 # Modified from http://www.instructables.com/id/
   Easy-ESP8266-WiFi-Debugging-with-Python/step2/Software/
05
06 def enum(**enums):
07     return type('Enum', (), enums)
08
09 Status = enum(ERR='ERROR', OK=['OK', 'ready', 'no change'], BUSY='busy')
10
11 def send_cmd( sCmd, waitTm=1, retry=5 ):
12         lp = 0
13         ret = ""
14
15         print"Sending command: %s" % sCmd
16
17         for i in range(retry):
18                 ser.flushInput()
19                 ser.write( sCmd + "\r\n" )
20                 ret = ser.readline()    # Eat echo of command.
21                 time.sleep( 0.2 )
22                 while( lp < waitTm or 'busy' in ret):
23                         while( ser.inWaiting() ):
24                                 ret = ser.readline().strip
                                    ( "\r\n" )
25
26                                 lp = 0
27                         if( ret in Status.OK ): break
28                         #if( ret == 'ready' ): break
29                         if( ret == Status.ERR ): break
30                         time.sleep( 1 )
31                         lp += 1
32
33                 time.sleep(1)
34                 if( ret in Status.OK ): break
35
36         print( "Command result: %s" % ret )
37         return ret
38
39 port = "/dev/ttyUSB0"
40
41 speed = 115200
42 #ssid = "yourSSID"
43 #pwd = "yourPASSWORD"
44
45 ser = serial.Serial(port,speed)
46 if ser.isOpen():
47     ser.close()
48 ser.open()
49 ser.isOpen()
50
51 send_cmd("AT")

In the esp8266 directory, the command

$ sudo python testSerialESP8266.py
Sending command: AT
Command result: OK
$

runs the program and shows the results.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content