Introduction: Raspberry Pi Zero Wifi Access Point With a Custom PCB Antenna
What are we making?
The title of this tutorial has lots of technical terms in it. Let's break it down.
What is a Raspberry Pi Zero (Rπ0)? A Raspberry Pi Zero is a tiny computer. It is the smaller version of the Raspberry Pi single board computer, and it can fit in a 30mm by 65mm by 5mm box. In addition to its small size, it is very inexpensive and very low power. It is also powerful enough to run a full Linux based operating system, Raspbian. As with any other computer, you can use the Rπ0 to browse the web, play games, use office tools, write software, and so on. This tutorial uses the Raspberry Pi Zero Model W, which has a built in wifi adapter.
What is a wifi adapter? If you want to use wifi to connect your cellphone, tablet, or laptop to the internet, your device needs a wifi adapter. A wifi adapter contains circuitry and an antenna. It converts data signals to and from electromagnetic waves with frequency near, for example, 2.4 GHz. Most cellphones, tablets, and laptops contain a built in wifi adapter. However, you can also purchase an external wifi adapter which connects to a computer via USB. In this project, we use both the internal wifi adapter of the Rπ0 as well as an external wifi adapter.
What is a wifi access point? Multiple cellphones, tablets, or computers can communicate wirelessly with a single wifi access point, and data from these devices is transferred through the access point to the internet. In this project, the Rπ0 is the wifi access point. Why would you want your own wifi access point? Devices need to be within around 100 meters of an access point to communicate. Suppose there is a public wifi access point in the center of a library. Anyone with a laptop within that distance can use the access point to wirelessly get online. What if you want access in the park next to the library, 200 meters away? You can put a new access point at the edge of the library's property, 100 m from the first access point. Then, anyone with a laptop within 100 m of that new access point also can get online. Within limits of available bandwidth, these access points can be chained together to spread internet access over a wider area.
What is a custom Printed Circuit Board (PCB)? A PCB is a circuit constructed by depositing layers of material on an insulating board. Copper is patterned in desired locations to form wires, and holes are drilled where components will be placed. Custom PCBs are designed using specialized software. For this project, a custom PCB was designed using the open source KiCad software. The design was then sent to a manufacturer to be produced. Designing and ordering a custom PCB is neither expensive nor time consuming. The steps are detailed below. If you lay out a PCB using software and have it manufactured, you get a circuit that is durable, precisely manufactured, and designed to your exact specifications. In this project, we use a custom PCB to make a wifi antenna.
What is an antenna? The antenna is the part of the wifi access point hardware which converts signals to and from electromagnetic radiation. Many antennas can transmit and receive signals equally well from all directions. Other antennas are directional, operating much better along a particular direction. In this project, we chose to use a directional antenna. When a directional antenna transmits a signal, it focuses the energy in a particular direction so, all else equal, a well aligned directional antenna can communicate over a longer distance than one that is not directional. This Instructable was inspired by another Instructable that made a directional wifi antenna out of (literally) paperclips and popsicle sticks. That Instructable contained a pattern for a wifi Yagi antenna, and our antenna is made from that pattern with slight modifications. A Yagi antenna, also called Yagi-Uda antenna, is a type of directional antenna originally designed in 1926. Another great source of antenna designs, as well as other information about antennas, is the ARRL antenna book.
While some people access the internet multiple times a day, many other people lack reliable internet access. Lack of internet access is a problem both in rural and urban areas, and it is a problem in both developed and developing countries. For example, 23% of households in Wayne County Michigan, which includes Detroit, lacked internet access in 2017. Solutions to this problem need to be inexpensive because many of the people without computer access have limited resources. Additionally, solutions need to work without requiring infrastructure such as laying copper wire or fiber optic cables. In these instructions we show how to build your own wifi access point so you can extend internet yourself.
About this Tutorial
These instructions are modular. You can follow parts of these instructions without necessarily completing the parts before or after it. For example, if you are interested in using a Rπ0 as an access point but aren't too interested in antennas, feel free to use any wifi adapter and ignore the steps involving making the antenna. If you are interested in making a custom Yagi antenna, skip straight to that part of the tutorial. The PCB layout files for the antenna are included.
The step to install the wifi adapter and the step to set up the Rπ0 as an access point were tested using Raspbian Stretch 4.14.52 and 4.14.79. Hopefully they will continue to work with future versions. However, these steps may need to be modified if config files for wifi access change in newer versions of the operating system.
Step 1: Gather Supplies
Supplies needed for the Raspberry Pi Zero Setup
- Raspberry Pi Zero W
Make sure to get the model W which has built in wifi.
https://www.adafruit.com/product/3400 - Micro SD Card
Get one at least 16GB.
https://www.amazon.com/gp/product/B073JWXGNT - MicroSD Card Reader
https://www.amazon.com/IOGEAR-MicroSD-Reader-Write... - USB Hub with MicroUSB connector
https://www.amazon.com/gp/product/B01JL837X8/ - USB Keyboard and Mouse
https://www.amazon.com/d/Keyboard-Mouse-Combos/Log... - Mini-HDMI to HDMI cable
Make sure to get the Mini-HDMI, not Micro-HDMI, size.
https://www.amazon.com/AmazonBasics-High-Speed-Min... - HDMI compatible monitor
- Power Supply
You can use a USB battery pack instead.
https://www.adafruit.com/product/1995
Additional Supplies Needed for Setting up the Wifi Access Point
- Amazon Basics USB Wifi Adapter with Detachable Antenna
https://www.amazon.com/AmazonBasics-Wi-Fi-11N-USB-...
Additional Supplies Needed for the Custom PCB Antenna
- RG-58 Solderable Cable Connector
Digikey part number CONSMA007-R58-ND
https://www.digikey.com/products/en?keywords=CONS... - Custom Printed Circuit Board
- Soldering Iron and Small Amount of Solder
Step 2: Set Up the Raspberry Pi Zero
Download the Raspbian NOOBs Lite zip file from https://www.raspberrypi.org/downloads/noobs and unzip it.
Connect the MicroSD card to the computer using the MicroSD card reader. The MicroSD card should either be new or newly formatted. Copy the files onto the MicroSD Card.
The next step is to connect the Rπ0 hardware. Insert the MicroSD card into the Rπ0. Connect the USB hub to the Rπ0, and connect the keyboard and mouse to the USB hub. Connect the Rπ0 to the power supply, and plug it in. The Amazon Basics wifi adapter won't be used in this step, so leave it unconnected.
Follow the instructions in the wizard to install the Raspbian operating system onto the Rπ0. This step involves:
- Logging onto the established wifi network
- Installing Raspbian Full (Be patient, this takes a while.)
- Setting the country, time zone, and language
- Setting a password for user pi
- Connecting to the established wifi network
- Updating (Be patient, this takes a while.)
- Rebooting
At this point, we have a working Rπ0 computer running the Raspbian operating system. Click on the wifi icon in the upper right corner of the screen. It should show wlan0 connected to your established wifi network.
Step 3: Install the Wifi Adapter Driver
The Amazon Basics brand wifi adapter is great for antenna projects because the supplied antenna can be unscrewed so our antenna can be screwed on. Unfortunately, Raspbian doesn't recognize this wifi adapter. It is a Realtek 818b adapter with serial number 70F11C0531F8. According to https://www.raspberrypi.org/forums/viewtopic.php?..., the chip in it requires the RTL8192EU driver. The needed driver is available online from MrEngman.
To install the driver, plug the Amazon Basic wifi adapter into the USB hub, and open up a terminal. Enter the following commands on the command line:
sudo wget http://fars-robotics.net/install-wifi -O /usr/bin/install-wifi sudo chmod +x /usr/bin/install-wifi sudo install-wifi -h sudo install-wifi
Click on the wifi icon on the upper right of the screen.
It should show wlan0 and wlan1, and both should be connected to the established wifi network. At this point, you have a working Rπ0 computer running with two working wifi adapters, the internal one and the external Amazon Basics wifi adapter.
Step 4: Set Up the Rπ0 As an Access Point
The next step is to set up the Rπ0 to act as a wifi access point. At the end of this step, the external Amazon Basics wifi adapter will be called wlan1 by the Rπ0, and it will communicate with the established wifi network. The internal wifi adapter will be called wlan0 by the Rπ0, and devices such as cellphones, tablets, and laptops can to connect to the Rπ0 on the new wifi network. These cellphones, tablets, and laptops will be able to use this new wifi access point to communicate on the internet.
This Rπ0 can extend the range of an established wifi network. For example, suppose we want to connect a cellphone to the internet, but the cellphone is 200 m from the established wifi access point. The cellphone may not be able to communicate with established wifi access point so far away. However, we can place the Rπ0 with the new access point in the middle. The Rπ0 then can use the external wifi adapter to communicate with the established wifi network which is only 100 m away, and the Rπ0 can use the internal wifi adapter to communicate with the cellphone which is also only 100 m away.
Adafruit has an excellent tutorial on how to set up a Raspberry Pi as a wifi access point. The tutorial details the steps which include setting up the wifi access point, installing needed packages, editing config files, and starting services. However, the procedure has multiple steps, and the instructions need to be modified for our purposes. We are using a Rπ0 instead of the larger Raspberry Pi, and we are establishing a connection between two wireless access points instead of a wired and wireless access point. Additionally, further changes to config files are needed to successfully set up the access point.
We wrote a program to simplify the install process. The attached zip file contains the modified config files needed as well as a small C program which automates the setup of the access point. It is closely based on the Adafruit tutorial. This program backs up existing config files, copies in the new config files contained in the zip file, and completes the installation of the access point.
Some additional packages are needed before we can use the install script. Use the following commands to install the needed software.
sudo apt-get install hostapd isc-dhcp-server sudo apt-get install iptables-persistent
Download the attached zip file and save it in a new directory. Open a terminal and change to that directory. The next steps are to unzip the file and run the install script.
tar-xzvf insatll-rpiAP.tar.gz cd install-rpiAP sudo ./install-rpiAP.o
This program will prompt you to enter the name of the (established) wifi network and its password. It will set up a new access point named PI_AP with password Raspberry.
After the script is done, reboot the Rπ0. Now, if you click on the network icon on the upper right part of the screen, it says no wireless interfaces are found. Don't worry; they exist and are working. At this point, the original wifi network exists, and we have a new wifi network named Pi_AP. Take a cellphone or other device and try to connect to the new wifi access point. Open a web browser on the device to test the internet connection while using this new access point.
The following seven config files are modified by the installation program: /etc/dhcp/dhcpd.conf, /etc/default/isc-dhcp-server, /etc/network/interfaces, /etc/hostapd/hostapd.conf, /etc/default/hostapd, /etc/init.d/hostapd, and /etc/sysctl.conf. You may want to make additional modifications to these config files. The Adafruit tutorial mentioned above provides additional details. For example, modify the file /etc/hostapd/hostapd.conf if you want to change the name of your new access point or its password. If you want to connect multiple Rπ0 access points to your established network, each one needs a unique IP address. The installation process uses 192.168.42.1. The files /etc/dhcp/dhcpd.conf and /etc/network/interfaces will need to be modified. Additionally, you will need the command sudo ifconfig wlan0 192.168.zz.1 where zz is replaced by another integer. Also, this access point has been tested for IPv4 communication only. Additional modifications to the install procedure or the config files may be needed for both IPv4 and IPv6 communication on the access point.
Attachments
Step 5: Design the Antenna
Designing and making an antenna is easier than it sounds. Our approach was to start with a pattern, modify it, simulate it to ensure it still satisfies our needs, and then lay it out on a PCB. If you don't want to make your own antenna, use the one that comes with with the wifi adapter. Alternatively, if you want to make, but not design or simulate, your own antenna, we have attached our PCB layout files. However, read on if you are interested in antenna design, antenna simulation, or PCB layout. The antenna we use hasn't been optimized. The purpose here is to show how you can make your own antenna, not to show an ideal antenna.
We wanted a directional antenna that works at wifi frequencies. The Instructable we started with includes a detailed pattern for a directional Yagi antenna which can be made out of paperclips and popsicle sticks. We made only one modification. This antenna is 42 cm long and contains 15 conductive elements. We got rid of all but four of the elements so the antenna will be shorter.
Next, we simulated the antenna to ensure that it was still directional, even with fewer elements. EZNECby Roy Lewallen is an easy to use antenna simulation tool. We used the demo version of EZNEC 6.0. The first step to using this software is to describe the antenna. Click on the Wires button, and enter the location of the antenna elements. The size and location of these elements are detailed in the antenna pattern. Next, we set the frequency to 2.4 GHz for wifi signals, and we chose the ground type to be free space. The EZNEC file describing the antenna, WifiYagi.ez, is attached.
The output of the EZNEC simulation is shown below, and it verifies that the modified antenna is still directional. The left part of the figure shows the antenna. The black lines are the conductive elements, and the red circle on the second element is where the the wifi adapter connects. The right part of the figure is the 3D radiation pattern plot. The figure shows the relative strength of the signal at a fixed distance from a transmitting antenna at different angles. Since the plot is larger in x direction than in other directions, the antenna is directional. Most of the energy transmitted by the antenna will go in the x direction. If we orient this antenna properly, and assuming all else is equal, this antenna should be able to communicate over longer distances in the x direction than if we had not used a directional antenna.
The next step is to lay out the custom PCB. While the antenna pattern we started with is easy to construct, it is difficult to construct precisely. Printed circuit boards are manufactured more accurately, and they are more durable. We used the open source program KiCad. Our PCB layout files are attached, in wifi_pcb.tar.gz. To unzip the file, use the command:
tar -zxvf wifi_pcb.tar.gz
The steps to laying out the PCB are to:
- Open a new KiCad project.
- Go to the PCB Layout Editor.
- Select the Add Graphic Lines button and the Edge.Cuts layer, and define the perimeter of the PCB.
- Select the Add Graphic Lines button and the F.Cu layer, and draw the antenna elements in the front copper layer.
- Select the Add Vias button, and insert two holes where the wifi adapter will be connected.
- Select the Add Graphic Polygon button and the F. Mask layer, and draw a hole in the front solder mask so it won't cover the via holes. Repeat using the B.Mask layer to draw a hole in the back solder mask too.
- Add any additional marks or labels desired to the silkscreen layers.
- Select File then Plot to generate Gerber files.
Attachments
Step 6: Make the Antenna
We purchased PCBs made from our layout. Adafruit has a list of hobbyist-friendly PCB manufacturers. While we've tried a fewPCBmanufacturers, we really don't know which is best. The PCB shown was manufactured by Oshpark.
Once the PCB arrives, the next step is to solder on the RG-58 coax connector. The PCB has two via holes. The pin which comes with the connector is too short, so solder a small piece of wire into one of the via holes. Put a large dot of solder connecting the shell to the other via hole. You now have a directional Yagi wifi antenna made from a custom PCB.
Unplug the Amazon Basics wifi adapter. Unscrew the antenna that it came with, and screw on the new PCB antenna. Plug the wifi adapter back in to the USB hub. The project is now complete.