LoginSignup
20
18

More than 3 years have passed since last update.

RaspberryPiで赤外線アレイセンサAMG8833(Grid-EYE)からデータ取得

Last updated at Posted at 2019-10-04

必要なもの

  • Raspberry Pi
    • Raspberry Pi 3 model B+を使用しています
  • Conta サーモグラフィー AMG8833搭載
  • ブレッドボードおよびジャンパーワイヤ

モジュールについて

DSCN0696.JPG

モジュールとRaspberry Piの接続

  • AMG8833(3.3V) ⇔ GPIO1(3.3V)
  • AMG8833(GND) ⇔ GPIO6(Ground)
  • AMG8833(SDA) ⇔ GPIO3(SDA)
  • AMG8833(SCL) ⇔ GPIO5(SCL)

(Raspberry PiのGPIOピン配置は https://pinout.xyz/ などを参照)

DSCN0697.JPG

fritzingで書いた配線図は以下です。
Adafruit社が提供しているFritzing-Libraryを利用したのですが、基盤のピン配置が今回使用したものと少し違うので注意してください。

以降はRaspberry Piで作業します。

使用しているRaspberry PiのOSバージョンは以下の通りです。

$ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 10 (buster)
Release:    10
Codename:   buster

I2Cを有効化します。

$ sudo raspi-config
-> 5 Interfacing Options
--> P5 I2C

接続できているか確認します。

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

このように「68」が出ていれば問題ありません。
工場出荷時は68になっているようです。
変更したい場合はSJ1のソルダージャンパーをH側と接続すると「69」になります。

データ取得

Adafruit社から提供されているCircuitPythonを使用します。

$ sudo pip3 install adafruit-circuitpython-amg88xx

Adafruitのサンプルプログラムを参考にプログラムします。
https://learn.adafruit.com/adafruit-amg8833-8x8-thermal-camera-sensor/raspberry-pi-thermal-camera

amg8833.py
# -*- coding: utf-8 -*-

import time

import busio
import board

import adafruit_amg88xx

# I2Cバスの初期化
i2c_bus = busio.I2C(board.SCL, board.SDA)

# センサーの初期化
sensor = adafruit_amg88xx.AMG88XX(i2c_bus)

# センサーの初期化待ち
time.sleep(.1)

# 8x8の表示
print(sensor.pixels)

ただし、このまま実行するとエラーになります。

$ python3 amg8833.py
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/adafruit_bus_device/i2c_device.py", line 68, in __init__
    i2c.writeto(device_address, b'')
  File "/usr/local/lib/python3.7/dist-packages/busio.py", line 69, in writeto
    return self._i2c.writeto(address, buffer, stop=stop)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 38, in writeto
    self._i2c_bus.write_bytes(address, buffer[start:end])
  File "/usr/local/lib/python3.7/dist-packages/Adafruit_PureIO/smbus.py", line 244, in write_bytes
    self._device.write(buf)
OSError: [Errno 121] Remote I/O error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/adafruit_bus_device/i2c_device.py", line 74, in __init__
    i2c.readfrom_into(device_address, result)
  File "/usr/local/lib/python3.7/dist-packages/busio.py", line 59, in readfrom_into
    return self._i2c.readfrom_into(address, buffer, stop=stop)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 44, in readfrom_into
    readin = self._i2c_bus.read_bytes(address, end-start)
  File "/usr/local/lib/python3.7/dist-packages/Adafruit_PureIO/smbus.py", line 155, in read_bytes
    return self._device.read(number)
OSError: [Errno 121] Remote I/O error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "amg8833.py", line 12, in <module>
    sensor = adafruit_amg88xx.AMG88XX(i2c_bus)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_amg88xx.py", line 131, in __init__
    self.i2c_device = I2CDevice(i2c, addr)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_bus_device/i2c_device.py", line 76, in __init__
    raise ValueError("No I2C device at address: %x" % device_address)
ValueError: No I2C device at address: 69

I2Cのアドレスが69でないといけないようです。
ソルダージャンパーを変更してアドレスを69にしてもいいですが、https://github.com/adafruit/Adafruit_CircuitPython_AMG88xx を見たらオプションでアドレス変更できると書いてあるので、センサーの初期化のときにアドレスを68に指定します。

amg8833.py
# -*- coding: utf-8 -*-

import time

import busio
import board

import adafruit_amg88xx

# I2Cバスの初期化
i2c_bus = busio.I2C(board.SCL, board.SDA)

# センサーの初期化
# アドレスを68に指定
sensor = adafruit_amg88xx.AMG88XX(i2c_bus, addr=0x68)

# センサーの初期化待ち
time.sleep(.1)

# 8x8の表示
print(sensor.pixels)

これで8x8の温度が取得できます。

$ python3 amg8833.py 
[[27.25, 26.75, 26.75, 27.25, 27.75, 26.75, 27.75, 29.75]
 [27.0,  27.25, 27.25, 26.75, 27.25, 27.5,  29.75, 32.5]
 [27.25, 26.5,  26.75, 27.25, 27.0,  27.5,  27.75, 28.75]
 [26.75, 25.5,  26.5,  23.5,  27.0,  24.75, 27.5,  33.5]
 [26.75, 26.75, 26.75, 27.0,  27.25, 26.75, 27.25, 32.0]
 [26.5,  26.5,  26.5,  27.25, 26.75, 27.0,  28.0,  32.25]
 [26.5,  26.5,  26.5,  27.0,  27.0,  27.25, 28.0,  31.0]
 [26.0,  26.5,  26.0,  26.5,  26.5,  26.75, 26.75, 27.75]]

見やすいように改行したり空白を入れたりしましたが、実際は一列で表示されます。

(2019.10.11追記)
上記では数字のみの取得でしたが、画像として表示する記事を書きました。
https://qiita.com/tm_nagoya/items/32d7e5becf73ba8a6110

20
18
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
20
18