码迷,mamicode.com
首页 > 编程语言 > 详细

树莓派2代B model 上手初体验,不用显示器,Python GPIO 点亮一颗LED

时间:2015-11-19 07:19:26      阅读:3733      评论:0      收藏:0      [点我收藏+]

标签:树莓派2代b model 上手初体验   不用显示器   python gpio 点亮一颗led   

开题:【好东西,值得研究!】

标题:树莓派2代B model 上手初体验,不用显示器,Python GPIO 点亮一颗LED


【知识普及】

1,树莓派各版本对比:

技术分享


2,树莓派2代BModel 主板,图样


技术分享

技术分享


技术分享



树莓派2 代B GPIO 图技术分享


技术分享





【所需硬件】

一张TF卡,8G或者8G以上,我的是 【三星TF卡16g class10 EVO】

一根网线,让树莓派与路由器连接 

一个5V 500MA 的普通USB电源,为树莓派供电 ,我试过了,5V 500ma没问题

一个树莓派2代B 

一个普通路由器【如果你连路由器都没有,可以参照windows的网络共享功能】

一个LED,及导线俩根

一个1K电阻


【软件准备】

windows下操作:

需要用的软件下载地址:

下载Win32DiskImager:http://sourceforge.net/projects/win32diskimager/

下载树莓派官方推荐系统:http://downloads.raspberrypi.org/


下载【树莓派定制的Debian系统】

下载最新版树莓派Debian系统: http://downloads.raspberrypi.org/raspbian_latest

下载后得到文件:2015-09-24-raspbian-jessie.zip

解压这个压缩文件得到:2015-09-24-raspbian-jessie.img



下载【Win32DiskImager】

http://jaist.dl.sourceforge.net/project/win32diskimager/Archive/Win32DiskImager-0.9.5-install.exe


【写入Linux系统】

TF内存卡插入读卡器,读卡器插入电脑USB

打开Win32DiskImager,找到img文件,目标盘符为TF卡,大约10几分钟,OK!


确保路由器开启DHCP服务,以便于让树莓派开机就能得到IP地址

Win32DiskImager写入Sucessfully之后,把TF卡插在树莓派的TF卡槽,





【准备就绪,开机】

插好网线,与开启DHCP的路由器连接

插入USB电源,开机

打开路由器管理页面,在ARP映射可以看到多出一个树莓派的IP,

如果IP太多你还是不知道是哪一个,可以把每个MAC地址复制到百度【MAC地址分析】,看到【Raspberry Pi Foundation】,这个就是树莓派对应的MAC



Xshell下载:http://www.netsarang.com/products/xsh_overview.html

得到IP后,打开Xshell工具,ssh跟上树莓派的IP

ssh 10.11.12.100

账户:pi

密码:raspberry

技术分享


【切换到root】

pi@raspberrypi ~ $ sudo su
root@raspberrypi:/home/pi#





【更新源】晚上网速有些慢,我的用了15分钟

root@raspberrypi:~# apt-get update
Get:1 http://mirrordirector.raspbian.org jessie InRelease [15.0 kB]                                   
Get:2 http://archive.raspberrypi.org jessie InRelease [13.3 kB]                             
Get:3 http://mirrordirector.raspbian.org jessie/main armhf Packages [8,962 kB]
Get:4 http://archive.raspberrypi.org jessie/main Sources [31.2 kB]
Get:5 http://archive.raspberrypi.org jessie/ui Sources [5,197 B]             
Get:6 http://archive.raspberrypi.org jessie/main armhf Packages [101 kB]                                                         
Get:7 http://archive.raspberrypi.org jessie/ui armhf Packages [7,639 B]                                                          
Ign http://archive.raspberrypi.org jessie/main Translation-en_GB                                                                 
Ign http://archive.raspberrypi.org jessie/main Translation-en                                                                    
Ign http://archive.raspberrypi.org jessie/ui Translation-en_GB                                                                   
Ign http://archive.raspberrypi.org jessie/ui Translation-en                                                                      
Get:8 http://mirrordirector.raspbian.org jessie/contrib armhf Packages [37.5 kB]                                                 
Get:9 http://mirrordirector.raspbian.org jessie/non-free armhf Packages [70.2 kB]                                                
Get:10 http://mirrordirector.raspbian.org jessie/rpi armhf Packages [1,356 B]                                                    
Ign http://mirrordirector.raspbian.org jessie/contrib Translation-en_GB                                                          
Ign http://mirrordirector.raspbian.org jessie/contrib Translation-en
Ign http://mirrordirector.raspbian.org jessie/main Translation-en_GB
Ign http://mirrordirector.raspbian.org jessie/main Translation-en
Ign http://mirrordirector.raspbian.org jessie/non-free Translation-en_GB
Ign http://mirrordirector.raspbian.org jessie/non-free Translation-en
Ign http://mirrordirector.raspbian.org jessie/rpi Translation-en_GB
Ign http://mirrordirector.raspbian.org jessie/rpi Translation-en
Fetched 9,244 kB in 15min 48s (9,742 B/s)
Reading package lists... Done



