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

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. 
主站蜘蛛池模板: 县级市| 阳泉市| 柳州市| 五莲县| 福州市| 五大连池市| 铅山县| 综艺| 金溪县| 府谷县| 靖西县| 陆丰市| 镶黄旗| 贵州省| 广昌县| 铜梁县| 肃北| 潜山县| 平昌县| 台东县| 江山市| 罗田县| 大姚县| 汉川市| 巴东县| 伽师县| 忻州市| 谷城县| 岑溪市| 焉耆| 无为县| 宁德市| 吉安市| 都昌县| 临朐县| 永城市| 松潘县| 沂水县| 贵定县| 泸西县| 贵港市|