Raspberry Pi Thermal Cam

Demo

See demo below, note restart button and color changing LED when heat is detected.

Demo Of Thermal Cam

Using ADAFRUIT AMG8833 IR THERMAL CAMERA Amazon Link

Customizations

  • Added a Reset button to my Pi, code can be seen in restart-button.py
  • Initial restart code on startup using /etc/rc.local, you can see that method and others here: https://www.dexterindustries.com/howto/run-a-program-on-your-raspberry-pi-at-startup/
  • Added two LEDs (green and red). Green light is on by default, then when enough "hot pixels" enter the frame the green light turns off and red light turns on. That can be seen with the "hotPixels" variable
    hotPixels=0
    for ix, row in enumerate(BICUBIC):
        x_console = 2
        for jx, pixel in enumerate(row):
            color_index = 0
            if pixel > 300:
                hotPixels = hotPixels+1
            if COLOR_RANGE != 0:
                color_index = int(round((pixel - MINPIXEL) / COLOR_RANGE))
            if color_index < 0:
                color_index = 0
            if color_index > len(CONSOLE_COLORS) - 1:
                color_index = len(CONSOLE_COLORS) - 1
            print_there(x_console, Y_CONSOLE * 2 - 2, "  ", CONSOLE_COLORS[color_index])
            if pixel > MAXPIXEL:
                MAXPIXEL = pixel
            if pixel < MINPIXEL:
                MINPIXEL = pixel
            x_console += 1
        Y_CONSOLE += 1
    sys.stdout.flush()
    HEAT_RANGE = MAXPIXEL - MINPIXEL
    COLOR_RANGE = HEAT_RANGE / len(CONSOLE_COLORS)
    if hotPixels > 10:
        GPIO.output(18,GPIO.HIGH)
        GPIO.output(25,GPIO.LOW)
    else:
        GPIO.output(18,GPIO.LOW)
        GPIO.output(25,GPIO.HIGH)
  • There are 3 thermal cam code files.
    • 1 will open a new window with a video feed to show you thermal readings
    • The second will leverage your console to output a visual feed (this one visually looks best)
    • The third doesnt not have an output, if you want to start the code on reboot of the Pi then you need to use this option, also required for background or headless execution
  • Becuase the python code to initiate the thermal cam logic must be run from pi and not root (This may not be the case for you if you install the dependencies more cleanly that I did) I could not use /etc/rc.local to run the python script on startup because I need the pi user to run it. For this reason I used crontab -e with an @reboot command to ensure the code was ran by the correct user on startup.
@reboot /bin/bash /home/pi/thermal-cam/startup.sh
  • startup.sh is simply:
#!/bin/bash

python3 /home/pi/thermal-cam/thermal-cam-bare.py >> /home/pi/thermal-cam/cam-logs.txt