2017年3月15日 星期三

raspberry pi 用sharp GP2Y1014AU偵測空氣品質.

由於pi 沒有analog input. 所以必須要另外加MCP3008
「raspberry pi GPIO 腳位」的圖片搜尋結果

sharp GP2Y1014AU
21511649203037_699







參考用 gp2y1010au

PIN 1 接150歐姆電阻 電阻另一端接到5V(pi PIN 2)
           接16V 220uF. 負極端接地 (pi PIN 6)
PIN 2/4 接地 (pi PIN 6)
PIN 6 接 5V (pi PIN 2)
PIN 5 接MCP3008 CH0
PIN 3 接raspberry pi GPIO17/PIN 11

MCP 3008

MCP3008
PIN 16, 接pi 5V (pi PIN 2)
PIN 15, 接pi 5V (pi PIN 2)
PIN 14, PIN9 接 pi PIN 6
PIN 10, pi PIN 24 SPI0_CE0(GPIO8)
PIN 11, pi PIN 19 SPI0_MISI (GPIO10)
PIN 12, pi PIN 21 SPI0_MISO(GPIO9)
PIN 13, pi PIN 23 SCLK (GPIO 11)

pi 上確認
  有 sudo pip install spidev
  /boot/config.txt 有加以下兩行
   dtparam=spi=on
   dtparam=i2c_arm=on

測到數值:
  3000+ = very bad
  1050-3000 = bad
  300-1050 = normal
  150-300 = good
  75-150 = very good
  0-75 = best

python code :


import spidev
import time
import os
import RPi.GPIO as GPIO

# open(bus, device) : open(X,Y) will open /dev/spidev-X.Y
spi = spidev.SpiDev()
spi.open(0,0)

# Read SPI data from MCP3008, Channel must be an integer 0-7

#this function should remove " 
def ReadADC(ch):
    if ((ch ">" 7) or (ch "<" 0)):
       return -1
    adc = spi.xfer2([1,(8+ch)"<""<"4,0])
    data = ((adc[1]&3)"<""<"8) + adc[2]
    return data

# Convert data to voltage level
def ReadVolts(data):
  volts = (data * 5.0) / float(1023)
  return volts

# Define sensor channels
pm_ch = 0

# Define delay between readings
delay = 5
R1 = 17

#enable GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(R1,GPIO.OUT)

while True:
  #set GPIO R1 17
  GPIO.output(R1,GPIO.HIGH)

  # Read the temperature sensor data
  pm_data = ReadADC(pm_ch)
  pm_volts = ReadVolts(pm_data)
  pm_value = pm_volts * 0.17 - 0.1

  #disbale GPIO R1 17
  GPIO.output(R1,GPIO.LOW)

  # Print out results
  print "Read Data : ",pm_data,"volts : ",pm_volts," (",pm_value*1000,"ug/m3)"

# Delay seconds
time.sleep(delay)


2017年3月14日 星期二

逆止風門DIY

網路購入
廚房抽油煙機排煙管用逆止風門 : 850
浴廁使用 : 390

使用膠帶纏繞就可以完成. 防止外面風灌進來, 蚊蟲飛入.

2015年11月2日 星期一

家用電腦更新

老爸用那台監視機.
更換主機板, 記憶體.
原本是asus M3A78-CM + kingston 2G DDR2-800.
換 asus m5a78l-m/usb3 + kingston 4G DDR3-1600

之前換過cpu. 保內送修amd althon 5050e. 換回amd althon2 250.
所以能續用cpu.
主機板跟記憶體是2009年購入. 都是24hrs 不關機使用.

2014年11月17日 星期一

install unrar on raspberry pi

Download and unpack
___ wget http://www.rarlab.com/rar/unrarsrc-4.2.4.tar.gz
___ gunzip -v unrarsrc-4.2.4.tar.gz
___ tar -xvf unrarsrc-4.2.4.tar
Compile
___ cd unrar/
___ make -f makefile.unix
Install
___ sudo cp unrar /usr/local/bin
Configure alternatives to point to my unrar instead of the unrar-free
___ sudo update-alternatives --install /usr/bin/unrar unrar /usr/local/bin/unrar 10
___ update-alternatives --display unrar
___ sudo update-alternatives --config unrar

raspberry b+ 入手

raspberry b+ 入手.
壓克力殼 + toshiba變壓器 + 兩小片散熱片.  => 1425元 (含7-11取貨付款30元)
另外買了創見16G c10 micro sd. (259元)
b+ usb有四孔. 可hot plug. (b板只有2孔不能hot plug)

準備架webcam stream server.
1 usb : wifi adapter
3 usb : web cam

耗電應該在10W 內.