
media_dir=A,/samba/DLNA/Music #A表示这个目录是存放音乐的,当minidlna读到配置文件时,它会手动加载这个目录下的音乐文件
media_dir=P,/samba/DLNA/Picture
media_dir=V,/samba/DLNA/Video
db_dir=/samba/DLNA/db #配置minidlna的数库数据的存放目录
log_dir=/samba/DLNA/log #配置日志目录
#=======================================================================================
在/samba文件夹下,建立以下文件夹,并修改好权限为read and write。
/etc/init.d/minidlna restart
测试:
/etc/init.d/minidlna status
返回如下结果为正常。

先在树莓派以上对应的video等文件夹内存上一些文件(可借助samba直接从电脑上考入),然后返回到计算机进行操作。
点击我的手机上面的网络,出现媒体设备

双击开启媒体播放器,在上面的列表栏下方其它媒体库中出现raspberrypi:root,点击后,可选取音乐树莓派 音乐播放器,视频等。

这时双击就可以欣赏了。
手机上推动网络共享,可安装es file explorer工具,在其网络处进行修改,设置方式与电脑基本一样,这里不再详述。设置后,文件均可浏览,媒体文件双击可以播放。
也可以直接使用updp播放器,这里我安装的是moliplayer,可以在其附近设备里,直接找到raspberrypi:root,访问其媒体问题,注意,这里是访问的DLNA共享,所以不需要再输入密码。
智能电视一般都是用的android平台,与手机基本一样。
更新一下安装源

sudo apt-get update
安装aria2
sudo apt-get install aria2
在/etc目录下构建aria2目录用来保存配置文件:
sudo mkdir /etc/aria2
创建空白的aria2.session文件:
sudo touch /etc/aria2/aria2.session
创建配置文件
sudo nano /etc/aria2/aria2.conf
在该文件中输入下面内容:
#=========文件保存目录自行设置
dir=/samba
disable-ipv6=true
#打开rpc的目的是为了给web管理端用
enable-rpc=true
rpc-allow-origin-all=true
rpc-listen-all=true
#rpc-listen-port=6800
continue=true
input-file=/etc/aria2/aria2.session
save-session=/etc/aria2/aria2.session
max-concurrent-downloads=3

这里为了便于共享,我直接修改将文件下载到samba共享文件夹。
sudo aria2c --conf-path=/etc/aria2/aria2.conf
如果没有提示任何出错信息,那就按ctrl+c停止上面的语句,转为后台运行:
sudo aria2c --conf-path=/etc/aria2/aria2.conf -D
同时其此句提到开机开启中,编辑/etc/rc.loca,如下

为了能web管理aria2进行下载,需要调试yaaw和apache环境。
安装appach
sudo apt-get install apache2
修改/var/www的权限
chmod 777 /var/www
从下载yaaw,点击右下角的
,下载后将解压后的文件夹内内容拷贝到/var/www文件夹下。这时键入树莓派IP,如果出现下面页面,则表示即将正常工作了。

这里可以点add添加下载任务,具体步骤不再详述。
很多网站都介绍了aria2实现迅雷离线下载的方式,这里也做一下描述。我以firefox浏览器为例,chrome浏览器本身有一个迅雷离线增加软件,可以从%E8%BF%85%E9%9B%B7%E7%A6%BB%E7%BA%BF%E5%A2%9E%E5%BC%BA%E8%84%9A%E6%9C%AC/bcbkegabebafalcgckcdphlpainejkja进行安装,安装后就和firefox基本一样了。
在firefox里添加一个书签:

具体为:
===========================================================
名称为:ThunderLixianExporter
地址为:javascript:void((function(){var d=document;var s=d.createElement('script');s.src='http://s.binux.me/tle.js';s.id='TLE_script';d.body.appendChild(s)})())
==================================================================

登录迅雷离线网站:lixian.xunlei.com,登录后,点一下书签中的ThunderLixianExporter,然后单击迅雷页面右上角的配置图标(小齿轮)。



