[RPi] 为树莓派添加DIY智能散热风扇

普通散热风扇只有两个线,即VCC电源以及GND接地,而树莓派的GPIO最大只能输出几十毫安,所以根本无法直接通过GPIO来控制风扇。
所以,我们需要加装一个三极管使用小电流来控制大电流。

三极管在很多旧设备里面可以找到,这里以 1AM 示例(从USB支付钥匙拆的)。然后以以下示意图接上三极管。

GitHub: https://github.com/xswxm/Smart_Fan_for_Raspberry_Pi.git

这次一共写了两个版本,一个是普通版本,只能开关风扇,另一个PWM版本支持PWM调速。笔者的风扇使用PWM调速时,能够良好的工作,但有滋滋的噪声,这可能与风扇的质量有关,或许也可以后期改进电路解决。

sudo apt-get update
sudo apt-get install python python-dev python-pip
# 安装模块
sudo pip install rpi.gpio
sudo apt-get install pigpio python-pigpio
# 查看帮助文档
python fan.py -h
# 以默认配置运行
python fan.py
# 后台运行
nohup python fan.py &
# 设置pin为24,每2秒检测一下CPU温度,若超过50度则开启风扇
python fan.py -t 50 -i 2 -p 24
# 启用 pigpio 服务
sudo pigpiod
# 查看帮助文档
python fan_pwm.py -h
# 以默认配置运行
python fan_pwm.py
# 后台运行
nohup python fan_pwm.py &
# 设置pin为24,每2秒检测一下CPU温度,若超过50度则开启风扇,同时设置温度每增加1摄氏度,风扇速度增加10%
python fan_pwm.py -t 50 -i 2 -p 24 -s 10

[RPi] 树莓派添加samba文件共享服务

1. 安装Samba

sudo apt-get install samba samba-common-bin

2. 为samba添加用户,可以使用现有账户,也可以创建专属账户

添加专属账户(如果你只想要添加已存在的账户,可以跳过这一步)

# 添加账户,username即你想要添加的账户名
sudo useradd username
# 建立共享文件夹即修改用户组
sudo mkdir -p /home/username
sudo chown -R username:username /home/username/

为samba添加账户

# 添加账户,username是你想要添加到samba的账户,该步骤会要求设置密码,需要注意的是如果你samba下的用户名的密码区别于树莓派系统下的用户名的密码
sudo smbpasswd -a username

3. 修改配置文件

# 对原配置文件做一备份
sudo mv /etc/samba/smb.conf /etc/samba/smb.conf.bak
# 创建一个新的配置文件
sudo nano /etc/samba/smb.conf

配置文件可以照如下修改,然后按 Ctrl+o 保存,Ctrl+x退出

[pi]
    comment= My Samba
    path = /home/username
    valid users = username
    browseable = yes
    writable = yes

部分参数解释:
pi: 显示的名称
comment: 显示名称下的注释
path: 共享的路径
vaild users: 具有操作权限的用户名
browseable: 是否可以浏览
writable: 是否可以写入

4. 重启samba服务

sudo service smbd restart

5. 使用samba服务

Windows用户: 打开计算机,在地址栏输入 ‘\\youripaddress\’(不含引号,youripaddress是你的树莓派IP地址)即可找到共享的文件夹
Linux用户: 打开文件浏览器,在地址栏 ‘smb://youripaddress/’(不含引号,youripaddress是你的树莓派IP地址)即可
输入对应的用户名和密码即可浏览操作拥有权限的文件及文件夹

[12864/SSD1306] Play Snake on Raspberry Pi

System Monitor for Raspberry Pi with 12864/SSD1306, and you can download all the files from GitHub.

Demo
Demo

Setting Up
Configure your 128464 by following this tutorial: https://learn.adafruit.com/ssd1306-oled-displays-with-raspberry-pi-and-beaglebone-black/usage?view=all

# Ports used for the Display. You may have to change them to yours
RST = 25
DC = 24
# Configurations of this game
# You may check the preference below and alter the values if you want
display_interval = 0.05                # Refresh display every 0.05 second => FPS = 20
size = 2                               # Size of a snake, 2 means one point occupies four pixels (2x2)
# Initialize the boundary of the gaming area
area = (0, 0, disp.width*2/3/size-1, (disp.height-2)/size-1)    # Gameing area in points with size
boundary = (0, 0, (area[2]+1)*size+1, (area[3]+1)*size+1)       # Gameing boundary
boundary_cross = True                  # snake is able to cross the boundary 
# Block setting
block_mode = False                     # Do not create blocks
# Initialize a snake
snake = []                             # snake
snake0 = (area[2]/2, area[3]/2)        # snake's head (first pixel)
snake1 = snake0                        # snake's tail (last pixel)
l = 4                                  # snake's length = 4
interval_max = 1
interval_min = 0.05
interval = interval_max                # move the snake every 1 second
direction = (1, 0)                     # direction = Right
food = snake0                          # normal food
food_score = 1                         # each food worth 1 score
sfood = ()                             # initialize a empty special food
sfood_lifetime = 10                    # special food exists for 10 seconds
sfood_count = 0                        # to count the time of the special food
sfood_interval = 0.25                  # refresh the special food every 0.25 second
sfood_time = 30                        # Possible to generate a special food every 30 seconds
sfood_score = 5                        # each special food worth 5 scores
blocks = []                            # blocks for blocking the snake
scores = [0, 10, 50, 100, 150, 250, 350, 550, 750, 950, 1200]
levels = [0, 1,  2,  3,   4,   5,   6,   7,   8,   9,   10]
score = 0
level = 0

