Skip to content

imacube/thermal-camera

Repository files navigation

This repo draws heavily on the code provided by Seeed Studio and utilizes their MLX90640 110 degree Thermal Camera.

The frame rate setting for the camera in this code was chosen based on initial experiences with a Raspberry Pi Zero W.

The camera uses a 32x24 array but the data feed is all one line.

Setup

Wiring

The Seeed Studio Grove Thermal Imaging Camera IR Array uses 3 to 6V. I connected mine to the 3.3V DC on my Raspberry Pi Zero W. Current consumption of approximately 18mA.

Match the SDA and SCL pins on the camera to those on the Pi.

  • Camera SDA -> GPIO 2 (SDA)
  • Camera SCL -> GPIO 3 (SCL)

Software

  1. Install grove.py.
    curl -sL https://github.com/Seeed-Studio/grove.py/raw/master/install.sh | sudo bash -s -
  2. Install the driver.
    pip3 install seeed-python-mlx90640
    If you need to run with sudo.
     sudo pip3 install seeed-python-mlx90640
  3. Check for i2c number. This should return a device.
    ls /dev/i2c*
  4. Check for the camera as an i2c device. Its address is 0x33.
    i2cdetect -y -r 1
  5. Give it a try! :D

Refresh Rate

I found that REFRESH_2_HZ worked on a Raspberry Pi Zero W with stream.py. Higher ones might work, especially for time-lapse.py.

This code is an example of how to create the device and set the refresh rate. This was found on Seed Studio Wiki for their Thermal Imaging Camera.

import seeed_mlx90640
mlx = seeed_mlx90640.grove_mxl90640()
mlx.refresh_rate = seeed_mlx90640.RefreshRate.REFRESH_8_HZ  # The fastest for raspberry 4 
# REFRESH_0_5_HZ = 0b000  # 0.5Hz
# REFRESH_1_HZ = 0b001  # 1Hz
# REFRESH_2_HZ = 0b010  # 2Hz
# REFRESH_4_HZ = 0b011  # 4Hz
# REFRESH_8_HZ = 0b100  # 8Hz
# REFRESH_16_HZ = 0b101  # 16Hz
# REFRESH_32_HZ = 0b110  # 32Hz
# REFRESH_64_HZ = 0b111  # 64Hz

Boosting Refresh Rate

Always be aware when editing boot options your Pi might not boot.

Find the dtparam=i2c_arm=on line in /boot/config.txt and replace it with the one below.

dtparam=i2c_arm=on,i2c_arm_baudrate=400000

This sets the i2c baudrate to the maximum supported by the CPU, the default is 100000. See the links below for peripheral specification and device tree.

Streaming

Run the stream.py script to host a small website with Flask that streams what the thermal camera sees.

Thermal Image Capturing

Run time-lapse.py or write a simple script to call thermal.py to capture the thermal data.

Time Lapse Images

Run time-lapse.py. Data is written to thermal.csv. Images are captured as raw numeric data from the camera every 10 seconds and stored in the CSV file. Use thermal-to-images.py to convert the raw data into PNG images.

The data is formatted as one line per image. An example file is thermal.csv.

Converting Images to Video

I found that I needed an image that is images/img0000.png for this to work. I don't know if everything has to

ffmpeg -r 5 -i images/img%04d.png -vcodec libx264 -pix_fmt yuv420p -y movie.mp4

Sources

About

Experimenting with a thermal camera

Resources

License

Stars

Watchers

Forks

Packages

No packages published