官术网_书友最值得收藏!

Connecting the Raspberry Pi Zero W to a laptop via Wi-Fi

When the Raspberry Pi Zero first came out in 2015, it didn't have a built-in Wi-Fi module, which made it difficult to connect to the internet. Some Raspberry Pi developers came up with useful hacks to connect the Raspberry Pi to the internet and some companies also created Ethernet and Wi-Fi modules for the Raspberry Pi Zero.

In 2017, however, the Raspberry Pi Zero W was launched. This had a built-in Wi-Fi module, which meant that Raspberry Pi developers no longer needed to perform any DIY hacks or purchase a separate component to add internet connectivity. Having built-in Wi-Fi also helps us to wirelessly connect the Raspberry Pi Zero W to a laptop. Let's take a look at how this can be done.

The process of connecting Raspberry Pi Zero W to a laptop's Wi-Fi is similar to that of Raspberry Pi 3B+. Since the Raspberry Pi Zero W does not have an Ethernet port, however, we will have to write a few lines of code inside the cmdline.txt and config.txt files. 

Even though cmdline.txt and config.txt are text (TXT) files, the code in these files does not open properly inside Microsoft's Notepad software. To edit these files, we will need to use code editor software, such as Notepad++ (only available for Windows) or Brackets (available for Linux and macOS).

After installing either of these, let's customize the microSD card as follows:

  1. In the Raspberry Pi Zero W, we also need to create an SSH file on the microSD card. For instructions on how to create an SSH file on the microSD card, refer to the section, Creating an SSH file on a microSD card.
  2. After creating an SSH file, right-click on the config.txt file and open it in Notepad++ or Brackets. In this case, we will open it in Notepad++:

Scroll all the way down to the bottom of this code and add the line dtoverlay=dwc2 at the end. After adding the code,  save and close the file. 

  1. Next, open the cmdline.txt file inside Notepad++. The entire code inside the cmdline file will be displayed on one line. Next, make sure that you add only one space between the word consoles and the word modules

Enter the line modules-load=dwc2,g_ether at the end next to the plymouth.ignore-serial-consoles code:  

  1. Next, connect the Raspberry Pi Zero W to your laptop using a data transfer USB cable. Connect the USB cable to the data port of the Raspberry Pi Zero W, and not the power port:
  1. Make sure that the USB cable that you are connecting to the Raspberry Pi Zero W and the laptop supports data transfer. For example, take a look at the following photograph:

In the preceding photo, there are two similar, but importantly different, cables:

    • The small USB cable on the left was included with my power bank kit. This USB cable supplies power but does not support data transfer.
    • The USB cables on the right were included with the purchase of a new Android smartphone. These do support data transfer.

A simple way to check whether your USB supports data transfer or not is to connect it to your smartphone and laptop. If your smartphone is detected, this means that your USB cable does support data transfer. If not, you will need to purchase a USB cable that supports data transfer. The following screenshot shows a smartphone being detected by a PC, meaning that the cable in use is a data cable:

If your USB cable is detected but loses connection frequently, I recommend that you purchase a new USB cable. Sometimes, older USB cables do not work properly because of wear and tear. 
主站蜘蛛池模板: 新邵县| 卓资县| 漳州市| 孝感市| 苍梧县| 连江县| 静安区| 柞水县| 丁青县| 诸城市| 滦南县| 江安县| 兰溪市| 温泉县| 衡东县| 玛沁县| 平原县| 拉萨市| 九江县| 合川市| 卓资县| 南昌市| 长葛市| 筠连县| 易门县| 江油市| 湛江市| 彭山县| 渝中区| 宝鸡市| 城步| 鹿泉市| 航空| 丹阳市| 额尔古纳市| 琼结县| 祥云县| 韶关市| 安福县| 定兴县| 宿州市|