Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

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

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
ksk8
Nice to meet you
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした