The Raspberry Pi also has an i2c interface, and even better has processing capability to interpolate and filter the sensor output. By adding processing power, you can ‘turn’ the 8x8 output into what appears to be a higher-resolution display.

We’re using a PiTFT 2.8” and a Pi Cobbler but the code can be adapted to output to the HDMI display - we’re using pygame to draw to the framebuffer.

You can use any Raspberry Pi computer, from Pi A+ to Pi 3 or even a Pi Zero, but we happen to have a Pi 3 on our desk set up already so we’re using that.

Raspberry Pi Thermal Camera | Adafruit AMG8833 8x8 Thermal Camera Sensor | Adafruit Learning System - 图1

Did you really think the Raspberry Pi would stop getting better? At this point, we sound like a broken record, extolling on the new Pi’s myriad improvements like we’re…

Raspberry Pi Thermal Camera | Adafruit AMG8833 8x8 Thermal Camera Sensor | Adafruit Learning System - 图2

Is this not the cutest little display for the Raspberry Pi? It features a 2.8” display with 320x240 16-bit color pixels and a resistive touch overlay. The plate uses the high…

Raspberry Pi Thermal Camera | Adafruit AMG8833 8x8 Thermal Camera Sensor | Adafruit Learning System - 图3

This is the assembled version of the Pi T-Cobbler Plus. It only works with the Raspberry Pi Model Zero, A+, B+, Pi 2, Pi 3 & Pi 4! (Any Pi with 2x20…

If you have not done so already, the first thing you will need to do is setup your PiTFT. Instructions on how to do so can be found in this guide.

Finally, install both pygame and scipy. Pygame lets us draw easily to a screen using python, we’ll use that to make the display work. Scipy is a powerful scientific/data processing library that we can use to magically turn the 8x8 = 64 pixel array into something that looks more like a 32x32 = 1024 pixel array. Wow, isn’t digital signal processing cool?

  1. sudo apt-get install -y python-scipy python-pygame
  2. sudo pip3 install colour

With the Pi powered off, we can wire up the sensor to the Pi Cobbler like this:

  • Connect Vin to the 3V or 5V power supply (either is fine)
  • Connect GND to the ground pin on the Cobbler
  • Connect SDA to SDA on the Cobbler
  • Connect SCL to SCL on the Cobbler

You can also use direct wires, we happen to have a Cobbler ready. remember you can plug the cobbler into the bottom of the PiTFT to get access to all the pins!

Raspberry Pi Thermal Camera | Adafruit AMG8833 8x8 Thermal Camera Sensor | Adafruit Learning System - 图4

Now you should be able to verify that the sensor is wired up correctly by asking the Pi to detect what addresses it can see on the I2C bus:

Raspberry Pi Thermal Camera | Adafruit AMG8833 8x8 Thermal Camera Sensor | Adafruit Learning System - 图5

It should show up under it’s default address (0x69). If you don’t see 0x69, check your wiring, did you install I2C support, etc?

At long last, we are finally ready to run our example code

  1. “””This example is for Raspberry Pi (Linux) only!

  2. It will not work on microcontrollers running CircuitPython!”””

  3. import os

  4. import math

  5. import time

  6. import busio

  7. import board

  8. import numpy as np

  9. import pygame

  10. from scipy.interpolate import griddata

  11. from colour import Color

  12. import adafruit_amg88xx

  13. i2c_bus = busio.I2C(board.SCL, board.SDA)

  14. low range of the sensor (this will be blue on the screen)

  15. MINTEMP = 26.

  16. high range of the sensor (this will be red on the screen)

  17. MAXTEMP = 32.

  18. how many color values we can have

  19. COLORDEPTH = 1024

  20. os.putenv(‘SDL_FBDEV’, ‘/dev/fb1’)

  21. pygame.init()

  22. initialize the sensor

  23. sensor = adafruit_amg88xx.AMG88XX(i2c_bus)

  24. pylint: disable=invalid-slice-index

  25. points = [(math.floor(ix / 8), (ix % 8)) for ix in range(0, 64)]

  26. grid_x, grid_y = np.mgrid[0:7:32j, 0:7:32j]

  27. pylint: enable=invalid-slice-index

  28. sensor is an 8x8 grid so lets do a square

  29. height = 240

  30. width = 240

  31. the list of colors we can choose from

  32. blue = Color(“indigo”)

  33. colors = list(blue.range_to(Color(“red”), COLORDEPTH))

  34. create the array of colors

  35. colors = [(int(c.red 255), int(c.green 255), int(c.blue * 255)) for c in colors]

  36. displayPixelWidth = width / 30

  37. displayPixelHeight = height / 30

  38. lcd = pygame.display.set_mode((width, height))

  39. lcd.fill((255, 0, 0))

  40. pygame.display.update()

  41. pygame.mouse.set_visible(False)

  42. lcd.fill((0, 0, 0))

  43. pygame.display.update()

  44. some utility functions

  45. def constrain(val, min_val, max_val):

  46. return min(max_val, max(min_val, val))

  47. def map_value(x, in_min, in_max, out_min, out_max):

  48. return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min

  49. let the sensor initialize

  50. time.sleep(.1)

  51. while True:

  52. read the pixels

  53. pixels = []

  54. for row in sensor.pixels:

  55. pixels = pixels + row

  56. pixels = [map_value(p, MINTEMP, MAXTEMP, 0, COLORDEPTH - 1) for p in pixels]

  57. perform interpolation

  58. bicubic = griddata(points, pixels, (grid_x, grid_y), method=’cubic’)

  59. draw everything

  60. for ix, row in enumerate(bicubic):

  61. for jx, pixel in enumerate(row):

  62. pygame.draw.rect(lcd, colors[constrain(int(pixel), 0, COLORDEPTH- 1)],

  63. (displayPixelHeight ix, displayPixelWidth jx,

  64. displayPixelHeight, displayPixelWidth))

  65. pygame.display.update()

If you have everything installed and wired up correctly, you should see a nice thermal camera image. Cool tones (blue and purple) are cooler temperatures, and warmer tones (yellow, red) are warmer temperatures.

If your image seems to be flipped on the screen, try changing the orientation of the AMG8833 breakout on the breadboard.

If you’re interested int he details, and want to know more about how we made 64 pixels look like many more, it’s called bicubic interpolation (hat tip to OSHpark for the idea!)

This guide was first published on Jun 28, 2017. It was last updated on Jun 28, 2017.

This page (Raspberry Pi Thermal Camera) was last updated on Nov 07, 2020.