Xiaobian himself is a Python development engineer, I spent three days to organize a set of Python learning tutorials, from the most basic Python scripts to Web development, crawler, data analysis, data visualization, machine learning, etc., these materials can be “click” to get the friends who want

1, the preface

During this period, XIAobian saw something called Raspberry PI and found it very interesting after preliminary understanding, so he wanted to record the whole process.

2. What is raspberry pie

Raspberry Pi, short for RPi, (or RasPi/RPi for computer programming education) is a tiny computer the size of a credit card, based on Linux. With the launch of Windows 10 IoT, we’ll also be able to use raspberry PI running Windows.

Since its inception, by many computer enthusiasts and makers sought after, once a “party” hard to find. Although its appearance is “petite”, inside the “heart” is very powerful, video, audio and other functions are all, it can be said that the sparrow is small, all the five organs.

In my own words

In my words, raspberry PI is a mainframe. You can connect external monitor, keyboard and mouse, USB disk and other peripherals, because it is small in size, and there are many serial ports and external ports, you can directly call a lot of underlying hardware.

Models on the market

There are mostly third-generation B+ models on the market, and there are a lot of raspberry PI on Taobao. The price of pure motherboard (without any peripherals) is around 230+, which is a little expensive and beyond my budget. So I continue to look for cheap ones, and finally I found a raspberry PI with 100+.

Raspberry PI Zero W

Raspberry PI Zero W is a mini raspberry PI that is only 1/3 the size of the 3B +. When you actually get it, it’s super small and super cute. Here is my actual image so you can see how mini it really is.

As you can see, at the top is a plain black felt-tip pen, followed by a plug-and-play external wifi card, followed by a USB card reader, and at the bottom is today’s hero, the Zero W. It’s super small. There’s no. It’s a perfect illustration of the saying, “a sparrow may be small, but it has all the organs.”

The key parameters of the Zero W raspberry PI are as follows:

(1), BCM2835 processor, 1GHz main frequency, 512MB RAM

(2) BCM43438 WiFi/BT chip

(3), Micro-USB power interface

(4) micro-USB OTG interface

(5), miniHDMI port

(6), composite video and reset the extension interface

(7) Fragile CSI camera interface

(8) Micro-SD card for storing the operating system

(9) 40-PIN GPIO extension interface

(10), size: 65mm*30mm

With a CPU of 1 core and 512 MEgabytes of memory, you might think it can’t do anything, but it’s actually pretty good, so it’s a pretty small case for running a website.

More raspberry pie

For more raspberry PI models or tutorials you can go to the Raspberry PI Lab website, which has plenty of resources.

3. Raspberry PI Zero W installation system

1. Prepare

Here are some things you might want to prepare ahead of time:

(1) 16GB or 32GB SanDisk memory card

(2), a most common USB Android data cable (not Type-C)

(3) usb disk formatting tool (SDFormatter is recommended)

(4), system burn tool (Win32DiskImager)

(5) Raspberry PI System (download from the official website)

I used Raspbian Stretch Lite as an official system image. Lite is a deskless version with only a dark console, which is small in size and saves on performance and memory.

Name with desktop is a desktop UI, not familiar with liunx system friends may be more friendly, but the volume is very large, the occupation of performance will be higher.

2. Download the system image file

Download the system image you need, as shown below

You start with a zip package, about 360MB in size, that you need to unzip to get the folder shown above.

You can then enter the folder and see an IMG image, which is about 1.7GB in size.

Ps: If the official Raspbian image is from another third party, it may not be an IMG image after being decompressed. Please refer to Baidu to solve this problem.

3. Use Win32DiskImager to write an image to the memory card

After inserting the memory card into the card reader, insert it into the computer.

Open Win32DiskImager software, select IMG image, device select your U disk, and then click Write, write completion will pop up a successful prompt box.

Ps: I did not select the device in the picture above, because the card reader is not inserted, it is just a demonstration

4. Modify the files in the Boot partition

Don’t pull out the card reader just yet. At this point, our computer can see that there is only one partition on the USB flash drive called Boot, which is probably only about 40MB in size. Don’t worry, because Windows doesn’t recognize other partitions of the Liunx system on the memory card.

4.1 Creating an SSH File **

Our ERO W has a mini HDMI interface, but I don’t need a screen, so I need to use SSH to connect to the system in Zero W, so I need to turn on the SSH function at the first boot.

Enter the boot partition and create a new file named SSH, without the suffix !!!! Don’t write anything in it either!!

4.2 Creating the wpa_supplicant.conf file

Since SSH connection requires AN IP address, we need to automatically connect Zero W to wifi at the first startup so that it can be in the same LOCAL area network with our computer, so that we can connect to zero W system through SSH.

Similarly, create a file named wpa_supplicant.conf in the boot partition and write the following information to the file and save it:

country=CN
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
ssid="Your wifi name"
psk="Your wifi password"
}
Copy the code

5. Assemble and connect our smallest mainframe

Remove the memory card from the card reader, insert it into the Zero W, and use a USB Android cable to connect to the power supply (5V1A).

Wait for a few minutes, during which time our Zero W light will keep flashing, which is normal. When the light is on, we go to the router and check the IP address of the raspberry PI.

You can see that the IP address of Zero W is 192.168.0.104. Then use SSH connection tool (putty is recommended) to connect to Raspberry PI. The initial account is PI and the password is Raspberry.

The connection is successful, as shown in the figure above. So our system is installed correctly.

Ps: If the mobile phone turns on the hotspot as a router, we can download an app named Android Terminal and enter IP Neigh command to check the IP information of the device connected to the mobile phone.

6. Optimize our raspberry PI system

6.1 modify source

Because of the foreign source, our domestic connection was slow in the past, so we need to modify it to the domestic source. I modified the source of UNIVERSITY of Science and Technology of China.

6.1.1 Modifying the sources.list file

sudo nano /etc/apt/sources.listOther contents - comments, add the following: deb http://mirrors.ustc.edu.cn/raspbian/raspbian/raspbian stretch main contrib non -Copy the code

6.1.2 Modifying the raspi.list file

sudo nano /etc/apt/sources.list.d/raspi.listOther contents - comments, add the following: deb http://mirrors.ustc.edu.cn/archive.raspberrypi.org/debian stretch the main UICopy the code

6.1.3 Performing the Update

sudo apt-get update
sudo apt-get upgrade
Copy the code

6.2 Changing the Time Zone

Sudo dpkg-reconfigure tzdata find Asia Asia and select Shanghai.Copy the code

6.3 Enabling SSH automatically upon Startup

The first:

Go to the Interfacing option selection, then go to SSH and press Enter to enable it.Copy the code

The second:

If the SSH service is started after the system is restarted or shut down, the SSH service is disabled by default. You still need to manually start the service. For convenience, you can enable the SSH service to automatically start upon system startup by opening the /etc/rc.local file in the exit statement0/etc/init.d/ SSH startCopy the code

7. Install nginx

# installation
sudo apt-get install nginx
# start
sudo /etc/init.d/nginx start
# to restart
sudo /etc/init.d/nginx restart
# stop
sudo /etc/init.d/nginx stop
Copy the code

Open your browser to 192.168.0.104 (your raspberry PI IP address) and you will see the nginx page, indicating that it is installed.

8. Intranet penetration

Intranet penetration means that Intranet (local) Web applications are penetrated to the public network through NAT so that others can access them.

At present, Intranet penetration mainly consists of NGROK and FRP, which are very easy to use. Domestic NGROK is free of charge, including ItTUN, Sunny and NatApp, which are all free of charge. The first two can customize the domain name, while the latter requires VIP version to customize the domain name.

I have tried all three, I found sunny’s ARM version of ngrok client does not work on my raspberry PI, ittun’s and NatPP’s Ngrok are ok, I use ittun’s Ngrok_ARM version because I need to customize the domain name.

The use of these three official website has a detailed description, we check.

Here’s a normal runtime screenshot:

Since I need ngrok to run in the background, I use a Screen session to make it run in the background. However, self-starting is not implemented yet. In case of power failure or network failure, I have to manually run ngrok, which is a pain point that has not been solved yet.

9. More

Raspberry PI can not only be used to run a website, there are many functions waiting for you to develop, you can go to the Raspberry PI lab, many gods have written a lot of practical tutorials.

My zero W status information is as follows:

Nginx and Ngrok services are enabled on the server. The remaining memory is 250MB, which is very comfortable. The CPU temperature is not high, running for two days, basically between 37-39.

I have spent three days in compiling a set of Python learning tutorials, from the most basic Python scripts to Web development, crawlers, data analysis, data visualization, machine learning, etc. These materials have wanted to friends: Click to pick it up