Thursday, 4 February 2016

Getting started with the Pimoroni ESP8266 IOT pHAT


The ESP8266 pHAT from Pimoroni for adding wifi to your Raspberry Pi projects.  Here's a brief 'quick-start guide'. If you're going to use the pHAT on a Pi Zero, it can be easier to do the config on a full-size Pi then just transfer the pHAT and SD card when you're all done.


1. Start with a fresh install of Jessie

2. sudo apt-get update

3. sudo apt-get upgrade

4. sudo apt-get install minicom

5. We need to stop the Pi using the Serial port for console messages. Edit /boot/cmdline.txt to remove 'console=ttyAMA0' from the line. You should be left with:

dwc_otg.lpm_enable=0  console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

6. sudo raspi-config. Go to Advanced Options => Serial and set it to disabled.

7. Shutdown the Pi

8. Solder the header onto the pHAT. Attach to the Pi and power up.

9. Now we can connect to the ESP8266 via a serial connection. Run minicom -b 115200 -o -D /dev/ttyAMA0


10. To test, type

AT

and hit enter/return as normal. Then type ctrl+j 

You should see the reply OK


11. Now you can start putting the ESP8266 to work. There's a useful list of AT commands here, but to get started try:

AT+CWMODE=1
AT+CWLAP

which will list all the wifi Access Points that it can see.


12. To connect to one:

AT+CWJAP="SSID","password"



Obviously replace SSID and password of the network you're trying to connect to!

13. Then find your IP address

AT+CIFSR



To disconnect for the AP, type

AT+CWQAP

Don't forget the ctrl-j after each command. 

To quit minicom, type ctrl+a then q

14 As a more advanced test, you can set up your Pi as a simple web server.  Download this really useful python code:


 git clone https://github.com/guyz/pyesp8266.git

Then change into that directory and run the server code

python esp8266server.py /dev/ttyAMA0 115200 "SSID" "password"

You should see a whole bunch of familiar AT commands being executed. When everything has finished, fire up your web browser and connect to the IP address just allocated to your PI/ESP8266.

You should see the system date displayed:


Once you're finished developing, transfer everything over to your Pi Zero.



  

12 comments:

  1. The following forum posts explains how to set minicom to send the linefeed (ctrl-j)

    Basically press ctrl-a, z, then a

    http://arstechnica.com/civis/viewtopic.php?f=20&t=566236

    ReplyDelete
  2. I dropped minicom long time ago for screen:

    screen /dev/ttyUSB0 115200

    It made my life way simpler.

    ReplyDelete
  3. Great guide. I have followed all steps and everything works until I try the example server code, connection to my WiFi router completes but when I try and browser to the IP address nothing is returned (browser times-out).

    ReplyDelete
  4. Great post Richard. It inspired me to continue your work and write a post on how to flash the firmware on the pHAT:

    http://paulbyford.blogspot.co.uk/2016/03/updating-firmware-on-pimoroni-esp8266.html

    ReplyDelete
  5. after I typed "AT+CWMODE=1" the esp8266 disappeared from my wifi devices and all i get is error messages from minicom. I do not know what happened. Is there any way to reset it? It is now not getting recognized by any of my Pi's.

    ReplyDelete
  6. I get nothing. I followed the instructions and when I get to minicom, it comes up and I get nothing but help screens and other things pop up, no communication though. I went to the update firmware page and the reset.py script causes lights on the esp8266 but I get no indication of any kind in minicom. Across the bottom of minicom is 115200 8n1 | vt102 | offline | ttyAMA0

    ReplyDelete