pi2wifi
A WIFI ADAPTER FOR THE PI ZERO THAT DOESN'T USE THE USB PORT
First, I want to give well-earned credit to this wonderful project. (Read through it, it's very informative.) I'm truly standing on the shoulders of giants here: all I've done is make it as small as possible, leveraging my technique of using resistors to attach a circuit board to the Pi Zero like I did here. I guess it's kind of a reductionist thing. The result is a somewhat slow WiFi adapter for the Pi Zero for under $5.
Here's the schematic. The connection from test point P1-EN to the ESP module EN pin isn't shown. Also not shown are 33 ohm series resistors between P2 and the Pi Zero, on all but P2-17, 30, and 34, which are directly connected. Pretty simple isn't it?
DOING THE WORK
I spent an afternoon designing the board, and sent it off to OSH Park. I was somewhat anxious: I'd never done a cutout before, and the cutout had to be made oversize since it had rounded edges. I also had to make a footprint for the ESP, so I didn't know if it was accurate. I didn't know if my power and ground traces were large enough. I was worried about cross-talk in the data lines since there wasn't enought room for a ground plane. And I'd never lap-soldered a module before: could I make the necessary low-resistance connections by hand? So many worries.
As for software, the original kernel module source only needed some small changes. I changed the reset GPIO since I didn't want to fiddle with module parameters. I added a few lines of code to both the source and the overlay so the overlay would auto-load the module. I changed a couple of makefiles so the module would compile in-tree. After a quick compile, I had a shiny new kernel module!
IT'S SO SIMPLE IT CAN'T FAIL, RIGHT?
While I was waiting for my boards, I built a prototype by soldering short resistors from the ESP to a salvaged IDE connector like this:
I triple checked everything, installed the config files, booted up, and loaded the kernel module. Woo, no smoke! But it didn't actually work. Kernel messages stated that the ESP wasn't resetting. After looking at the source code, it became apparent that it was assumed that the reset line had a pull-up. To do a reset, the code simply set the GPIO as an output with value 0, waited a bit, then freed the GPIO, relying on the pull-up to bring the pin to a logic 1. Of course the GPIO I had selected for reset had a default pull-down. I fixed this by changing the overlay to enable a pull-up on the reset GPIO, compiled the overlay and rebooted.
It was still dead as a doornail. (What is a doornail, anyway?) It was time for the mighty oscilloscope, so I hauled it out and connected it up. I checked the SDIO clock: it seemed to be working. While probing the SDIO data lines, one of the resistors came loose from the ESP because of the probe strain. Then I noticed that one of the other resistors had also come loose: I had cold solder joints! This hadn't happened to me for a long time, so I wasn't expecting it. It was probably caused by the pads on the end of the ESP being so small: they're only designed for lap soldering, not wires. I re-soldered the end connections with plenty of flux and solder, and re-booted.
And it worked! The kernel module loaded, and I could do an iwlist scan. It even picked up my settings from the previously installed USB WiFi dongle, and connected to my access point.
When I received the circuit boards I de-soldered the module from the connector and soldered it to the circuit board. It fit extremely well: the cutout and footprint were perfect. On power-up everything worked flawlessly. I had worried for naught!
Here's what it looked like. The assembly is barely bigger than the Zero:
This edge view shows how thin the assembly is:
BENCHMARKING
It was time for a speed test! I compiled the netio tool, set up a server, and did a test. I was getting better than 3 megabits per second. I tested a USB dongle in another Pi, at the same location, and I got just over 10 megabits per second. So it was running at about one-third speed. This doesn't look very good at first glance, but it's actually pretty remarkable considering how close the ESP module's antenna is to the Pi Zero's ground plane and grounded USB connector shell. Lifting the assembly above the Zero would undoubtedly improve this, but I wanted the lowest profile possible. And 3 megabits per second is still better than the broadband connection feeding my access point.
LESSONS LEARNED
Sometimes you should trust your design tools and wait for the circuit board. Or maybe use a proper breakout with easy-to-solder pads?
When switching GPIOs around, pay attention to pull-ups/pull-downs. The code may rely on default values.
Metal close to small WiFi antennas does slow things down, but not so much as to be useless.
PARTS AND TOOLS
Order your boards from OSH Park. One order will get you three boards for $2.25, shipping included.
7 each 33 ohm 1/8W resistors for each board you're building. You can order 50 from DigiKey for under two dollars, exclusive of shipping.
24 gauge solid wire, three 25 mm pieces per board. I find the floors of comms closets are a good source!
40mm piece of small diameter insulated wire, 30 gauge wire wrap wire is perfect.
One ESP-12F module for each board. Here is a supplier that's worked for me in the past: currently a bit over $3 each, shipping included.
A block of urethane or similar foam, at least 25mm thick and at least 50mm square.
Hot glue gun, Blue Tack, or clay. Chewing gum might also work!
Flush wire cutter or even a fingernail clipper.
Tool or some way to strip the insulated wire.
Soldering stuff.
ASSEMBLY
Break any remaining tabs off of the circuit board. Sand the broken edges smooth if you're a perfectionist (like me).
Lay the ESP-12F face down on the circuit board, align the traces, and solder it down. Use flux if you have it.
Strip the ends and solder the insulated wire from the EN pin on the ESP module to the pad right below the gear symbol on the circuit board.
Trim the resistor lead lengths to 20-25mm.
Lay a Pi Zero on the foam, component side up.
Stab resistors through the Zero all the way into the foam, in GPIO holes 13, 15, 16, 18, 22, 35, and 37.
Tease the free ends of the resistors into the proper holes in the circuit board and push the board all the way down until it sits on top of the resistors.
Use hot glue or whatever to prop up the ESP end of the board and hold it in place while soldering.
Stab the solid wire pieces into the remaining three holes and into the foam, until they only protrude a bit above the circuit board.
Solder the resistors and wires to the circuit board and trim the ends.
Pull the assembly out of the foam, solder the resistors and wires to the Pi, and trim the ends.
Remove the glue or whatever you used. If you used hot glue, the bond can be easily broken by applying Isopropyl Alcohol.
Clean up any flux residue.
QUICK SOFTWARE SETUP
Download the 2016-11-25 Raspbian image and copy it to a fresh SD card.
Download from the files sub-page esp8089.ko, config.txt, and esp8089.dtbo, and copy them to the SD card's FAT32 partition.
Boot the imaged SD card in the Pi and do the usual initial configuration.
Reboot and log in.
Move /boot/esp8089.dtbo to /boot/overlays.
Move /boot/esp8089.ko to /lib/modules/4.4.34+.
Run the command sudo depmod.
Reboot and the WiFi adapter should work! Of course you need to configure which access point to use, and a password if needed.
HARDER SOFTWARE SETUP (FOR EXPERTS)
Compile the kernel module for the kernel you're running. The source is in the esp8089.tgz file.
Copy the compiled kernel module to the proper modules directory and run depmod.
Copy the esp8089.dtbo file to /boot/overlays.
Add dtoverlay=esp8089,poll_once=off to the /boot/config.txt file.
Reboot.
TROUBLESHOOTING
Use dmesg and lsmod to see if the driver loaded. If it didn't, either your ESP-12F is bad, there is a bad solder joint, there is a problem with your config or overlay, or the module version doesn't match the kernel version.
IMPROVEMENTS
Flipping the ESP over to the other edge of the circuit board will probably increase speed, at the expense of a larger system footprint. Of course this will mean a re-design of the circuit board, but at least it shouldn't markedly increase cost.
This site has been tested to display correctly using Gnome Web on the Raspberry Pi.