Actions

FLIR Pi HOWTO: Difference between revisions

From HacDC Wiki

(Initial commit)
 
m (Signing my work)
 
(20 intermediate revisions by the same user not shown)
Line 1: Line 1:
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.
The space has a [http://www.flir.com/flirone/ios-android/#specifications FLIR One] infrared camera which is designed to plug into an Android device.  You can watch [https://www.youtube.com/watch?v=CT9mILHT6DM this review] -- among others -- on YouTube.
 
Here's how to set up a Raspberry Pi to handle the camera, from scratch.


== An operating system would be a good start ==
== An operating system would be a good start ==
Line 7: Line 9:
     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. If not, your file is corrupt. This could mean an error in transmission or something more sinister...


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:


     $ df -h
     $ '''df -h'''


In my case, this is an 8GB SD card at /dev/sdb1
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".
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 (and presumably, Debian) the package name is '''gddrescue''' but the command itself drops the initial '''g'''.


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


Specifically, as of this writing:
Specifically, as of this writing:


     $ sudo ddrescue --force -b 4M 2016-11-25-raspbian-jessie.img /dev/sdb
     $ '''sudo ddrescue --force -b 4M 2016-11-25-raspbian-jessie.img /dev/sdb'''
 
'''NOTE''': The destination ''device'' does '''not''' contain a ''partition'' number.


(Another option is to use "dcfldd" from the package of the same name.)
(Another alternative to '''dd''' is to use '''dcfldd''' from the package of the same name, which also, unlike '''dd''', provides a progress report as it burns.)


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


Eject the SD safely and pop it into a Pi. Boot the Pi, preferably with an Ethernet cable attached.
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!)
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


    $ '''nmap 192.168.26.2-255 -sn'''
     Starting Nmap 7.12 ( https://nmap.org ) at 2016-12-05 21:42 EST
     Starting Nmap 7.12 ( https://nmap.org ) at 2016-12-05 21:42 EST
     Nmap scan report for 192.168.26.6
     Nmap scan report for 192.168.26.6
Line 54: Line 63:
     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'''. There is a GUI to do that, or in a terminal you can use '''raspi-config'''.
 
Images are always out of date. So, fetch the latest and greatest packages for your Pi. And, while you're at it, get Avahi which makes working remotely sooo much simpler.
 
    $ '''sudo apt update'''
    $ '''sudo apt full-upgrade'''
    $ '''sudo apt install avahi-utils'''


    $ sudo apt update
Get all your SSH key ducks in a row to ease communicating with the wee beastie. In addition to adding the appropriate public keys to the appropriate '''~/.ssh/authorized_keys''' file on the appropriate machines you want to talk to each other (and ensuring the permissions on said file are '''600'''), adding a stanza to '''.ssh/config''' like:
    $ 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
    '''# HacDC's FLIR Infrared Camera Pi'''
  ~/.ssh/authorized_keys file (and ensuring the permissions on said file are 600), adding the .ssh/config
    '''#'''
    '''Host flirpi.local'''
      '''User pi'''
      '''ForwardX11 yes'''
    '''Host flirpi'''
      '''Hostname flirpi.local'''
      '''User pi'''
      '''ForwardX11 yes'''


    Host flirpi.local
will let you easily ssh into the Pi without worrying about DNS services or remembering the IP numeric address du boot. (Installing the '''avahi-utils''' package is what allows us to use the '''.local''' to find the Pi. The above just lets us set up an even shorter alias to that, and to automatically specify the user to connect as -- not to mention the whole forwarding of X11 stuff, which lets us run graphics software on the Pi even if we don't have graphics capabilities on the Pi.)
      User pi
      ForwardX11 yes
    Host flirpi
      Hostname flirpi.local
      User pi
      ForwardX11 yes


See both the following:
For additional suggestions see both the following:


     http://www.penguintutor.com/linux/raspberrypi-headless
     http://www.penguintutor.com/linux/raspberrypi-headless
Line 77: Line 91:


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


We're already at 56% used of the 8GB...


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.
== 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.


    $ sudo apt install git
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 raspberrypi-kernel-headers
    $ sudo apt-get install libusb-1.0-0-dev


     $ mkdir -p github/FLIR
     $ '''sudo apt install git'''
     $ cd github/FLIR
    $ '''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:
Compile and install the Video for Linux loopback driver module:


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


Moment of truth: Compile flir.
Moment of truth: Compile flir.


     $ cd ~/github/FLIR/
     $ '''cd ~/github/FLIR/'''


Search the blog at
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 the recently created '''~/github/FLIR/'''.


    http://www.eevblog.com/forum/thermal-imaging/\
Determine, for certain, where the '''libusb.h''' file was installe in order to reference it in the FLIR compilation command.
    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/.
    $ '''find / -name libusb.h 2>/dev/zero'''
    /usr/include/libusb-1.0/libusb.h


Determine, for certain, where the libusb.h file is to use in the FLIR compilation.
    $ '''gcc '-I/usr/include/libusb-1.0' -o flir flir8g-mint.c -lusb-1.0 -lm'''


    $ find / -name libusb.h 2>/dev/zero
Make sure that both the FLIR's power AND data lines are connected to the Pi, and type:
    /usr/include/libusb-1.0/libusb.h


     $ gcc '-I/usr/include/libusb-1.0' \
     $ '''sudo modprobe v4l2loopback video_nr=1,2'''
          -o flir flir8g-mint.c -lusb-1.0 -lm
     $ '''sudo ./flir'''
    $ 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:
The console should, after a second or two, start spitting out all sorts of camera data in an ongoing stream.


    $ sudo apt install mplayer
To see the camera data as video, install '''mplayer''' on the Pi and run it with some special parameters:
    $ 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:
    $ '''sudo apt install mplayer'''
    $ '''mplayer tv:// -tv driver=v4l2:device=/dev/video1'''


    # Last modified by Ubuntourist <dc.[email protected]> 2016.12.06 (kjc)
Finally, since it's easier than figuring out the RIGHT way to do it, add a couple of lines to '''/etc/rc.local''' to automatically load the recently compiled and installed Video for Linux loopback module upon reboots:


     # 2016.12.06 KJC - Load Video for Linux loopback driver module
     '''# Last modified by Ubuntourist <[email protected]> 2016.12.06 (kjc)'''
     modprobe v4l2loopback video_nr=1,2
    '''# 2016.12.06 KJC - Load Video for Linux loopback driver module'''
     '''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.
== Sample results ==
The stream can be captured to a file named capt.mpeg via the command:
    $ '''mplayer tv:// -tv driver=v4l2:input=1:device=/dev/video1:width=640:height=480 -vf pp=lb -vo yuv4mpeg:file=capt.mpeg'''
The tool "record my desktop" glitched a bit, but you should see something like this [https://www.youtube.com/watch?v=tNHJ2JB33pA High Resolution Video]. However, if you don't set up X11 forwarding, (either by adding a stanza to your .ssh/config as shown above, or by specifying a -X explicitly in the ssh command) then mplayer will do its best to accommodate, and produces this lovely [https://www.youtube.com/watch?v=YJrgaSwYpEo Low Resolution ASCII Art Video].
--[[User:Ubuntourist|Ubuntourist]] ([[User talk:Ubuntourist|talk]]) 05:53, 21 December 2016 (PST)

Latest revision as of 13:53, 21 December 2016

The space has a FLIR One infrared camera which is designed to plug into an Android device. You can watch this review -- among others -- on YouTube.

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. If not, your file is corrupt. This could mean an error in transmission or something more sinister...

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 (and presumably, Debian) the package name is gddrescue but the command itself drops the initial 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

NOTE: The destination device does not contain a partition number.

(Another alternative to dd is to use dcfldd from the package of the same name, which also, unlike dd, provides a progress report as it burns.)

If you've burned the SD correctly, you should now have two partitions -- a root (/) and a boot (/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. There is a GUI to do that, or in a terminal you can use raspi-config.

Images are always out of date. So, fetch the latest and greatest packages for your Pi. And, while you're at it, get Avahi which makes working remotely sooo much simpler.

   $ 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 the appropriate public keys to the appropriate ~/.ssh/authorized_keys file on the appropriate machines you want to talk to each other (and ensuring the permissions on said file are 600), adding a stanza to .ssh/config like:

   # HacDC's FLIR Infrared Camera Pi
   #
   Host flirpi.local
     User pi
     ForwardX11 yes
   Host flirpi
     Hostname flirpi.local
     User pi
     ForwardX11 yes

will let you easily ssh into the Pi without worrying about DNS services or remembering the IP numeric address du boot. (Installing the avahi-utils package is what allows us to use the .local to find the Pi. The above just lets us set up an even shorter alias to that, and to automatically specify the user to connect as -- not to mention the whole forwarding of X11 stuff, which lets us run graphics software on the Pi even if we don't have graphics capabilities on 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 the recently created ~/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

Make sure that both the FLIR's power AND data lines are connected to the Pi, and type:

   $ 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 on the Pi 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 automatically load the recently compiled and installed Video for Linux loopback module upon reboots:

   # 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.

Sample results

The stream can be captured to a file named capt.mpeg via the command:

   $ mplayer tv:// -tv driver=v4l2:input=1:device=/dev/video1:width=640:height=480 -vf pp=lb -vo yuv4mpeg:file=capt.mpeg

The tool "record my desktop" glitched a bit, but you should see something like this High Resolution Video. However, if you don't set up X11 forwarding, (either by adding a stanza to your .ssh/config as shown above, or by specifying a -X explicitly in the ssh command) then mplayer will do its best to accommodate, and produces this lovely Low Resolution ASCII Art Video.

--Ubuntourist (talk) 05:53, 21 December 2016 (PST)