B4R Question AMG88xx thermal Camera Sensor

peacemaker

Expert
Licensed User
Longtime User
B4X:
'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

<<<��<�<�<�<<AppStart
Setup_Chipset
t=490
Tmp=30.6250
Tmp0= 0; data=0
Tmp1= 0; data=0
Tmp2= 0; data=0
Tmp3= 321.7500; data=1287
Tmp4= 193; data=772
Tmp5= 64.5000; data=258
Tmp6= 0; data=0
Tmp7= 16; data=64
Tmp8= 0; data=0
Tmp9= 0; data=0
Tmp10= 0; data=0
Tmp11= 0; data=0
Tmp12= 0; data=0
Tmp13= 0; data=0
Tmp14= 0; data=0
Tmp15= 0; data=0
Tmp16= 0; data=0
Tmp17= 30; data=120
Tmp18= 30; data=120
Tmp19= 30; data=120
Tmp20= 28.7500; data=115
Tmp21= 26.7500; data=107
Tmp22= 27.7500; data=111
Tmp23= 28.7500; data=115
Tmp24= 29; data=116
Tmp25= 31; data=124
Tmp26= 30.5000; data=122
Tmp27= 30.5000; data=122
Tmp28= 29; data=116
Tmp29= 29; data=116
Tmp30= 28.5000; data=114
Tmp31= 30; data=120
Tmp32= 26.2500; data=105
Tmp33= 29.7500; data=119
Tmp34= 29.5000; data=118
Tmp35= 29; data=116
Tmp36= 29; data=116
Tmp37= 29.5000; data=118
Tmp38= 29; data=116
Tmp39= 30.5000; data=122
Tmp40= 28.2500; data=113
Tmp41= 28.5000; data=114
Tmp42= 28.5000; data=114
Tmp43= 29.5000; data=118
Tmp44= 29.7500; data=119
Tmp45= 29.7500; data=119
Tmp46= 30; data=120
Tmp47= 30.2500; data=121
Tmp48= 28.7500; data=115
Tmp49= 30; data=120
Tmp50= 30.5000; data=122
Tmp51= 31.5000; data=126
Tmp52= 30.7500; data=123
Tmp53= 31.5000; data=126
Tmp54= 31.5000; data=126
Tmp55= 31.2500; data=125
Tmp56= 30.7500; data=123
Tmp57= 32.5000; data=130
Tmp58= 32.5000; data=130
Tmp59= 33; data=132
Tmp60= 32.2500; data=129
Tmp61= 31.7500; data=127
Tmp62= 32.5000; data=130
Tmp63= 31.5000; data=126

AVG temperature = 29.0658

But strange that some dot is with very big value, or sometimes - negative (> 0x800), or zero.
 

Attachments

  • test_amg88_v.0.1.zip
    2.4 KB · Views: 226
  • TempDownload.png
    TempDownload.png
    163.2 KB · Views: 198
Upvote 0
Top