2016年2月19日 星期五

在Raspberry 上面使用ADXL345



Step 1: Setting up the Raspberry pi for the ADXL 345

ADXL 345 pin out 圖

 RPI GPIO 圖

The ADXL345 supports both I2C and SPI connections, I used I2C, which requires some configuration on the Pi:
使用I2C 來連線.....

Use the GPIO diagram above to help with the wiring
GND - GND 
3V - 3V3
SDA - SDA
SCL - SCL
check 一下系統有沒有把I2C關掉

Add the I2C modules to the Pi's configuration:
sudo nano /etc/modules
Then add the following lines:
i2c-bcm2708
i2c-dev
Remove I2C from the blacklist:
sudo nano /etc/modprobe.d/fbdev-blacklist.conf
Change this:
blacklist i2c-bcm2708
To this:
#blacklist i2c-bcm2708
Reboot to make the changes:
sudo reboot

Step 2: Installing the Stuff


You will need to install smbus:
sudo apt-get install python-smbus i2c-tools git-core
Now test the ADXL345 is found on the I2C bus by running:
sudo i2cdetect -y 1

看的出來address 0x53的地方有device....

如果沒有看到0x53...代表你線接錯了...或是i2c關掉了

Now download from
不太會使用gitcore.....  所以我從網頁右上角有個 Download Zip..... 按下... 然後用ftp 傳到RPI...


cd adxl345-python-master
Then write:
sudo python example.py
If you get 0.000G for all axis then something probably isn't set up correctly.

看一下  example.py
from adxl345 import ADXL345

adxl345 = ADXL345()

axes = adxl345.getAxes(True)
print "ADXL345 on address 0x%x:" % (adxl345.address)
print "   x = %.3fG" % ( axes['x'] )
print "   y = %.3fG" % ( axes['y'] )
print "   z = %.3fG" % ( axes['z'] )

解釋如下 :



#import the adxl345 module
import adxl345
#create ADXL345 object 
accel = adxl345.ADXL345()
#get axes as g 
axes = accel.getAxes(True) 
# to get axes as ms^2 use  
axes = accel.getAxes(False)
#put the axes into variables 
x = axes['x'] 
y = axes['y'] 
z = axes['z']
#print axes 
print x 
print y 
print z
Change the program for fun!
The default range is 2g which means that the maximum G the ADXL345 can measure is 2.048, but at a high degree of sensitivity.
You can change the sensitivity of the ADXL345 by using the .setRange() method of the class.

這邊還有另外一個sample code

Firstly download their file from:
From there download the User manual(Super Kit for Pi) and the Code and Frizting(Super kit for Pi)

會看到兩個code ...


也是可以參考一下......  

Reference : http://www.instructables.com/id/how-to-use-the-ADXL345-on-Raspberry-pi/

2016年2月17日 星期三

如何在Raspberry 上面打中文



首先執行
sudo raspi-config
更改系統的語系(locale)。

選擇「Internationalisation Options」。




選擇「Change Locale」。


zh_TW 開頭的就是台灣的中文語系,您可以依照自己的需求選擇編碼,除非有特別需要,不然選「zh_TW.UTF-8」應該就夠了。



英文的語系也是常會用到的,也可以順便選一下。

接著要設定系統預設的語系,如果您都是習慣使用 X Window 環境的人,可以直接選擇zh_TW.UTF-8,但如果您像我一樣有時候會在 console 下工作的話,就建議選擇en_US.UTF-8,這樣在 console 下面才不會因為沒有中文字型產生亂碼。




接著安裝酷音中文輸入法:
sudo apt-get install -y scim-chewing

Reference : http://blogger.gtwang.org/2014/12/raspberry-pi-chinese-input-method.html

如何在Raspberry上面截圖


如果是在 X Window 下,最簡單的方式是安裝 shutter,但這有兩個缺點,就是 shutter相依的套件太多,所以光是截圖這個小功能就需要安裝將近 90MB 的套件,並且執行起來很慢,但使用最容易。

