分类目录归档:技术文献

树莓派 PCF8591 AD/DA

树莓派本身没有AD/DA功能,如果树莓派外接模拟传感器,则必须外接AD/DA功能扩展板才能用。Pioneer 600扩展带有AD/DA芯片PCF8591,pcf8591带1通道8位DA,4通道8位AD,通过I2C控制。

一、DAC
1、bcm2835程序

编译并执行
gcc –Wall pcf8591.c –o pcf8591 –lbcm2835
sudo ./ pcf8591

2、Python程序

执行程序
sudo python pcf8591
3、wiringPi程序

编译并执行程序
gcc –Wall pcf8591.c –o pcf8591 –lbcm2835 -lwiringPi
sudo ./ pcf8591
二、ADC
1、bcm2835程序

编译并执行
gcc –Wall pcf8591.c –o pcf8591 –lbcm2835
sudo ./ pcf8591
2、Python程序

执行程序
sudo python pcf8591
3、wiringPi程序

编译并执行程序
gcc –Wall pcf8591.c –o pcf8591 -lwiringPi
sudo ./ pcf8591

Linux中设置UEFI启动项 -- efibootmgr

usage: efibootmgr [options]
-a | --active sets bootnum active
-A | --inactive sets bootnum inactive
-b | --bootnum XXXX modify BootXXXX (hex)
-B | --delete-bootnum delete bootnum (hex)
-c | --create create new variable bootnum and add to bootorder
-C | --create-only create new variable bootnum and do not add to bootorder
-D | --remove-dups remove duplicate values from BootOrder
-d | --disk disk (defaults to /dev/sda) containing loader
-e | --edd [1|3|-1] force EDD 1.0 or 3.0 creation variables, or guess
-E | --device num EDD 1.0 device number (defaults to 0x80)
-g | --gpt force disk with invalid PMBR to be treated as GPT
-i | --iface name create a netboot entry for the named interface
-l | --loader name (defaults to \EFI\redhat\grub.efi)
-L | --label label Boot manager display label (defaults to "Linux")
-n | --bootnext XXXX set BootNext to XXXX (hex)
-N | --delete-bootnext delete BootNext
-o | --bootorder XXXX,YYYY,ZZZZ,... explicitly set BootOrder (hex)
-O | --delete-bootorder delete BootOrder
-p | --part part (defaults to 1) containing loader
-q | --quiet be quiet
-t | --timeout seconds set boot manager timeout waiting for user input.
-T | --delete-timeout delete Timeout.
-u | --unicode | --UCS-2 pass extra args as UCS-2 (default is ASCII)
-v | --verbose print additional information
-V | --version return version and exit
-w | --write-signature write unique sig to MBR if needed
-@ | --append-binary-args file append extra args from file (use "-" for stdin)
-h | --help show help/usage

sshfs 远程挂载文件系统

SSH 是一个强大且安全的工具,我们除了可以用它来远程管理主机外,还可以通过它建立 SSH tunnel 作 Proxy 用,远程传输文件等等。而这里我想要介绍另外一个功能,那就是结合 sshfs 这个工具可以把远程主机的文件系统映射到本地主机上,透过 SSH 把远程文件系统挂载到本机上,这样我们可以不必使用 scp 工具就可以做到直接复制及删除远程主机的文件了,就像操作本地磁盘一样方便。
sshfs 是基于 FUSE 构建的 SSH 文件系统客户端程序,通过它远程主机的配置无需作任何改变,就可以透过 SSH 协议来挂载远程文件系统了,非常方便及安全。
首先安装epel的yum源方便安装
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
yum -y install sshfs

挂载远程 ssh 文件系统:

sshfs root@192.168.1.218:/home/ /mnt/
sshfs 用户名@远程主机IP:远程主机路径 本地挂载点
sshfs -o transform_symlinks -o follow_symlinks user@hostname: /home/username/sshfs
-o transform_symlinks 表示转换绝对链接符号为相对链接符号
-o follow_symlinks 沿用服务器上的链接符号

 

通过/etc/fstab 开机自动挂载

I was able to make sshfs mount via fstab with Ubuntu 14.04 by doing using the following syntax as a standard user (note anything in CAPS is a variable for you to fill in):