在里面的窗口中填写aria2.json-RPC Path,这个值来自于yaaw那个页面,具体步骤是,输入树莓派IP显示yaaw页面,点击右上的配置界面,如下图

在set页面中存在该值:

保存好后,在离线页面的每行记录的取回本地后面会出现一个下拉菜单,选择yaaw就会直接添加到yaaw任务中了。


到此树莓派 音乐播放器,树莓派的NAS服务器搭建完成,试了一下效果,还是很满意的。
直接从家里找了一个orico的包装盒,大小刚好适合,而且壳子非常硬,外观也相当不错。
加装一个1602显示屏,目的是显示时间和CPU温度,当然也可以显示其他内容,我此处只显示了这两项。这里还必须加装一个电位器(也就是可变电容,如果没有,可以加一个10K的电阻)
1602共16个端口,只用其中12个,具体接法如下:
LCD1602液晶屏模块提供了16个引脚,我们只需接其中的12个即可:
VSS,接地
VDD,接5V电源
VO,液晶对比度调节,接电位器中间的引脚,电位器两边的引脚分别接5V和接地。
RS,寄存器选择,接GPIO14
RW,读写选择,接地,表示写模式
EN,使能信号,接GPIO15

D0,数据位0,4位工作方式下不用,不接
D1,数据位1,4位工作方式下不用,不接
D2,数据位2,4位工作方式下不用,不接
D3,数据位3,4位工作方式下不用,不接
D4,数据位4,接GPIO17
D5,数据位5,接GPIO18
D6,数据位6,接GPIO27
D7,数据位7,接GPIO22
A,液晶屏背光+,接5V
K,液晶屏背光-,接地
注意:1、这里的VSS、VDD等在有些1602的板子上会标明,有些则只标了数字,如一端写着1,一端写着16,1对应的就是VSS端,16对应的就是K端,因此依次连接就可以了。
2、GPIO各端口及5V、接地等端口见图示,因为我用的是B+的板了,因此此处的图只是B+的端口图。
3、连接通电后,1602会亮起,其中一行为白色方格,一行什么也不显示,如果全不显示,可调节一下电位器

