树莓派使用 (Raspberry)

来源:互联网 发布:淘宝 大麦网 编辑:程序博客网 时间:2024/04/30 23:24
通过笔记本电脑登陆raspberry 
通过TTL串口连接树莓派(无需网络)
配置Raspberry
关闭系统
Configure eth0 to not use DHCP
配置JAVA
配置Tomcat
USB to Serial 配置
安装配置Linux串口调试工具minicom
使用Rxtx进行串口通讯编程
串口开发中遇到问题及对策
Samba安装 - Windows下匿名访问Linux共享目
树莓派中使用SFTP
其他


Version: 2014-12-24-wheezy-raspbian

通过笔记本电脑登陆raspberry 
方式一: 
通过网线连接树莓派,在路由器管理界面中找到树莓派IP,
通过SSH Secure Shell或Putty等工具使用此IP进行连接。

方式二:
step1)通过SSH登陆raspberry, 安装xrdp服务 
pi@raspberrypi ~ $ sudo apt-get install xrdp
step2)通过mstsc.exe进行连接,输入登陆raspberry的用户名密码 pi/raspberry 即可。 


通过TTL串口连接树莓派(无需网络)
将6,8,10分别于USB端GND, RXD, TXD相连,另外树莓派接上5V外接电源。

在PuTTY中选择通过Serial连接,设定COM口号码,波特率为115200。



配置Raspberry
sudo raspi-config 

关闭系统 
sudo shutdown -h now 


启用root账户 
root账户默认没有密码,但账户锁定
需要root权限时,由sudo执行 
pi@raspberrypi ~ $ sudo su - 

重新开启root账号,可执行 
pi@raspberrypi ~ $ sudo passwd root

再执行以下命令解锁账户 
pi@raspberrypi ~ $ sudo passwd --unlock root


Configure eth0 to not use DHCP
step1) Using a static IP
pi@raspberrypi ~ $ sudo vi /etc/network/interfaces 
修改前
...
iface eth0 inet dhcp
... 

修改后
...
#iface eth0 inet dhcp
iface eth0 inet static
address 192.168.199.100
netmark 255.255.255.0
gateway 192.168.199.1
...

step2) Add your DNS server
pi@raspberrypi ~ $ sudo vi /etc/resolv.conf 
追加如下一行
nameserver 192.168.199.1 

配置好之后,重启系统,用新IP连接即可。

Ref:
http://elinux.org/Configuring_a_Static_IP_address_on_your_Raspberry_Pi
http://www.slblabs.com/2012/08/16/rpi-ssh-ip/


配置JAVA 
1)打开/etc/profile, 在文件内容最后加入 
export JAVA_HOME=/usr/jdk1.8.0_06 
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar 
export PATH=$JAVA_HOME/bin:$PATH 
注: $JAVA_HOME/bin放在$PATH前,可避免执行系统预先安装好的java命令,可用 java -version 测试。 
2)执行命令 
source /etc/profile 


配置Tomcat
1)下载 apache-tomcat-7.0.57.tar.gz
http://tomcat.apache.org/download-70.cgi
2)拷贝文件到 /usr/local/目录下
3)解压
root@raspberrypi:/usr/local# tar -zxvf apache-tomcat-7.0.57.tar.gz
4)启动Tomcat
root@raspberrypi:/usr/local# apache-tomcat-7.0.57/bin/startup.sh
5)关闭Tomcat
root@raspberrypi:/usr/local# apache-tomcat-7.0.57/bin/shutdown.sh
6)设置Tomcat开机自启动
# vi /etc/rc.local
在语句"exit 0"之前追加 /usr/local/apache-tomcat-7.0.57/bin/startup.sh 即可
7)查看Tomcat是否已启动
# ps -ef | grep tomcat
例:
未启动
root@raspberrypi:/etc# ps -ef | grep tomcat 
root 2546 2310 0 22:32 pts/0 00:00:00 grep tomcat 

已启动
root@raspberrypi:/etc# ps -ef | grep tomcat 
root 2555 1 84 22:34 pts/0 00:00:03 /usr/jdk1.8.0_06/bin/java -Djava.util.logging.config.file=/usr/local/apache-tomcat-7.0.57/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/local/apache-tomcat-7.0.57/endorsed -classpath /usr/local/apache-tomcat-7.0.57/bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.57/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/apache-tomcat-7.0.57 -Dcatalina.home=/usr/local/apache-tomcat-7.0.57 -Djava.io.tmpdir=/usr/local/apache-tomcat-7.0.57/temp org.apache.catalina.startup.Bootstrap start 
root 2565 2310 0 22:34 pts/0 00:00:00 grep tomcat 



USB to Serial 配置
1.网上购买PL2303芯片的Usb转RS232(公头)线,并将USB一端插入树莓派USB口
2.查看树莓派是否支持USB转串口
pi@raspberrypi:~$lsmod | grep usbserial 
usbserial 26684 3 pl2303 
若有usbserial表示支持usb转串口
3.查看新插入的串口线对应的串口号
pi@raspberrypi:~$ dmesg | grep ttyUSB 
[ 982.354246] usb 1-1.5: pl2303 converter now attached to ttyUSB0 
[ 1082.051230] pl2303 ttyUSB0: pl2303 converter now disconnected from ttyUSB0 
[ 2679.800016] usb 1-1.5: pl2303 converter now attached to ttyUSB0 



安装配置Linux串口调试工具minicom
安装
pi@raspberrypi:~$ sudo apt-get install minicom
配置
pi@raspberrypi:~$ sudo minicom -s
选择[ Serial port setup ] ->
    | A - Serial Device : /dev/ttyUSB0 |
    | B - Lockfile Location : /var/lock |
    | C - Callin Program :                     |
    | D - Callout Program :                  |
    | E - Bps/Par/Bits : 9600 8N1         |
    | F - Hardware Flow Control : No  |
    | G - Software Flow Control : No   |