安裝時間有點久....

pi@raspberrypi:~$ sudo apt-get -y install shutter




Accessorise ->  Shutter


點選你的範圍....然後按下 Enter....就會截圖了....然後另存新檔....

如果覺的 shutter 不適合,還可以用 scrot + openbox,之後就可以按 PrtSc 直接做 snapshot。有關 scrot 的使用方式可以參考這篇。

在terminal  windows 使用...
  1. 抓取桌面:scrot desktop.png,该命令将当前的整个桌面抓取下来,并保存为 desktop.png 文件。可以在当前的目录中找到此图像文件。
  2. 抓取窗口:scrot -bs window.png,选项 b 使 scrot 在抓取窗口时一同将外边框抓取下来,而 s 选项则让用户选择所要抓取的是何窗口。
  3. 抓取区域:scrot -s rectangle.png,在执行此命令后,使用鼠标拖曳的矩形区域将被 scrot 抓取下来。

Reference : https://www.raspberrypi.com.tw/960/snapshot-on-raspberry-pi/

2016年2月16日 星期二

ublox neo-6m gps raspberry pi


明天來實做看看



Reference : https://bigdanzblog.wordpress.com/2015/01/18/connecting-u-blox-neo-6m-gps-to-raspberry-pi/

Raspberry 使用固定ip..... pppoe

首先你要先去中華電信的網頁申請固定IP加浮動IP..... (比較便宜的方案... 但比較不穩定)

http://service.hinet.net/2004/adslstaticip.php

按下申請....不用錢....

然後他就會秀出你的固定ip.....

接下來就是在RPI那端使用pppoe的連線方式來連線....

使用 pppoeconf 套件


直接從官方套件庫安裝 PPPoE 撥接程式。
sudo apt-get -y install pppoeconf


準備設定撥接參數。
sudo pppoeconf

輸入撥接帳號。
XXXXX@ip.hinet.net

輸入撥接密碼
your_password....

如果帳號跟密碼忘了....就是跑一趟中華電信吧....像我今天就是

最後執行結果如下:






http://blog.itist.tw/2015/02/raspberry-pi-pppoe-connection.html

在cmd line的模式下來超頻 on raspberry



sudo vi /boot/config.txt
In this file, you’ll want to add the following two lines:
arm_freq=800
sdram_freq=500

reboot ....and check this frequency by

vcgencmd get_config arm_freq
and it should be

arm_freq=800

Maybe you could use

sudo raspi-config












Again to check it, you can type in
vcgencmd get_config arm_freq
and it should say:
arm_freq=800
You can also check more options by typing:
vcgencmd get_config int
And it should look like this:
arm_freq=800
core_freq=250
sdram_freq=500
disable_overscan=1
boot_delay=1
temp_limit=85
Enjoy! 




Reference : https://www.jeremymorgan.com/tutorials/raspberry-pi/how-to-overclock-raspberry-pi/

設定 keyboard 的方法on terminal


如果當你設置keyboard後....發覺要打pi  變成不是pi  例如  60 時

這時候你就會需要用到這一招了...

用nb 遠端連線進去RPI.....


有兩種方式可以重新改變keyboard setting...

method 1:

vi  /etc/default/keyboard
內容如下:
XKBMODEL="pc105"
XKBLAYOUT="tw"
XKBVARIANT=""
XKBOPTIONS="lv3:alt_switch,terminate:ctrl_alt_bksp"

BACKSPACE="guess"

直接去修改....



method 2: 利用tool 去啟動 keyboard configuration

You can change the setting for default system keyboard hardware (e.g. "Generic 105-key keyboard"to "Generic 101-key keyboard") and also the system keyboard layout (e.g. "us-intl" to "us") with the command
sudo dpkg-reconfigure keyboard-configuration
我是選  pc 105 鍵  ->  taiwaniness  -> both....  ->  no 組合鍵

method 3 :  使用  raspi-config  -> keyboard....有時候這個怪怪的