How to Use

# Run directly with diffculity = 0
sudo python snake.py
# Run directly with diffculity = 1
sudo python snake.py 1
# Run directly with diffculity = 2
sudo python snake.py 2

How to Play
Control: Press ‘w’, ‘a’, ‘s’, ‘d’
Speed up/remove effect: Press ‘q’
Exit game: Press ‘x’

License
—-
MIT

[12864/SSD1306] System Monitor for Raspberry Pi

System Monitor for Raspberry Pi with 12864/SSD1306, and you can download all the files from GitHub.

Demo
Demo

Modules
Adafruit_GPIO.SPI
Adafruit_SSD1306
psutil

Setting Up
Configure your 128464 by following this tutorial: https://learn.adafruit.com/ssd1306-oled-displays-with-raspberry-pi-and-beaglebone-black/usage?view=all

sudo apt-get install python-pip
sudo pip install psutil
# Ports used for fthe Display. You may have to change them to yours
RST = 25
DC = 24

How to Use

python disp.py

License
—-
MIT

[12864/SSD1306] Video Player

It is a python script for playing videos on 12864 over SPI sockets, and you can download all the files from GitHub.

Demo

Modules
Adafruit_GPIO.SPI
Adafruit_SSD1306

Setting Up
Configure your 128464 by following this tutorial

sudo apt-get install python-pip
sudo apt-get install python-pygame
sudo pip install opencv-python
# Ports used for the Display. You may have to change them to yours
RST = 25
DC = 24

How to Use

# sudo python player.py file_path
# Play BadApple.zip
sudo python player.py BadApple.zip

Convert a video
I provided a m file for matlab for converting videos while you can also convert any videos with opencv

[MyIoT] A start with personal server for home automation

What is myIoT:
1. myIoT is a solution for home automation, it can be implemented on your Raspberry Pi. And it theoretically can enable you to control devices (include other embedded devices connected to the server) and acquire info of these devices.
2. It is currently based on python (sever part) and Android (Client)
3. It can process HTTPS and Socketio requests.

Github link: https://github.com/xswxm/MyIoT

It currently can handle HTTPS and Socketio requests, UDP could be patched to it later so we can do some fancy things like having audio or video conversations, just blow you image and it can control everything.

Screenshots:

Raspberry Pi:Raspbian安装XBMC(译)

之前有看过各种关于在Raspbian上安装XBMC的方法,有用添加密钥破解安装的,也有在Pi上编译的(我去,我绝对不敢干这事了,在Pi上编译大文件,简直就是浪费青春),但作者实测的效果不尽人意,要么就是没编译成功,就算安装上了也容易假死。。。。好吧,但是我还是没死心,抱着试一试的态度搜遍论坛,找到了这篇教程,安装好后感觉很好,可以说没死机过,轻微的小卡属于正常,之前安装Raspbmc和Openelec都是这样的,毕竟Pi的CPU性能有限。好吧,不废话了,下面就开始教程(翻译)。

原文:XBMC for Raspberry Pi

1 安装

sudo /etc/apt/sources.list.d/mene.list

deb http://archive.mene.za.net/raspbian wheezy contrib
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key 5243CDED
sudo apt-get update
sudo apt-get install xbmc

2  配置

audio video input dialout plugdev tty

大部分情况下以上的用户组都是存在的,假如万一你的Pi上没input这个用户组,则可以使用下面命令来添加用户组:

addgroup --system input
sudo usemod -a -G tty pi  #注意一定要有–a,不然Pi就只存在于tty这个用户组了
sudo /etc/udev/rules.d/99-input.rules

SUBSYSTEM=="input", GROUP="input", MODE="0660"

KERNEL=="tty[0-9]*", GROUP="tty", MODE="0660"
sudo raspi-config
# 进入Advanced选项修改显存为128MB,切记一定要改大,不然默认的64MB显存直接卡爆。

3  运行

sudo nano /etc/default/xbmc
# 首先将“USER=xbmc”改为“USER=pi”,pi是你的用户名。
# 如果需要开机启动则将“ENABLED=0”改为“ENABLED=1”
sudo service xbmc start

sudo service xbmc stop

Raspberry Pi:解决硬盘自动挂载和Transmission下载提示Permission Denied的问题

由于接触linux不久,很多问题都要不断摸索。
这次主要是Transmission提示Permission Denied无法创建文件了,干脆就连硬盘自动挂载一起解决了。。

1  硬盘自动挂载

df -h
/dev/sda1       /media/HDD0     vfat    defaults          0       0
/dev/sda5       /media/HDD1     ext4    defaults          0       0

第一排是挂载的磁盘,第二行是挂载的目录,第三行是挂载磁盘的文件格式,我的硬盘被我分了两个区,分别是fat格式和ext4格式的,第四行一般就defaults,第五行0,第六行是挂载是否扫描,0的话就不扫描,其它数字就是扫描,扫描顺序数字越大越后扫描,一般的话0就好,不然扫描要好久的。。。

2  下载目录权限设置

ls -l 下载目录
-wrxwrxwrx A B......  #w:写入;r:读取;x:执行
# A是所属用户,B是所属用户组,第一个wrx是A的权限,第二个wrx是B的权限,第三个就是其他用户的权限。
sudo chmod u=rwx,g=rwx,o=rwx 下载目录  #u = user; g = group; o = others, rwx自行修改

重启下就啥都解决啦。。