选择[ Filenames and paths ] ->
    | A - Download directory : /home/pi |
    | B - Upload directory : /tmp              |
选择[ Save setup as dfl ]


使用Rxtx进行串口通讯编程
注1: ?
使用minicom与windows上串口助手通信时,有时minicom无反应。
需 minicom -s 进行设置,然后选择 'exit from minicom',再重启系统后才可通信

注2:
1) 下载 RXTXcomm.jar 及 arm版 librxtxSerial-2.1-7.so
2) 重命名为 librxtxSerial.so
3) 将 librxtxSerial.so 放置于 /usr/jdk1.8.0_06/jre/lib/arm/ 目录下
4) 将 RXTXcomm.jar 放置于 /usr/jdk1.8.0_06/jre/lib/ext/ 目录下

注3:



串口开发中遇到问题及对策
背景
程序结构
设备侧 -------(串口)-------树莓派服务侧 -----(rest)------PC Client (即Browser)
设备侧用PC串口助手模拟

初始状态
Rest服务部署在Tomcat中,Tomcat位于Raspbian
librxtxSerial.so 放置于 /usr/jdk1.8.0_06/jre/lib/arm/ 目录下
RXTXcomm.jar 放置于 /usr/jdk1.8.0_06/jre/lib/ext/ 目录下

PC Client访问Rest服务,抛出如下异常
nested exception is java.lang.NoClassDefFoundError: gnu/io/UnsupportedCommOperationException

于是将
RXTXcomm.jar放于WEB-INF/lib/目录下
或 放置于 <TOMCAT>/lib/目录下

PC Client再此访问服务,又抛出如下异常
java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path
 java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857)
 java.lang.Runtime.loadLibrary0(Runtime.java:870)
 java.lang.System.loadLibrary(System.java:1119)
 gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:83)

于是查看Tomcat的logs/catalina.out日志,发现如下
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/arm:/lib:/usr/lib

于是将
librxtxSerial.so放于/usr/lib/目录下

重启系统

运行如下命令测试
# echo test > /dev/ttyUSB0  (? 有时必须先执行此命令)
若设备端 (PC串口助手)有显示
则在PC Client侧可通过Brower访问服务


Samba安装 - (Windows下匿名访问Linux共享目录)
#sudo apt-get install samba
#sudo apt-get install smbclient
 
启动Samba服务器
#sudo /etc/init.d/samba start
关闭
#sudo /etc/init.d/samba stop
重启
#sudo /etc/init.d/samba restart
 
配置Samba服务 
#mkdir /home/pi/share
#sudo  cp /etc/samba/smb.conf  /etc/samba/smb.conf.bak  // 备份
 
#vi  /etc/samba/smb.conf 
将文件中的内容做如下相应修改
1)在"#security=user"后面添加:
security=share
 
2)在文件结尾添加如下行:
[share]
comment=this is Linux share directory
path=/home/pi/share
public=yes
writable=yes

 
保存退出,启动Samba服务
#/etc/init.d/samba start
 
在Windows 下访问共享目录,输入
\\<树莓派IP>\share
 
关于Windows下无写权限: chmod -R go+rwx  /home/pi/share
Ref: http://www.linuxidc.com/Linux/2011-07/38996.htm
 
树莓派中使用SFTP
Ref: http://www.raspberrypi.org/documentation/remote-access/ssh/sftp.md
The SSH File Transfer Protocol is a network protocol that provides file access, file transfer, and file management functionalities over SSH.
By using SFTP you can easily change, browse and edit files on your Raspberry Pi. SFTP is easier to setup than FTP as Raspbian has SSH enabled by default.
FILEZILLA
1) Download the latest FileZilla Client version for your operating system from filezilla-project.org.
2) Launch FileZilla and go to File Site manager.
3) Fill in the IP address, user name and password (by default the user name is pi and the password raspberry) of your Raspberry Pi in the dialog and choose SFTP as the protocol.
4) Click Connect and you will see the home folder of the user.

其他

通过笔记本电脑登陆raspberry
方式三: 
通过VNC进行连接 
1)通过SSH登陆raspberry,安装VNC服务 (http://www.penguintutor.com/linux/tightvnc) 
pi@raspberrypi ~ $ sudo apt-get install tightvncserver 
2)设置VNC密码 
pi@raspberrypi ~ $ vncpasswd 

3)在raspberry侧启动tightvncserver 
pi@raspberrypi /usr/bin $ ls -l tight* 
-rwxr-xr-x 1 root root 4344 Jun 12 2012 tightvncconnect 
-rwxr-xr-x 1 root root 11724 Jun 12 2012 tightvncpasswd 
-rwxr-xr-x 1 root root 19655 Jun 12 2012 tightvncserver 
pi@raspberrypi /usr/bin $ ./tightvncserver 

New 'X' desktop is raspberrypi:2 

Starting applications specified in /home/pi/.vnc/xstartup 
Log file is /home/pi/.vnc/raspberrypi:2.log 

4)在Windows侧, 
通过VNC-Viewer-5.0.3-Windows-32bit.exe进行连接 
输入<IP地址:控制台号>, 如:192.168.199.117:2 
再输入第二步中设定的VNC密码即可。 


Is armhf or armel ? 
执行如下命令,有输出是armhf, 无输出表示armel 
pi@raspberrypi /usr/bin $ readelf -A /proc/self/exe | grep Tag_ABI_VFP_args 
Tag_ABI_VFP_args: VFP registers 
pi@raspberrypi /usr/bin $ 


0 0
原创粉丝点击