【安装Python的GPIO库】


先安装python开发包

root@raspberrypi:~# apt-get -y install python-dev 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  libpython-dev libpython2.7-dev python2.7-dev
The following NEW packages will be installed:
  libpython-dev libpython2.7-dev python-dev python2.7-dev
0 upgraded, 4 newly installed, 0 to remove and 56 not upgraded.
Need to get 18.2 MB of archives.
After this operation, 25.7 MB of additional disk space will be used.
Get:1 http://mirrordirector.raspbian.org/raspbian/ jessie/main libpython2.7-dev armhf 2.7.9-2
Get:2 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-dev armhf 2.7.9-1 [1,188 B]
13% [1 libpython2.7-dev 2,376 kB/17.9 MB 13%] [2 python-dev 1,188 B/1,188                                                                         Get:3 http://mirrordirector.raspbian.org/raspbian/ jessie/main libpython-dev armhf 2.7.9-1 [19.6 kB]
Get:4 http://mirrordirector.raspbian.org/raspbian/ jessie/main python2.7-dev armhf 2.7.9-2 [281 kB]
Fetched 18.2 MB in 13s (1,306 kB/s)                                     
Selecting previously unselected package libpython2.7-dev:armhf.
(Reading database ... 118460 files and directories currently installed.)
Preparing to unpack .../libpython2.7-dev_2.7.9-2_armhf.deb ...
Unpacking libpython2.7-dev:armhf (2.7.9-2) ...
Selecting previously unselected package libpython-dev:armhf.
Preparing to unpack .../libpython-dev_2.7.9-1_armhf.deb ...
Unpacking libpython-dev:armhf (2.7.9-1) ...
Selecting previously unselected package python2.7-dev.
Preparing to unpack .../python2.7-dev_2.7.9-2_armhf.deb ...
Unpacking python2.7-dev (2.7.9-2) ...
Selecting previously unselected package python-dev.
Preparing to unpack .../python-dev_2.7.9-1_armhf.deb ...
Unpacking python-dev (2.7.9-1) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up libpython2.7-dev:armhf (2.7.9-2) ...
Setting up libpython-dev:armhf (2.7.9-1) ...
Setting up python2.7-dev (2.7.9-2) ...
Setting up python-dev (2.7.9-1) ...
root@raspberrypi:~#





树莓派GPIO官方说明 https://pypi.python.org/pypi/RPi.GPIO

下载树莓派python GPIO库

root@raspberrypi:~# mkdir /home/gpio
root@raspberrypi:~# cd /home/gpio
root@raspberrypi:/home/gpio# wget https://pypi.python.org/packages/source/R/RPi.GPIO/RPi.GPIO-0.5.11.tar.gz
--2015-09-24 16:38:10--  https://pypi.python.org/packages/source/R/RPi.GPIO/RPi.GPIO-0.5.11.tar.gz
Resolving pypi.python.org (pypi.python.org)... 43.249.72.223
Connecting to pypi.python.org (pypi.python.org)|43.249.72.223|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 27060 (26K) [application/octet-stream]
Saving to: ‘RPi.GPIO-0.5.11.tar.gz’

RPi.GPIO-0.5.11.tar.gz           100%[======================>]  26.43K  94.0KB/s   in 0.3s   

2015-09-24 16:38:15 (94.0 KB/s) - ‘RPi.GPIO-0.5.11.tar.gz’ saved [27060/27060]
可以看到下载的GPIO库文件只有27K
root@raspberrypi:/home/gpio# ls -lh
-rw-r--r-- 1 root root 27K May 14 18:27 RPi.GPIO-0.5.11.tar.gz


解压并进入目录
root@raspberrypi:/home/gpio# tar xf RPi.GPIO-0.5.11.tar.gz 
root@raspberrypi:/home/gpio# cd RPi.GPIO-0.5.11
root@raspberrypi:/home/gpio/RPi.GPIO-0.5.11#


安装GPIO库

root@raspberrypi:/home/gpio/RPi.GPIO-0.5.11# python setup.py install
running install
running build
running build_py
creating build
creating build/lib.linux-armv7l-2.7
creating build/lib.linux-armv7l-2.7/RPi
copying RPi/__init__.py -> build/lib.linux-armv7l-2.7/RPi
running build_ext
building ‘RPi.GPIO‘ extension
creating build/temp.linux-armv7l-2.7
creating build/temp.linux-armv7l-2.7/source
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c source/py_gpio.c -o build/temp.linux-armv7l-2.7/source/py_gpio.o
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c source/c_gpio.c -o build/temp.linux-armv7l-2.7/source/c_gpio.o
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c source/cpuinfo.c -o build/temp.linux-armv7l-2.7/source/cpuinfo.o
source/cpuinfo.c: In function ‘get_rpi_info’:
source/cpuinfo.c:41:7: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result]
       fgets(buffer, sizeof(buffer) , fp);
       ^
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c source/event_gpio.c -o build/temp.linux-armv7l-2.7/source/event_gpio.o
source/event_gpio.c: In function ‘gpio_export’:
source/event_gpio.c:75:5: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
     write(fd, str_gpio, len);
     ^
source/event_gpio.c: In function ‘gpio_unexport’:
source/event_gpio.c:90:5: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
     write(fd, str_gpio, len);
     ^
source/event_gpio.c: In function ‘gpio_set_direction’:
source/event_gpio.c:106:9: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
         write(fd, "in", 3);
         ^
source/event_gpio.c:108:9: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
         write(fd, "out", 4);
         ^
source/event_gpio.c: In function ‘gpio_set_edge’:
source/event_gpio.c:124:5: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
     write(fd, stredge[edge], strlen(stredge[edge]) + 1);
     ^
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c source/soft_pwm.c -o build/temp.linux-armv7l-2.7/source/soft_pwm.o
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c source/py_pwm.c -o build/temp.linux-armv7l-2.7/source/py_pwm.o
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c source/common.c -o build/temp.linux-armv7l-2.7/source/common.o
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c source/constants.c -o build/temp.linux-armv7l-2.7/source/constants.o
arm-linux-gnueabihf-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wl,-z,relro -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-armv7l-2.7/source/py_gpio.o build/temp.linux-armv7l-2.7/source/c_gpio.o build/temp.linux-armv7l-2.7/source/cpuinfo.o build/temp.linux-armv7l-2.7/source/event_gpio.o build/temp.linux-armv7l-2.7/source/soft_pwm.o build/temp.linux-armv7l-2.7/source/py_pwm.o build/temp.linux-armv7l-2.7/source/common.o build/temp.linux-armv7l-2.7/source/constants.o -o build/lib.linux-armv7l-2.7/RPi/GPIO.so
running install_lib
creating /usr/local/lib/python2.7/dist-packages/RPi
copying build/lib.linux-armv7l-2.7/RPi/GPIO.so -> /usr/local/lib/python2.7/dist-packages/RPi
copying build/lib.linux-armv7l-2.7/RPi/__init__.py -> /usr/local/lib/python2.7/dist-packages/RPi
byte-compiling /usr/local/lib/python2.7/dist-packages/RPi/__init__.py to __init__.pyc
running install_egg_info
Writing /usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.5.11.egg-info

root@raspberrypi:/home/gpio/RPi.GPIO-0.5.11# echo $?
0
可以看到,没有错误


编写一个程序,点亮LED!

注意: 这里使用GPIO.BOARD模式,对应的是主板物理引脚号的排序,也就是说pin1就是板子上的3V3. 

把led的负极接到板子上的GPIO.0(pin11) LED正极接一个1K的电阻,在接到5V上(pin2). 特别注意python的缩进.

root@raspberrypi:/home/gpio/RPi.GPIO-0.5.11# cd
root@raspberrypi:~# vim test.py
#!/user/bin/python
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11,GPIO.OUT)
while True:
     GPIO.output(11,True)
     time.sleep(1)
     GPIO.output(11,False)
     time.sleep(1)

     运行程序
root@raspberrypi:~# python test.py


【效果图】 ctrl+c用来终止程序

技术分享







再来写一个检查按键的小程序:

按键一端接到GND(pin6),一端加到GPIO.1(PIN12)

root@raspberrypi:~# vim test2.py
#!/user/bin/python
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11,GPIO.OUT)
GPIO.setup(12,GPIO.IN)
while True:
    in_value= GPIO.input(12)
    if in_value ==False:
       GPIO.output(11,False)
       time.sleep(1)
       GPIO.output(11,True)
       while in_value == False:
          in_value = GPIO.input(12)


不按下按键,灯会以1HZ的频率闪烁  

按下按键,LED灯熄灭,松手,LED亮起!

【效果图】ctrl+c用来终止程序

技术分享


gif动画没做好,不去碰按键,灯是1HZ闪烁状态的,

按下按键,LED是熄灭的。

物联网家居,开始折腾!


【树莓派关机命令】

root@raspberrypi:~# init 0

等2秒,然后可以拔电源了!















[树莓派新手入门基础命令】



查看CPU信息

root@raspberrypi:/home/pi# cat /proc/cpuinfo 
processor	: 0
model name	: ARMv7 Processor rev 5 (v7l)
BogoMIPS	: 38.40
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 5

processor	: 1
model name	: ARMv7 Processor rev 5 (v7l)
BogoMIPS	: 38.40
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 5

processor	: 2
model name	: ARMv7 Processor rev 5 (v7l)
BogoMIPS	: 38.40
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 5

processor	: 3
model name	: ARMv7 Processor rev 5 (v7l)
BogoMIPS	: 38.40
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 5

Hardware	: BCM2709
Revision	: a21041
Serial		: 000000000f4c5cc4


BCM2708/9 属于处理器的家族
BCM2835/6 属于处理的具体型号


为root设置密码

root@raspberrypi:/home/pi# passwd root
Enter new UNIX password:haha 
Retype new UNIX password: haha
passwd: password updated successfully
安装vim编辑器
root@raspberrypi:/home/pi# apt-get -y install vim

开启vim语法高亮
root@raspberrypi:/home/pi# vim /etc/vim/vimrc +19
去掉前面的引号“syntax on,改为下面的,按ESC,按shift+zz保存退出
syntax on

开启root远程登录
root@raspberrypi:/home/pi# vim /etc/ssh/sshd_config  +28
把PermitRootLogin without-password改为下面的,按ESC,按shift+zz保存退出
PermitRootLogin yes

重启sshd服务
root@raspberrypi:/home/pi# service sshd restart



root@Ubuntu:~# ssh 10.11.12.100 -l root
The authenticity of host ‘10.11.12.100 (10.11.12.100)‘ can‘t be established.
ECDSA key fingerprint is 42:6a:d5:02:d4:23:46:a6:da:00:24:8f:16:2c:c4:49.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘10.11.12.100‘ (ECDSA) to the list of known hosts.
root@10.11.12.100‘s password: haha

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Thu Sep 24 16:15:36 2015 from 10.11.12.14
root@raspberrypi:~# 
root远程 登录成功!




修改root的配置文件:

root@raspberrypi:~# vim .bashrc 
# ~/.bashrc: executed by bash(1) for non-login shells.
# Note: PS1 and umask are already set in /etc/profile. You should not
# need this unless you want different defaults for root.
# PS1=‘${debian_chroot:+($debian_chroot)}\h:\w\$ ‘
# umask 022
# You may uncomment the following lines if you want `ls‘ to be colorized:
 export LS_OPTIONS=‘--color=auto‘
 eval "`dircolors`"
 alias ls=‘ls $LS_OPTIONS‘
 alias ll=‘ls $LS_OPTIONS -lh‘
 alias l=‘ls $LS_OPTIONS -lA‘
#
# Some more alias to avoid making mistakes:
 alias rm=‘rm -i‘
 alias cp=‘cp -i‘
 alias mv=‘mv -i‘
 
 使配置立即生效,注意两个点之间的空格
 root@raspberrypi:~# . .bashrc


查看推荐的源

root@raspberrypi:/home/pi# cat /etc/apt/sources.list
deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi
# Uncomment line below then ‘apt-get update‘ to enable ‘apt-get source‘
#deb-src http://archive.raspbian.org/raspbian/ jessie main contrib non-free rpi


 查看防火墙:

 root@raspberrypi:~# iptables -L -nv
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination




查看内存信息:看到的是1G的哈

root@raspberrypi:~# cat /proc/meminfo 
MemTotal:         948120 kB
MemFree:          789508 kB
MemAvailable:     862084 kB
Buffers:           17436 kB
Cached:            79256 kB
SwapCached:            0 kB
Active:            85240 kB
Inactive:          46372 kB
Active(anon):      35252 kB
Inactive(anon):     6476 kB
Active(file):      49988 kB
Inactive(file):    39896 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:        102396 kB
SwapFree:         102396 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:         35016 kB
Mapped:            37816 kB
Shmem:              6812 kB
Slab:              13516 kB
SReclaimable:       6344 kB
SUnreclaim:         7172 kB
KernelStack:        1136 kB
PageTables:         1868 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:      576456 kB
Committed_AS:     521112 kB
VmallocTotal:    1105920 kB
VmallocUsed:        1188 kB
VmallocChunk:     900580 kB
CmaTotal:           8192 kB
CmaFree:            3740 kB



查看内存使用情况:

root@raspberrypi:~# free -m
             total       used       free     shared    buffers     cached
Mem:           925        172        752          7         25         82
-/+ buffers/cache:         65        860
Swap:           99          0         99




查看磁盘挂载情况:

root@raspberrypi:~# df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/root      ext4      3.9G  3.2G  515M  87% /
devtmpfs       devtmpfs  459M     0  459M   0% /dev
tmpfs          tmpfs     463M     0  463M   0% /dev/shm
tmpfs          tmpfs     463M  6.3M  457M   2% /run
tmpfs          tmpfs     5.0M  4.0K  5.0M   1% /run/lock
tmpfs          tmpfs     463M     0  463M   0% /sys/fs/cgroup
/dev/mmcblk0p1 vfat       56M   20M   37M  36% /boot
tmpfs          tmpfs      93M     0   93M   0% /run/user/1000
tmpfs          tmpfs      93M     0   93M   0% /run/user/0


插入一个32GU盘:

root@raspberrypi:~# df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/root      ext4      3.9G  3.2G  515M  87% /
devtmpfs       devtmpfs  459M     0  459M   0% /dev
tmpfs          tmpfs     463M     0  463M   0% /dev/shm
tmpfs          tmpfs     463M  6.3M  457M   2% /run
tmpfs          tmpfs     5.0M  4.0K  5.0M   1% /run/lock
tmpfs          tmpfs     463M     0  463M   0% /sys/fs/cgroup
/dev/mmcblk0p1 vfat       56M   20M   37M  36% /boot
tmpfs          tmpfs      93M     0   93M   0% /run/user/1000
tmpfs          tmpfs      93M     0   93M   0% /run/user/0
/dev/sda1      vfat       30G   14G   16G  47% /media/pi/SSK_32G


查看磁盘的详细信息:

root@raspberrypi:~# hdparm -I /dev/sda

/dev/sda:
SG_IO: bad/missing sense data, sb[]:  70 00 05 00 00 00 00 0a 00 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

ATA device, with non-removable media
	Media Serial Num:   YZ[\]^_`ab
	Media Manufacturer: cdefg
	Transport:          Parallel
Standards:
	Supported: 5 3 
	Likely used: 5
Configuration:
	Logical		max	current
	cylinders	0	0
	heads		2560	0
	sectors/track	32	0
	--
	Logical/Physical Sector size:           512 bytes
	device size with M = 1024*1024:           0 MBytes
	device size with M = 1000*1000:           0 MBytes 
	cache/buffer size  = unknown
Capabilities:
	IORDY(may be)(cannot be disabled)
	Standby timer values: spec‘d by Vendor
	R/W multiple sector transfer: Max = 0	Current = ?
	DMA: not supported
	PIO: pio0 
Security: 
	Master password revision code = 47
		supported
	not	enabled
	not	locked
	not	frozen
	not	expired: security count
	not	supported: enhanced erase
	92min for ENHANCED SECURITY ERASE UNIT. 
Integrity word not set (found 0x0000, expected 0x61a5)
root@raspberrypi:~# 






root@raspberrypi:~# hdparm -I /dev/sda1

/dev/sda1:
SG_IO: bad/missing sense data, sb[]:  70 00 05 00 00 00 00 0a 00 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

ATA device, with non-removable media
	Media Serial Num:   YZ[\]^_`ab
	Media Manufacturer: cdefg
	Transport:          Parallel
Standards:
	Supported: 5 3 
	Likely used: 5
Configuration:
	Logical		max	current
	cylinders	0	0
	heads		2560	0
	sectors/track	32	0
	--
	Logical/Physical Sector size:           512 bytes
	device size with M = 1024*1024:           0 MBytes
	device size with M = 1000*1000:           0 MBytes 
	cache/buffer size  = unknown
Capabilities:
	IORDY(may be)(cannot be disabled)
	Standby timer values: spec‘d by Vendor
	R/W multiple sector transfer: Max = 0	Current = ?
	DMA: not supported
	PIO: pio0 
Security: 
	Master password revision code = 47
		supported
	not	enabled
	not	locked
	not	frozen
	not	expired: security count
	not	supported: enhanced erase
	92min for ENHANCED SECURITY ERASE UNIT. 
Integrity word not set (found 0x0000, expected 0x61a5)
root@raspberrypi:~#




查看发行版信息,可以看到是基于Debian 8.0的jessie版本二次开发的

root@raspberrypi:/home/pi# lsb_release -a
No LSB modules are available.
Distributor ID:	Raspbian
Description:	Raspbian GNU/Linux 8.0 (jessie)
Release:	8.0
Codename:	jessie



root@raspberrypi:~# uname -a
Linux raspberrypi 4.1.7-v7+ #817 SMP PREEMPT Sat Sep 19 15:32:00 BST 2015 armv7l GNU/Linux



root@raspberrypi:~# cat /etc/debian_version 
8.0

root@raspberrypi:~# cat /etc/issue
Raspbian GNU/Linux 8 \n \l





 查看USB设备:

root@raspberrypi:~# lsusb -tv
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc_otg/1p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/5p, 480M
        |__ Port 1: Dev 3, If 0, Class=Vendor Specific Class, Driver=smsc95xx, 480M
        |__ Port 4: Dev 4, If 0, Class=Mass Storage, Driver=usb-storage, 480M



查看加载的内核驱动:

root@raspberrypi:~# lsmod
Module                  Size  Used by
iptable_filter          1260  0 
ip_tables              11618  1 iptable_filter
x_tables               13602  2 ip_tables,iptable_filter
sg                     18159  0 
cfg80211              420690  0 
rfkill                 16659  1 cfg80211
bcm2835_gpiomem         2995  0 
uio_pdrv_genirq         2966  0 
uio                     8235  1 uio_pdrv_genirq
i2c_dev                 6047  0 
snd_bcm2835            19769  3 
snd_pcm                74825  1 snd_bcm2835
snd_timer              18157  1 snd_pcm
snd                    52116  9 snd_bcm2835,snd_timer,snd_pcm
fuse                   81710  3 
ipv6                  339514  30



查看IP信息:

root@raspberrypi:~# ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:4c:5c:c4  
          inet addr:10.11.12.100  Bcast:10.11.12.255  Mask:255.255.255.0
          inet6 addr: fe80::ba27:ebff:fe4c:5cc4/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1572 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1377 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:113971 (111.2 KiB)  TX bytes:213173 (208.1 KiB)

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


查看路由表:

root@raspberrypi:~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.11.12.13     0.0.0.0         UG    202    0        0 eth0
10.11.12.0      0.0.0.0         255.255.255.0   U     202    0        0 eth0






查看开启服务的端口,以及建立的连接

root@raspberrypi:~# netstat -lntpa
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      469/sshd        
tcp        0    152 10.11.12.100:22         10.11.12.14:8041        ESTABLISHED 798/0           
tcp6       0      0 :::22                   :::*                    LISTEN      469/sshd





查看树莓派上一共有多少个用户

root@raspberrypi:~# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
systemd-timesync:x:100:103:systemd Time Synchronization,,,:/run/systemd:/bin/false
systemd-network:x:101:104:systemd Network Management,,,:/run/systemd/netif:/bin/false
systemd-resolve:x:102:105:systemd Resolver,,,:/run/systemd/resolve:/bin/false
systemd-bus-proxy:x:103:106:systemd Bus Proxy,,,:/run/systemd:/bin/false
pi:x:1000:1000:,,,:/home/pi:/bin/bash
sshd:x:104:65534::/var/run/sshd:/usr/sbin/nologin
messagebus:x:105:110::/var/run/dbus:/bin/false
avahi:x:106:111:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/bin/false
ntp:x:107:112::/home/ntp:/bin/false
statd:x:108:65534::/var/lib/nfs:/bin/false
lightdm:x:109:114:Light Display Manager:/var/lib/lightdm:/bin/false





本文出自 “折腾岁月。” 博客,请务必保留此出处http://990487026.blog.51cto.com/10133282/1714461

树莓派2代B model 上手初体验,不用显示器,Python GPIO 点亮一颗LED

标签:树莓派2代b model 上手初体验   不用显示器   python gpio 点亮一颗led   

原文地址:http://990487026.blog.51cto.com/10133282/1714461

(0)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!