USER@HOST:/REMOTE_DIR /LOCAL_DIR fuse.sshfs delay_connect,_netdev,user,idmap=user,transform_symlinks,identityfile=/home/USERNAME/.ssh/id_rsa,allow_other,default_permissions,uid=USER_ID,gid=USER_GID 0 0
This is a combination of the information found here http://superuser.com/questions/669287/automount-sshfs-using-fstab-without-mount-a and adding the **delay_connect** from here http://askubuntu.com/questions/326977/sshfs-is-not-mounting-automatically-at-boot-despite-etc-fstab-configuration.

I used this tutorial to get my USER_ID and USER_GID: https://kb.iu.edu/data/adwf.html

To find a user’s UID or GID in Unix, use the id command. To find a specific user’s UID, at the Unix prompt, enter:

id -u username

Replace username with the appropriate user’s username. To find a user’s GID, at the Unix prompt, enter:

id -g username

树莓派的启动流程

为了降低成本,树莓派省去了传统计算机用来存储引导加载程序的板载存储器(BIOS), 而是直接把引导程序放在了SD卡中。
model-b-plus-Raspberry-Pi
树莓派B+模型图

树莓派具有一款博通的BCM2835系统芯片, 当启动时,ARM1176JZF-S的CPU会处于复位状态,由VideoCore IV GPU核心负责启动系统。启动的第一阶段, 从系统芯片中加载第一阶段的启动程序, 这个启动程序负责加载存放在SD卡中的第二启动程序(bootcode.bin)。bootcode.bin在VideoCore GPU上执行并加载第三阶段的启动器start.elf。 start.elf读取存放系统配置的文件config.txt。

当config.txt文件被加载解析之后, start.elf会读取cmdline.txt和kernel.img. cmdline.txt包涵内核运行的参数,而kernel.img将会被加载到处理器分配的共享内存中,当内核加载成功,处理器将结束复位状态,内核开始正式运行,系统启动正式开始。

启动流程:
1, 系统加电。
2, 加载系统芯片中的第一启动程序。
3, 第一启动程序加载SD卡上的bootcode.bin。
4, bootcode.bin执行,并加载第三阶段启动程序start.elf。
5, start.elf读取config.txt并加载内核。
6, config.txt解析完成,start.elf读取再次加载cmdline.txt文件,最后加载内核文件,然后CPU开始运行,系统启动成功。

参考:
1, Understanding the Raspberry Pi Boot Process

使用 PyInstaller 把python程序 .py转为 .exe 可执行程序

最近使用Python为项目开发一款绘图工具(绘出 声场三维模型)。因为希望能把Python脚本发布为脱离Python平台运行的可执行程序,比如单个的exe文件。PyInstaller恰满足这个需求。本文PyInstaller的版本是2.0,支持Python2.7。下面讨论怎样安装,使用PyInstaller。PyInstaller本身并不属于Python包。在安装 pyinstaller 之前假设你已经安装了python ,注意把python 环境变量配置好, 即 进入cmd后 输入 python 会进入 python shell.
pyinstaller安装:
1,下载pyinstaller并解压(可以去官网下载最新版):
2,安装最新版本的 pywin32-217.win32-py2.7.exe:
不然会出现错误Error: PyInstaller for Python 2.6+ on Windows needs pywin32.
3,进入cmd ,
d:\>cd d:\PyInstaller-2.1
d:\pyinstaller>python pyinstaller.py
Usage: python pyinstaller.py [opts] <scriptname> [ <scriptname> ...] | <specfile>
pyinstaller.py: error: Requires at least one scriptname file or exactly one .spec-file
以上信息表示可以开展工作了,以下是测试一个demo.py 文件的打包,文件放在当前目录的pyinstaller-2.1文件夹里面 .
d:\pyinstaller-2.1>python pyinstaller.py --console --onefile demo.py

上面的命令成功运行后demo.py 会生成一个demo文件夹。在这个文件夹下面会有一个名为dist的文件夹,此文件夹下面有转换好的demo.exe。

1

点击 demo.exe,首先会出来一个 控制台的黑窗口,如下图:

2
4, 上面编译出来的exe能够正常运行了,但带一个黑色的console,以下重新编译,加入--windowed --icon,取消--console
D:\PyInstaller-2.1>python pyinstaller.py -w --onefile --icon="my.ico" demo.py
icon是你喜欢的图标文件,py为你要打包的程序。最后生成一个demo.exe可执行文件,点击demo.exe直接显示所绘图形。

3