Last active
May 1, 2019 20:25
-
-
Save nunnun/a705db6a168a4d832f64 to your computer and use it in GitHub Desktop.
サブゼミメモ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://astrobeano.blogspot.jp/2014/01/gy-80-orientation-sensor-on-raspberry-pi.html | |
以下のコマンドを実行 | |
sudo -s | |
echo "i2c-bcm2708" >> /etc/modules | |
echo "i2c-dev" >> /etc/modules | |
sed -i "s/^blacklist/#blacklist/g" /etc/modprobe.d/raspi-blacklist.conf | |
apt-get install i2c-tools python-smbus | |
exit | |
その後 | |
sudo reboot | |
再起動。再起動が終わったら、 | |
sudo i2cdetect -l | |
で結果を確認 | |
続き | |
sudo i2cdetect -y 1 | |
を確認して、70の列に77が有ればOK | |
sudo usermod -a -G i2c pi | |
その後再起動 | |
データを取得するための必要なソースを準備 | |
mkdir ~/src | |
cd ~/src | |
git clone https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code.git | |
git clone https://github.com/bashardawood/L3G4200D-Python | |
温度を確認(BMP085) | |
python ~/src/Adafruit-Raspberry-Pi-Python-Code/Adafruit_BMP085/Adafruit_BMP085_example.py | |
加速度を確認(ADXL345) | |
python ~/src/Adafruit-Raspberry-Pi-Python-Code/Adafruit_ADXL345/Adafruit_ADXL345.py | |
終了するにはCtrl+c | |
ジャイロを確認(L3G4200D) | |
python ~/src/L3G4200D-Python/gyro.py | |
終了するにはCtrl+c | |
Webサーバを構築してみる | |
1. 必要なパッケージをインストール | |
sudo apt-get install apache2 libapache2-mod-python | |
2. Apacheを再起動 | |
sudo /etc/init.d/apache2 restart | |
3. Webサーバにアクセスできるか確認 | |
ブラウザを開いて、自分のIPアドレスを打って、 | |
"It works!"って表示されればOK | |
4. なんかファイルを置いてみよう | |
cd /var/www | |
sudo nano test.html | |
適当にファイルを書いて保存 | |
その後ブラウザを開いてhttp://[自分のIPアドレス]/test.htmlにアクセスして確認 | |
5. Pythonを実行出来るようにする | |
sudo nano /etc/apache2/sites-available/default | |
<Directory /var/www/>の次の行に、 | |
AddHandler mod_python .py | |
PythonHandler mod_python.publisher | |
PythonDebug On | |
を追加して保存 | |
Apacheを再起動($ sudo /etc/init.d/apache2 restart) | |
6. Pythonのテストファイルを置いてみる | |
sudo nano /var/www/test.py | |
ファイルの中身は | |
def index(req): | |
return "Test successful"; | |
終わったらhttp://[自分のRaspberry PiのIPアドレス]/test.py | |
Test successful | |
と表示すれば成功 | |
Webサーバ経由でセンサーのデータを確認してみよう | |
sudo usermod -a -G i2c www-data | |
再起動(sudo reboot) | |
cd /var/www | |
sudo mkdir i2c | |
cd i2c | |
sudo cp ~/src/Adafruit-Raspberry-Pi-Python-Code/Adafruit_BMP085/*.py . | |
sudo nano temperature.py | |
中身は | |
from Adafruit_BMP085 import BMP085 | |
def index(req): | |
bmp = BMP085(0x77) | |
temp = bmp.readTemperature() | |
pressure = bmp.readPressure() | |
altitude = bmp.readAltitude() | |
result = "Temperature: %.2f C\n" % temp | |
result += "Pressure: %.2f hPa\n" % (pressure / 100.0) | |
result += "Altitude: %.2f" % altitude | |
return result | |
終わったらhttp://[自分のRaspberry PiのIPアドレス]/i2c/temperature.pyにアクセス | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment