Actions

FLIR Pi HOWTO: Difference between revisions

From HacDC Wiki

(More formatting)
(Finishing? touches)
Line 7: Line 7:
     https://www.raspberrypi.org/downloads/raspbian/
     https://www.raspberrypi.org/downloads/raspbian/


And, I like checksums.  So, copy the checksum too.  I go to the trouble of putting the sum in an appropriate file.  As of this writing (2016.12.06), the checksum is SHA-1. So, create a file named SHA1SUM with the checksum, two spaces, and then the name of the zip file.
And, I like checksums.  So, copy the checksum too.  I go to the trouble of putting the sum in an appropriate file.  As of this writing (2016.12.06), the checksum is SHA-1. So, create a file named '''SHA1SUM''' with the checksum, two spaces, and then the name of the zip file. The '''SHA1SUM''' file can have multiple checksums to check. Like so:
 
    '''6741a30d674d39246302a791f1b7b2b0c50ef9b7  2016-11-25-raspbian-jessie-lite.zip'''
    '''6587483c9b90b11185e2ce99175e27fe75af1f61  2016-11-25-raspbian-jessie.zip'''


Check the sum with:
Check the sum with:


     $ '''sha1sum --check SHA1SUM'''
     $ '''sha1sum --check SHA1SUM'''
    2016-11-25-raspbian-jessie-lite.zip: OK
    2016-11-25-raspbian-jessie.zip: OK


It should say "<filename>.zip: OK" if all is well.
If you see the '''OK''' then everything is okay. Duh.


Mount an SD card somewhere and see where it's mounted and how much free space is on it with:
Mount an SD card somewhere and see where it's mounted and how much free space is on it with:
Line 54: Line 59:
     Nmap done: 254 IP addresses (6 hosts up) scanned in 2.36 seconds
     Nmap done: 254 IP addresses (6 hosts up) scanned in 2.36 seconds


Configure the Pi and enable SSH. I changed the host name to "flirpi" and the default user (pi) password to "Infra-Red".
Configure the Pi and enable SSH. I changed the host name to '''flirpi''' and the default user ('''pi''') password to '''Infra-Red'''.


     $ '''sudo apt update'''
     $ '''sudo apt update'''
Line 60: Line 65:
     $ '''sudo apt install avahi-utils'''
     $ '''sudo apt install avahi-utils'''


Get all your SSH key ducks in a row to ease communicating with the wee beastie. In addition to adding public keys to the appropriate
Get all your SSH key ducks in a row to ease communicating with the wee beastie. In addition to adding public keys to the appropriate '''~/.ssh/authorized_keys''' file (and ensuring the permissions on said file are '''600'''), adding a stanza to '''.ssh/config''' like:
  ~/.ssh/authorized_keys file (and ensuring the permissions on said file are 600), adding the .ssh/config


     '''Host flirpi.local'''
     '''Host flirpi.local'''
Line 71: Line 75:
       '''ForwardX11 yes'''
       '''ForwardX11 yes'''


See both the following:
(Installing the avahi-utils is what allows us to use the '''.local''' to find the Pi.)
 
For additional suggestions see both the following:


     http://www.penguintutor.com/linux/raspberrypi-headless
     http://www.penguintutor.com/linux/raspberrypi-headless
Line 82: Line 88:
We're already at 56% used of the 8GB... Everything up until this point has been a good way to set up any Pi. But now, it's time to add the special sauce to make it talk to the FLIR.
We're already at 56% used of the 8GB... Everything up until this point has been a good way to set up any Pi. But now, it's time to add the special sauce to make it talk to the FLIR.


We need git to fetch the Video for Linux loopback source, since the Debian package seems hopelessly borked. To compile that, we need kernel header files. And finally, we need libusb-dev for a header file needed to compile the FLIR source code.
We need '''git''' to fetch the Video for Linux loopback source, since the Debian package seems hopelessly borked. To compile that, we need kernel header files. And finally, we need '''libusb-dev''' for a header file needed to compile the FLIR source code.


     $ '''sudo apt install git'''
     $ '''sudo apt install git'''
Line 104: Line 110:
Search the blog at http://www.eevblog.com/forum/thermal-imaging/question-about-flir-one-for-android/msg832208/#msg832208 for the source code link (flir8g-mint.c). It's a bit hidden near the bottom of the thread. Drop it in ~/github/FLIR/.
Search the blog at http://www.eevblog.com/forum/thermal-imaging/question-about-flir-one-for-android/msg832208/#msg832208 for the source code link (flir8g-mint.c). It's a bit hidden near the bottom of the thread. Drop it in ~/github/FLIR/.


Determine, for certain, where the libusb.h file is to use in the FLIR compilation.
Determine, for certain, where the '''libusb.h''' file was installe in order to reference it in the FLIR compilation command.


     $ '''find / -name libusb.h 2>/dev/zero'''
     $ '''find / -name libusb.h 2>/dev/zero'''
Line 114: Line 120:
     $ '''sudo ./flir'''
     $ '''sudo ./flir'''


The console should, after a second or two, start spitting out all sorts of camera data in an ongoing stream, To see the camera data as video:
The console should, after a second or two, start spitting out all sorts of camera data in an ongoing stream, To see the camera data as video, install '''mplayer''' and run it with some special parameters:


     $ '''sudo apt install mplayer'''
     $ '''sudo apt install mplayer'''
     $ '''mplayer tv:// -tv driver=v4l2:device=/dev/video1'''
     $ '''mplayer tv:// -tv driver=v4l2:device=/dev/video1'''


Finally, since it's easier than figuring out the RIGHT way to do it, add a couple of lines to /etc/rc.local to load the video for Linux loopback module compiled and installed above:
Finally, since it's easier than figuring out the RIGHT way to do it, add a couple of lines to '''/etc/rc.local''' to load the video for Linux loopback module compiled and installed above:


     '''# Last modified by Ubuntourist <[email protected]> 2016.12.06 (kjc)'''
     '''# Last modified by Ubuntourist <[email protected]> 2016.12.06 (kjc)'''
Line 126: Line 132:
     '''modprobe v4l2loopback video_nr=1,2'''
     '''modprobe v4l2loopback video_nr=1,2'''


Also, a ~/.bash_aliases file with:
Also, a '''~/.bash_aliases''' file with:


     '''# Written by Ubuntourist <[email protected]> 2016.12.06'''
     '''# Written by Ubuntourist <[email protected]> 2016.12.06'''
     '''alias heatwatch='mplayer tv:// -tv driver=v4l2:device=/dev/video1''''
     '''alias heatwatch='mplayer tv:// -tv driver=v4l2:device=/dev/video1''''


so that you can type "heatwatch" instead of remembering all the parameters for the mplayer command. (Remember to start flir first.)
added will let you type "heatwatch" instead of remembering all the parameters for the '''mplayer''' command. (Remember to start '''flir''' first.)


All told, 59% of the SD card's root partition (4.0 GB out of 7.1 GB) is being occupied at the moment.
All told, 59% of the SD card's root partition (4.0 GB out of 7.1 GB) is being occupied at the moment.

Revision as of 23:05, 6 December 2016

The space has a FLIR infrared camera which is designed to plug into an Android device. Here's how to set up a Raspberry Pi to handle the camera, from scratch.

An operating system would be a good start

Start by fetching the Raspibian image du jour from:

   https://www.raspberrypi.org/downloads/raspbian/

And, I like checksums. So, copy the checksum too. I go to the trouble of putting the sum in an appropriate file. As of this writing (2016.12.06), the checksum is SHA-1. So, create a file named SHA1SUM with the checksum, two spaces, and then the name of the zip file. The SHA1SUM file can have multiple checksums to check. Like so:

   6741a30d674d39246302a791f1b7b2b0c50ef9b7  2016-11-25-raspbian-jessie-lite.zip
   6587483c9b90b11185e2ce99175e27fe75af1f61  2016-11-25-raspbian-jessie.zip

Check the sum with:

   $ sha1sum --check SHA1SUM
   2016-11-25-raspbian-jessie-lite.zip: OK
   2016-11-25-raspbian-jessie.zip: OK

If you see the OK then everything is okay. Duh.

Mount an SD card somewhere and see where it's mounted and how much free space is on it with:

   $ df -h

In my case, this is an 8GB SD card at /dev/sdb1

The "dd" program is the standard way to burn an image. I don't like it because to get feedback on the progress of the burn, you have to go through odd somersaults of sending kill SIGs. This is just perverse. Use "ddrescue" instead. Under Ubuntu the package name is "gddrescue" but the command drops the "g".

   $ sudo ddrescue --force -b <blocksize> <source image> <destination device>

Specifically, as of this writing:

   $ sudo ddrescue --force -b 4M 2016-11-25-raspbian-jessie.img /dev/sdb

(Another option is to use "dcfldd" from the package of the same name.)

If you've burned the SD correctly, you should now have two partitions -- a root and a boot.

Eject the SD safely and pop it into a Pi. Boot the Pi, preferably with an Ethernet cable attached.

Use nmap to find the IP address of the Pi. The following pings all of the machines on the local network! (THANKS, Tom!)

   $ nmap 192.168.26.2-255 -sn

   Starting Nmap 7.12 ( https://nmap.org ) at 2016-12-05 21:42 EST
   Nmap scan report for 192.168.26.6
   Host is up (0.0033s latency).
   Nmap scan report for 192.168.26.97
   Host is up (0.038s latency).
   Nmap scan report for 192.168.26.100
   Host is up (0.00023s latency).
   Nmap scan report for 192.168.26.116
   Host is up (0.0015s latency).
   Nmap scan report for 192.168.26.156
   Host is up (0.0055s latency).
   Nmap scan report for 192.168.26.176
   Host is up (0.035s latency).
   Nmap done: 254 IP addresses (6 hosts up) scanned in 2.36 seconds

Configure the Pi and enable SSH. I changed the host name to flirpi and the default user (pi) password to Infra-Red.

   $ sudo apt update
   $ sudo apt full-upgrade
   $ sudo apt install avahi-utils

Get all your SSH key ducks in a row to ease communicating with the wee beastie. In addition to adding public keys to the appropriate ~/.ssh/authorized_keys file (and ensuring the permissions on said file are 600), adding a stanza to .ssh/config like:

   Host flirpi.local
     User pi
     ForwardX11 yes
   Host flirpi
     Hostname flirpi.local
     User pi
     ForwardX11 yes

(Installing the avahi-utils is what allows us to use the .local to find the Pi.)

For additional suggestions see both the following:

   http://www.penguintutor.com/linux/raspberrypi-headless
   http://www.penguintutor.com/linux/tightvnc

Okay. That was all very special. Now, time to get to why we're here.


Adding FLIR to the mix

We're already at 56% used of the 8GB... Everything up until this point has been a good way to set up any Pi. But now, it's time to add the special sauce to make it talk to the FLIR.

We need git to fetch the Video for Linux loopback source, since the Debian package seems hopelessly borked. To compile that, we need kernel header files. And finally, we need libusb-dev for a header file needed to compile the FLIR source code.

   $ sudo apt install git
   $ sudo apt install raspberrypi-kernel-headers
   $ sudo apt-get install libusb-1.0-0-dev
   $ mkdir -p github/FLIR
   $ cd github/FLIR

Compile and install the Video for Linux loopback driver module:

   $ git clone https://github.com/umlaeute/v4l2loopback
   $ cd v4l2loopback
   $ make
   $ sudo make install

Moment of truth: Compile flir.

   $ cd ~/github/FLIR/

Search the blog at http://www.eevblog.com/forum/thermal-imaging/question-about-flir-one-for-android/msg832208/#msg832208 for the source code link (flir8g-mint.c). It's a bit hidden near the bottom of the thread. Drop it in ~/github/FLIR/.

Determine, for certain, where the libusb.h file was installe in order to reference it in the FLIR compilation command.

   $ find / -name libusb.h 2>/dev/zero
   /usr/include/libusb-1.0/libusb.h
   $ gcc '-I/usr/include/libusb-1.0'  \
          -o flir flir8g-mint.c -lusb-1.0 -lm
   $ sudo modprobe v4l2loopback video_nr=1,2
   $ sudo ./flir

The console should, after a second or two, start spitting out all sorts of camera data in an ongoing stream, To see the camera data as video, install mplayer and run it with some special parameters:

   $ sudo apt install mplayer
   $ mplayer tv:// -tv driver=v4l2:device=/dev/video1

Finally, since it's easier than figuring out the RIGHT way to do it, add a couple of lines to /etc/rc.local to load the video for Linux loopback module compiled and installed above:

   # Last modified by Ubuntourist <[email protected]> 2016.12.06 (kjc)

   # 2016.12.06 KJC - Load Video for Linux loopback driver module
   modprobe v4l2loopback video_nr=1,2

Also, a ~/.bash_aliases file with:

   # Written by Ubuntourist <[email protected]> 2016.12.06
   alias heatwatch='mplayer tv:// -tv driver=v4l2:device=/dev/video1'

added will let you type "heatwatch" instead of remembering all the parameters for the mplayer command. (Remember to start flir first.)

All told, 59% of the SD card's root partition (4.0 GB out of 7.1 GB) is being occupied at the moment.