'AMG88xx Infrared Array Sensor “Grid-EYE”
'Vlad Pomelov aka Peacemakerv.
'v.0.1
'based on https://cdn-learn.adafruit.com/assets/assets/000/043/261/original/Grid-EYE_SPECIFICATIONS%28Reference%29.pdf
' I2C Bus Esp8266:
' D1 is GPI05 to SCL of chipset
' D2 is GPI04 to SDA of chipset
Sub Process_Globals
Public SlaveAddress As Byte = 0x69 'I2C address of the chipset. If AD0 (AD_SELECT) pin is set to HIGH, the I2C address will be 0x69.
Public Tmp As Double
Public AVG As Double
Private wire As WireMaster
Private raf As RandomAccessFile
Public const Size = 64 As Int 'qty of the dots in the camera matrix
Public const PCTL = 0x00 As Byte 'Power Control Register, commands: 0/0x10/0x20/0x21 = normal/sleep/standy 60 sec/standby 10 sec
Public const RST = 0x01 As Byte 'Reset Register, write only, commands: 0x30/0x3F = Flag reset/Initial reset
Public const FPSC = 0x02 As Byte 'Frame Rate Register, bit0: Setting Frame Mode = 1: 1FPS/0: 10FPS
Public const INTC = 0x03 As Byte 'Interrupt Control Register
Public const STAT = 0x04 As Byte 'Status Register
Public const SCLR = 0x05 As Byte 'Status Clear Register
Public const AVE = 0x07 As Byte 'Average Register
Public const TTHL = 0x0E As Byte 'Thermistor Temperature Register, low byte, 0.0625℃ per bit
Public const TTHH = 0x0F As Byte 'Thermistor Temperature Register, high byte, bit3 = sign: +125℃ = 0x7D0, +25℃ = 0x190, -0.25℃=0x804, -20℃= 0x940
Public const T01L = 0x80 As Byte 'Temperature Register of the 1st dot of 64, low byte
Public const T01H = 0x81 As Byte 'Temperature Register of the 1st dot of 64, high byte, next dots are ... up to T64L = 0xFE and T64H = 0xFF
End Sub
Public Sub Start
wire.Initialize
Setup_Chipset
CallSubPlus("tmr_tick", 100, 0)
End Sub
Sub Setup_Chipset
Log("Setup_Chipset")
wire.WriteTo(SlaveAddress, Array As Byte(PCTL, 0x00)) 'normal mode of work
wire.WriteTo(SlaveAddress, Array As Byte(FPSC, 0x00)) '10 FPS
End Sub
Sub tmr_tick(tag As Byte)
wire.WriteTo(SlaveAddress, Array As Byte(TTHL))
Dim b() As Byte = wire.RequestFrom(SlaveAddress, 2) '2 bytes
raf.Initialize(b, True) 'LittleEndian, yes !
Dim t As UInt = raf.ReadUInt16(raf.CurrentPosition)
If t > 0x800 Then 'negative temperatures are ignored
t = 0
End If
Tmp = t * 0.0625
Log("t=", T)
Log("Tmp=", Tmp) 'temperature of the internal thermistor
wire.WriteTo(SlaveAddress, Array As Byte(0x80)) 'start address of temperature matrix
Dim b() As Byte = wire.RequestFrom(SlaveAddress, 128)
If b.Length <> 128 Then
Log("Error reading from chipset !")
Return
End If
raf.Initialize(b, True) 're-init
Dim av As Float, count As Int
For i = 0 To Size - 1
Dim t As UInt = raf.ReadUInt16(raf.CurrentPosition)
If t > 0x800 Then 'negative temperatures are ignored
t = 0
End If
Tmp = t * 0.25
Log("Tmp", i, "= ", Tmp,"; data=", t) '64-dot temperature matrix of the camera
If t > 0 And t <= 125 Then
av = av + Tmp
count = count + 1
End If
Next
AVG = av / count
Log("AVG temperature = ", AVG)
End Sub