Electronic projects

[Electronic projects][bleft]

Arduino Projects

[Arduino Projects][bleft]

Metal detectors

[Metal detectors][bleft]

Home projects

[Home projects][bleft]

Raspberry Pi: Boot to use


Raspberry Pi: Boot to use

 The Raspberry Pi is an ultra-compact computer with a size of a credit card, developed by the Raspberry Pi Foundation in the United Kingdom. Due to its ultra-small size, the Raspberry Pi has been popular all over the world since its release in 2012. Regardless of the small size of the Raspberry Pi, it is a fully functional computer. After connecting the monitor, mouse and keyboard, you can use the Raspberry Pi like a normal desktop computer. For Raspberry Pi 3, it also has built-in wireless support for WiFi and Bluetooth, making it easier to connect wirelessly. Raspberry Pi can be seen in many hardware innovation projects. I will introduce the basic usage of Raspberry Pi in a series of articles.


Hardware introduction

The picture below shows a Raspberry Pi 3. As you can see, it provides a rich interface.

 The main interfaces of the Raspberry Pi are marked in the figure. To start the Raspberry Pi for the first time, you need a mouse and keyboard connected to the USB interface, as well as a common HDMI display. In addition, you also need a power supply with an output voltage of 5V. The output end of this power cord is Micro USB, which is connected to the Raspberry Pi. The official power socket of the Raspberry Pi can be directly plugged into a household 220V voltage socket. Or, you can buy a USB to Micro USB cable and plug the USB end into a PC or other USB port that provides power. Once connected, the Raspberry Pi will start automatically.

 We can take a look at other hardware on the Raspberry Pi by the way. In the center of the Raspberry Pi is Broadcom's ARM CPU, which is the heart of ARM. In addition, there is a GPU chip on the front, which is mainly used for image processing. The square chip on the back of the chip is the memory of the Raspberry Pi. Raspberry Pi mainly relies on these three chips for the most important control and calculation work. In addition, the Raspberry Pi also provides many interfaces to the outside world. There are 4 USB ports and 1 Ethernet port on the far right side of the picture. Insert a network cable into the Ethernet interface to connect to the Internet by wire. In addition to the power port, HDMI output port and audio port connected to the monitor, there is also a cable port for connecting a dedicated camera on the lower side. It should be noted that the Raspberry Pi will only output to the HDMI port when the display device is checked when the device is turned on, so the HDMI interface display must be connected before turning on the device. There is a cable port shown on the top on the left. Considering the widespread use of HDMI, the chance of this jack is not very high. There is a socket for a Micro SD card under the left side. This SD card replaces the hard drive in a normal computer. There is also a row of pins on the upper side of the Raspberry Pi, which constitutes a general programming interface (GPIO). GPIO can be used for low-level connections with many primitive hardware peripherals.


System installation and startup

Raspberry Pi is just hardware, we also need software to make Raspberry Pi run. The most basic software on the Raspberry Pi is its operating system. Since the Raspberry Pi uses a Micro SD card as its storage space, the operating system is also installed on this SD card. The Raspberry Pi official website provides a Raspbian image file . Just burn the image file to an SD card, and then insert this SD card into the Raspberry Pi. Raspbian is inherited from the Debian operating system. Debian is a distribution version of Linux, and Linux complies with Unix specifications. Therefore, if you are familiar with any operating system in the Unix family, you can quickly get started with Raspberry Pi. Conversely, when you are familiar with Raspbian, you can also use Unix systems like Apple OS X.

Operation interface of Raspbian system


For the Raspberry Pi, all software is installed on a small SD card, and the operating system is no exception. Without this SD card, the Raspberry Pi cannot be used at all. We need another computer to save the operating system program to this SD card. Needless to say, this computer must have an SD card read/write port. Many laptops come with SD card sockets. Even if not, a card reader with a USB interface can be bought very cheaply. In addition, you have to go to the official website of the Raspberry Pi to download the source files of the operating system. Since the operating system will be updated from time to time, the file name will also be different. I will refer to the file as raspbian.image in the following.


1) Unix system

If your computer is a Unix system, such as Linux and Mac OSX, we can use ready-made tools to make an operating system for the Raspberry Pi. After inserting the SD card into the card reader slot of the computer, we must first find the path where the SD card is mounted.


If it is under Mac OSX, then enter the following command to list all the mounted storage devices:

diskutil list

Find the device corresponding to the SD card size and write down its path, such as /dev/disk3. If it is a Linux system, you can use the following command to find out the path:

sudo fdisk -l


Then, you can use the common dd tool under UNIX systems to write the image file to the SD card:

sudo  dd  if =/dev/disk3 of=./raspian.image


2) Windows system

Under Windows, there are ready-made graphical software to complete the above-mentioned image burning work, such as Win32DiskImager recommended by the Raspberry Pi official website . The whole operation process is simpler than UNIX system, so I won't repeat it here.


After the writing is completed, insert the SD card into the card slot of the Raspberry Pi, connect the power supply to the Raspberry Pi, and you can see the startup screen of the Raspberry Pi on the screen.



After the boot is complete, you can enter the graphical desktop of Rapbian. The main functions provided by the graphical desktop are all included in the upper navigation bar:

  Operation interface of Raspbian system


The Menu in the upper left corner of the navigation bar contains a lot of application software. Many functional software are provided in the menu:

  • Programming: Programming tools, such as the dynamic programming language Python, Mathematica for mathematical operations, and Scratch for programming education.
  • Office: Office software, the open source LibreOffice suite.
  • Internet: Internet software, such as e-mail clients and browsers.
  • Games: Games. I'm a little disappointed here, except for Minecraft, which is Python Games for game programming.
  • Accessories: Tool software, such as File Manager, Terminal, text editor, etc.
  • Sound & Videos: VLC player.

In addition, the menu terminal Preferences is used for system settings, you can set the time, language, display and other options in it. The Shutdown button at the bottom is used to shut down or restart.


Next to the menu are five commonly used software from the menu, followed by the browser, file manager, terminal, and Mathematica and Wolfgram for scientific computing. In our tutorial, the most commonly used terminal is the terminal. Among the buttons on the right, from left to right are Bluetooth, Wifi, sound control, CPU usage monitoring, and time. You can connect to the wireless network via the Wifi button. All pluggable devices, such as USB memory, are listed on the far right. Apart from the huge Raspberry Pi logo on the desktop is a wastebasket.


The graphical desktop of the Raspberry Pi can indeed be explored for a while. But this desktop can be said to be a bit crude. "Beautiful graphics" has never been Linux's strengths. If you really want to use such a desktop system for office, I am afraid you will be even more disappointed. When the Raspberry Pi browser opens the video on the website, you are likely to experience slow page loading and slow video playback. If you want to open multiple windows to work, the desktop will easily crash. After all, the configuration of the Raspberry Pi is very low-end, and the presentation of computer graphics consumes resources. Fortunately, Linux provides a better way with Raspberry Pi: Shell.


Open Terminal, and a window with a black background will appear on the desktop. The window shows:

pi@raspberrypi:~ $

Here pi is your username and raspberrypi is the name of your computer


For example, enter the date command:


After hitting the Enter key, the current time of the system will be displayed.


Shell looks simple, but it is actually much more powerful than a graphical desktop. The Linux operating system is inherited from the Unix operating system. Regardless of whether it is Linux or Unix operating systems, initially only the Shell, a user interface, was provided. The graphical desktop developed later could not provide all the functions of Shell. If you are used to this text operation interface, you will find that it is not only more powerful than the desktop, but also much easier to use than the desktop. Now, I will introduce some commands, on the one hand, let you know more about Raspberry Pi, on the other hand, let you experience Shell.


Know your Raspberry Pi

1) Linux general commands

The Linux system provides a variety of commands. Enter these commands in the Shell, you can achieve many functions. I will introduce some commands here to help you understand your Raspberry Pi. First use the lscpu command to query the CPU information:



The CPU information is printed out in the terminal window:

Architecture: armv7l
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 1
Core(s) per socket: 4
Socket(s): 1
Model name: ARMv7 Processor rev 4 (v7l)
CPU max MHz: 1200.0000
CPU min MHz: 600.0000

