LoginSignup
1
2

More than 5 years have passed since last update.

⑦Raspberry Pi3で照射量を取得する(BH1750FVI)

Posted at

準備するもの(周辺機器)

1.Raspberry Pi 3
2.BH1750FVI(デジタル光センサー)
3.はんだごて
4.はんだ
5.オスジャンパー、メスジャンパー(Raspberry Pi初心者キット使用)

はんだごて

BH1750FVI+ブレッドボード+Raspberry Piを接続

スクリーンショット 2018-08-28 12.09.57.png

I2Cの設定

# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.

snd-bcm2835
i2c-bcm2708 ←追加
i2c-dev ←追加

I2Cにつながっている確認するツールをインストール

sudo apt-get install i2c-tools

IC2デバイスを確認

$ sudo i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- 23 -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

光センサーのアドレスは0x23

I2Cのデバイスをpythonから使う時は、smbusライブラリを使う

sudo apt-get install python-smbus

スクリプト作成

li.py
#!/usr/bin/python

import smbus

bus = smbus.SMBus(1)
addr = 0x23
luxRead = bus.read_i2c_block_data(addr,0x11)
print("Lux: "+str(luxRead[1]* 10))

スクリプト実行

$ sudo python li.py

Lux: 10.00
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2