对于1602板子的操作,已经有人做了一个示例,这样用出来就非常简洁了。示例代码下载地址:,解压后有Adafruit_CharLCD.py文件,此文件在LCD上会显示两行字符:LCD 1602 Test, 123456789ABCDEF。这里只应该在此文件上进行一下修改就可以了。
#!/usr/bin/python
#转载请注明:@小五义http://www.cnblogs.com/xiaowuyi QQ群:64770604
#
# based on code from lrvick and LiquidCrystal
# lrvic - https://github.com/lrvick/raspi-hd44780/blob/master/hd44780.py
# LiquidCrystal - https://github.com/arduino/Arduino/blob/master/libraries/LiquidCrystal/LiquidCrystal.cpp
#
#from time import sleep
import time,os
class Adafruit_CharLCD:
# commands
LCD_CLEARDISPLAY = 0x01
LCD_RETURNHOME = 0x02
LCD_ENTRYMODESET = 0x04
LCD_DISPLAYCONTROL = 0x08
LCD_CURSORSHIFT = 0x10
LCD_FUNCTIONSET = 0x20
LCD_SETCGRAMADDR = 0x40
LCD_SETDDRAMADDR = 0x80
# flags for display entry mode
LCD_ENTRYRIGHT = 0x00
LCD_ENTRYLEFT = 0x02
LCD_ENTRYSHIFTINCREMENT = 0x01
LCD_ENTRYSHIFTDECREMENT = 0x00
# flags for display on/off control
LCD_DISPLAYON = 0x04
LCD_DISPLAYOFF = 0x00
LCD_CURSORON = 0x02
LCD_CURSOROFF = 0x00
LCD_BLINKON = 0x01
LCD_BLINKOFF = 0x00
# flags for display/cursor shift
LCD_DISPLAYMOVE = 0x08
LCD_CURSORMOVE = 0x00
# flags for display/cursor shift
LCD_DISPLAYMOVE = 0x08
LCD_CURSORMOVE = 0x00
LCD_MOVERIGHT = 0x04
LCD_MOVELEFT = 0x00
# flags for function set
LCD_8BITMODE = 0x10
LCD_4BITMODE = 0x00
LCD_2LINE = 0x08
LCD_1LINE = 0x00
LCD_5x10DOTS = 0x04
LCD_5x8DOTS = 0x00
def __init__(self, pin_rs=14, pin_e=15, pins_db=[17, 18, 27, 22], GPIO = None):
# Emulate the old behavior of using RPi.GPIO if we haven't been given
# an explicit GPIO interface to use
if not GPIO:
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
self.GPIO = GPIO
self.pin_rs = pin_rs
self.pin_e = pin_e
self.pins_db = pins_db
self.GPIO.setmode(GPIO.BCM)
self.GPIO.setup(self.pin_e, GPIO.OUT)
self.GPIO.setup(self.pin_rs, GPIO.OUT)
for pin in self.pins_db:
self.GPIO.setup(pin, GPIO.OUT)
self.write4bits(0x33) # initialization
self.write4bits(0x32) # initialization
self.write4bits(0x28) # 2 line 5x7 matrix
self.write4bits(0x0C) # turn cursor off 0x0E to enable cursor
self.write4bits(0x06) # shift cursor right
self.displaycontrol = self.LCD_DISPLAYON | self.LCD_CURSOROFF | self.LCD_BLINKOFF
self.displayfunction = self.LCD_4BITMODE | self.LCD_1LINE | self.LCD_5x8DOTS
self.displayfunction |= self.LCD_2LINE
""" Initialize to default text direction (for romance languages) """
self.displaymode = self.LCD_ENTRYLEFT | self.LCD_ENTRYSHIFTDECREMENT
self.write4bits(self.LCD_ENTRYMODESET | self.displaymode) # set the entry mode
self.clear()
def begin(self, cols, lines):
if (lines > 1):
self.numlines = lines
self.displayfunction |= self.LCD_2LINE
self.currline = 0
def home(self):
self.write4bits(self.LCD_RETURNHOME) # set cursor position to zero
self.delayMicroseconds(3000) # this command takes a long time!
def clear(self):
self.write4bits(self.LCD_CLEARDISPLAY) # command to clear display
self.delayMicroseconds(3000) # 3000 microsecond sleep, clearing the display takes a long time
def setCursor(self, col, row):
self.row_offsets = [ 0x00, 0x40, 0x14, 0x54 ]
if ( row > self.numlines ):
row = self.numlines - 1 # we count rows starting w/0
self.write4bits(self.LCD_SETDDRAMADDR | (col + self.row_offsets[row]))
def noDisplay(self):
""" Turn the display off (quickly) """
self.displaycontrol &= ~self.LCD_DISPLAYON
self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol)
def display(self):
""" Turn the display on (quickly) """
self.displaycontrol |= self.LCD_DISPLAYON
self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol)
def noCursor(self):
""" Turns the underline cursor on/off """
self.displaycontrol &= ~self.LCD_CURSORON
self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol)
def cursor(self):
""" Cursor On """
self.displaycontrol |= self.LCD_CURSORON
self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol)
def noBlink(self):
""" Turn on and off the blinking cursor """
self.displaycontrol &= ~self.LCD_BLINKON
self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol)
def noBlink(self):
""" Turn on and off the blinking cursor """
self.displaycontrol &= ~self.LCD_BLINKON
self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol)
def DisplayLeft(self):
""" These commands scroll the display without changing the RAM """
self.write4bits(self.LCD_CURSORSHIFT | self.LCD_DISPLAYMOVE | self.LCD_MOVELEFT)
def scrollDisplayRight(self):
""" These commands scroll the display without changing the RAM """
self.write4bits(self.LCD_CURSORSHIFT | self.LCD_DISPLAYMOVE | self.LCD_MOVERIGHT);
def leftToRight(self):
""" This is for text that flows Left to Right """
self.displaymode |= self.LCD_ENTRYLEFT
self.write4bits(self.LCD_ENTRYMODESET | self.displaymode);
def rightToLeft(self):
""" This is for text that flows Right to Left """
self.displaymode &= ~self.LCD_ENTRYLEFT
self.write4bits(self.LCD_ENTRYMODESET | self.displaymode)
def autoscroll(self):
""" This will 'right justify' text from the cursor """
self.displaymode |= self.LCD_ENTRYSHIFTINCREMENT
self.write4bits(self.LCD_ENTRYMODESET | self.displaymode)
def noAutoscroll(self):
""" This will 'left justify' text from the cursor """
self.displaymode &= ~self.LCD_ENTRYSHIFTINCREMENT
self.write4bits(self.LCD_ENTRYMODESET | self.displaymode)
def write4bits(self, bits, char_mode=False):
""" Send command to LCD """
self.delayMicroseconds(1000) # 1000 microsecond sleep
bits=bin(bits)[2:].zfill(8)
self.GPIO.output(self.pin_rs, char_mode)
for pin in self.pins_db:
self.GPIO.output(pin, False)
for i in range(4):
if bits[i] == "1":
self.GPIO.output(self.pins_db[::-1][i], True)
self.pulseEnable()
for pin in self.pins_db:
self.GPIO.output(pin, False)
for i in range(4,8):
if bits[i] == "1":
self.GPIO.output(self.pins_db[::-1][i-4], True)
self.pulseEnable()
def delayMicroseconds(self, microseconds):
seconds = microseconds / float(1000000) # divide microseconds by 1 million for seconds
time.sleep(seconds)
def pulseEnable(self):
self.GPIO.output(self.pin_e, False)
self.delayMicroseconds(1) # 1 microsecond pause - enable pulse must be > 450ns
self.GPIO.output(self.pin_e, True)
self.delayMicroseconds(1) # 1 microsecond pause - enable pulse must be > 450ns
self.GPIO.output(self.pin_e, False)
self.delayMicroseconds(1) # commands need > 37us to settle
def message(self, text):
""" Send string to LCD. Newline wraps to second line"""
for char in text:
if char == '\n':
self.write4bits(0xC0) # next line
else:
self.write4bits(ord(char),True)
if __name__ == '__main__':
while 1:
lcd = Adafruit_CharLCD()
lcd.clear()
cputemp=os.popen('vcgencmd measure_temp').readline()
sumcputemp=cputemp.replace("temp=","CPU:").replace("'C\n","")
lcdout=time.strftime('%Y-%m-%d %H:%M',time.localtime(time.time()))+"\n"+sumcputemp
lcd.message(lcdout)
time.sleep(30)
将以下文件命名为1602.py,保存在/home/pi下面,修改/etc/rc.loca,添加上sudo python /home/pi/1602/py。树莓派开机时,插上电源,当1602能正常显示CPU温度时,表示机器即将开启完成,各项功能可正常使用。
(1)本想再安装一个风扇用来散热,结果手上没有3.3V的风扇了,所以就没加。感兴趣的同学可以自己加一下,因为树莓派输出为3.3V,所以最好是直接买3.3V的,如果买5V的,就一定要带个3.3V的继电器,要不只能对风扇控制。如果风扇依然常开那就无所谓了,5V就可以,直接接正负级。我当时的看法是CPU上了50度,风扇再运转,这样可以降温,同时声音也不会大。
(2)这个家庭服务器搭建出来之后,后面也有好多文章可做,比如可以借助他制定家庭监控平台,装上两个什么的,也可以做一些外网访问的修改,这样就可以直接从外网进行操作了。
1、树莓派变身Aria2下载服务器:
2、树莓派搭建NAS服务器:
3、DIY一套NAS+私有云盘+下载机:
4、树莓派变身Aria2下载服务器:
5、打造增强型Raspberry Pi-液晶屏篇
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/bofangqi/article-122943-1.html
真是的
对歌曲中的“爱你不后悔
国家的概念除了在生死存亡之时格外强烈外