As you can see, my Raspberry Pi uses a 4-core ARM processor with a maximum frequency of 1200MHz.


Then, you can use the free command to understand the memory usage:

free -h

When using the above command, the -h option is added. The letter h here means human readable, that is, the original byte-based result is converted into a unit that is more suitable for display. The results are as follows:

total used free shared buffers cached
Mem: 862M 739M 122M 14M 44M 397M
-/+ buffers/cache: 298M 563M
Swap: 99M 0B 99M

As you can see, the total amount of memory is 862M. In the next column, you can also see the used and free memory space.

 Then, we can look at the storage situation of the SD card, using the command fdisk 

sudo fdisk -l

The command fdisk is used to display disk information. Option -l means to list all disks. We again see the addition of sudo before the command . Because the execution of the fdisk command requires the authority of a super administrator, sudo executes fdisk as a super administrator. The last two lines of the result are as follows:

Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 8192 131071 122880 60M c W95 FAT32 (LBA)
/dev/mmcblk0p2 131072 30318591 30187520 14.4G 83 Linux

The entire SD card is divided into two partitions. One partition has a size of 60M and is specially used for booting the Raspberry Pi. Another partition is used to store all other data.


Using lsusb , you can find all USB peripherals:

Bus 001 Device 005: ID 0e8f:2517 GreenAsia Inc. 
Bus 001 Device 006: ID 045e:0750 Microsoft Corp. Wired Keyboard 600
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub


Using uname -a , the operating system information can be displayed completely:

Linux raspberrypi 4.1.19-v7+ #858 SMP Tue Mar 15 15:56:00 GMT 2016 armv7l GNU/Linux

The kernel used by my system is Linux 4.1.19 version. You can also see from the output that the release time of the kernel is March 15, 2016.


Finally, you can use the ifconfig command to view the network interface. The result of the command is as follows:


eth0 Link encap:Ethernet HWaddr b8:27:eb:d8:ed:f4  
          inet6 addr: fe80::9b8b:c0de:d083:6ddd/64 Scope:Link
          UP BROADCAST MULTICAST MTU:1500 Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

lo Link encap:Local Loopback  
          inet addr: Mask:
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING MTU:65536 Metric:1
          RX packets: 243 errors:0 dropped:0 overruns:0 frame:0
          TX packets:243 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes: 19020 (18.5 KiB) TX bytes: 19020 (18.5 KiB)

wlan0 Link encap:Ethernet HWaddr b8:27:eb:8d:b8:a1  
          inet addr: Bcast: Mask:
          inet6 addr: fe80::ba27:ebff:fe8d:b8a1/64 Scope:Link
          RX packets:45926 errors:0 dropped:4268 overruns:0 frame:0
          TX packets: 10469 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes: 26867855 (25.6 MiB) TX bytes: 1360267 (1.2 MiB)


Among them, eth0 represents the Ethernet interface, and wlan0 represents the Wifi interface. And lo is a virtual local interface, used to represent this machine. In the interface connected to the Internet, we can see the IP address of the interface and other information. For example, the IP address of wlan0 is Since I did not plug in the network cable, eth0 does not have an IP address.


2) Special commands for Raspberry Pi

In addition to common Linux commands, the Raspberry Pi also provides the vcgencmd command for direct interaction with the Raspberry Pi hardware. For example, execute in Shell:

vcgencmd measure_temp

In the above command, the measure_temp in the second paragraph is called the parameter of the command. Parameters are another way to provide additional information to the command in addition to options. The above command will return the temperature of the CPU:



Use the following command to measure the core voltage of the Raspberry Pi:

vcgencmd measure_volts core

Return voltage value:



There are many more functions provided by vcgencmd. In addition to displaying hardware information, you can also use this command to control the hardware. Its usage will not be listed one by one, please refer to vcgencmd for details .


This article introduces the hardware and basic operations of the Raspberry Pi, and thus starts the journey of the Raspberry Pi.


No comments:


Arduino Projects

[Arduino Projects][twocolumns]