Posts: 8
Joined: Tue Oct 16, 2018 7:09 pm

Night Vision IR Camera Live Local Stream

Fri Jan 18, 2019 9:07 pm

[Please note: this process has been set up specifically to live-stream and not take photos or record video]

This is a set up for a Raspberry Pi Infrared Camera stream on a Raspberry Pi Zero with a 2.8" Adafruit Resistive Display [with tactile buttons] running on Raspbian full desktop OS and a PiIRCam. Basically, I wanted a unit that acted as a full-time stream of the camera and displayed the feed on a 2.8" screen, so that I can have an Infrared camera unit that I can simply turn on and use. So, if you have an Adafruit 2.8" touchscreen display and a RPi Zero and Raspberry Infrared Camera and would like to program it to stream the camera feed on the display once it boots and subsequently program the buttons on the Adafruit 2.8" Resistive display to halt the system for safe shutdown then read on. (If you simply would like to learn how to program the buttons on the Adafruit 2.8" display to halt the system and reboot depending on hold time, skip to the bottom).

First and foremost make sure that you have your SD card flashed with Raspbian Stretch full desktop OS, note this is specifically set up with Raspbian Stretch full OS. And first run;

Code: Select all

sude apt-get update

Code: Select all

sudo apt-get upgrade
to ensure you have everything you need installed.

I started by using the below tutorial to set up a thermal infrared camera, it shows you the parts and pieces you will need to set up the 2.8" Resistive Display and shows you how to solder the RPi Zero board to the pin header and set up the RPiZero board to hook up to the 2.8" Resistive Display (This can show you how to set all the hardware up accordingly), the tutorial can be found at : ... malCam.pdf

Now that you have set up the hardware accordingly, read on!

The main issue I ran into was this is outdated and wasn't exactly helpful software-wise. Assuming you went with the above tutorial or are just setting up a Raspi Cam and want it to stream on your 2.8" Resistive display when you boot and/or want the tactile button(s) to halt the system then follow the below tutorial (Note if you just want the tactile buttons on your 2.8" Resistive Display to work skip down to bottom);

We will begin by setting up the display. This can be done easily by following Adafruit's Easy Install guide for the 2.8" Resistive Touchscreen Display. You can find the tutorial here; ... -install-2

Or just follow the below instructions taken from said tutorial;

The below code will program the display to function with your RPi Zero ( you will need to hook your RPi Zero up to a monitor or HDMI screen of some sort to program it until the screen is working) open the terminal and enter;

Code: Select all

cd ~
chmod +x
sudo ./
PiTFT Selection
Once you run it you will be presented with menus for configuration.

For the 2.4", 2.8" and 3.2" PiTFT with resistive touchscreen overlay select #1
For the 2.2" PiTFT select #2
For the 2.8" Capacitive PiTFT select #3
For the 3.5" PiTFT select #4

Next you will be asked for the rotation you want, don't worry if you're not 100% sure which you want, you can always change this later by re-running the script

After you run this it will ask you "Would you like the console to appear on the PiTFT display? Y/n" (This is for Raspbian Lite, Select No)

Then it will ask you, "Would you like the HDMI display to mirror to the PiTFT display?Y/n" (This is for Raspbian Full OS, select Yes)

You can also set your screen to run as a raw framebuffing device by selecting No to both these questions.

Now to set up the camera; (this is assuming you have already hooked the PiCam to the Pi already, which BE CAREFUL, super delicate stuff there); if you haven't here is a quick excerpt from; Install the Raspberry Pi Camera module by inserting the cable into the Raspberry Pi. The cable slots into the connector situated between the Ethernet and HDMI ports, with the silver connectors facing the HDMI port. 5. Run "sudo raspi-config" again - you should now see the "camera" option.
You can find a full tutorial here; ... -pi-camera

Now that the camera is set up accordingly, you want to set up the camera stream to run through VLC, the reason for this is that the alternative is typically that you have to run your camera stream through an online server that then displays on the raspi display. This is useful but if you lost internet access on your pi suddenly your camera unit wouldn't work. So setting up through VLC allows us to locally run the stream offline. This was accomplished following another user's, FAPSI, guide. First go into Raspi-config and enable I2C, SPI, and Camera in the interfacing options. Now that you have done that here's what you want to do;

First create a new text file in nano;

Code: Select all

nano /home/pi/stream
Then add this into it and save it once finished;

Code: Select all

raspivid -fps 25 -w 320 -h 240 -t 0 -o - |/usr/bin/cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264
(Note that the height and width are set to the Resistive Display's dimensions 320 x 240.)

Then you need to make the file executable;

Code: Select all

chmod +x stream

Now install VLC to encode the stream;

Code: Select all

sudo apt-get install vlc
you can test this by entering the command;

Code: Select all

Now with FAPSI's guide you can continue onward to put this into a rc.local file to start on boot, however, given the (resistive display) screen becoming disabled with rc.local we don't want to do this, instead we want to use autostart to boot our stream. However, we need to program the tactile buttons before we finalize the stream. To program the buttons we want to use code created by scruss which you can find at the URL below. (It has been tested and works on RPi3, RPi2 and RPiZero, and I believe also Raspbian Full and and Raspbian Lite, you can double check on the site); ...

First, create a file;

Code: Select all

in it write the following code and save the file;

Code: Select all

# -*- coding: utf-8 -*-
# example gpiozero code that could be used to have a reboot
#  and a shutdown function on one GPIO button
# scruss - 2017-10

use_button=27                       # lowest button on PiTFT+

from gpiozero import Button
from signal import pause
from subprocess import check_call


def rls():
        global held_for
        if (held_for > 5.0):
        elif (held_for > 2.0):
        	held_for = 0.0

def hld():
        # callback for when button is held
        #  is called every hold_time seconds
        global held_for
        # need to use max() as held_time resets to zero on last callback
        held_for = max(held_for, button.held_time + button.hold_time)

button=Button(use_button, hold_time=1.0, hold_repeat=True)
button.when_held = hld
button.when_released = rls

pause() # wait forever
save and enter the following commands in the console;

Code: Select all

sudo apt install python3-gpiozero
sudo mkdir -p /usr/local/bin
chmod +x
sudo cp /usr/local/bin
after running all of those your tactile button is now programmed to interface with GPIO pin 27 to run as a shutdown/reboot button depending on boot time, your screen is set up, your pi is updated and configured and your camera and camera stream have been set up. Now all we need is to set these processes up to run on boot. Follow the below instructions, which you can also find at; ... ograms-gui

To finalize the stream and fully set up your module what you will want to do is go into;

Code: Select all

sudo nano /home/pi/.config/lxsession/LXDE-pi/autostart
and add

Code: Select all


Code: Select all

in the line right above;

Code: Select all

@xscreen -no-splash
After this is done, save the file. Now your Stream and your Button program are set to run on boot! Reboot and Enjoy.

P.S. Don't forget to backup/flash your OS so you don't have to go through the mind-raking process all over again.
Last edited by smumpy on Sun Aug 04, 2019 8:54 pm, edited 29 times in total.

Posts: 8
Joined: Tue Oct 16, 2018 7:09 pm

Re: Night Vision IR Camera Live Local Stream

Wed Sep 18, 2019 1:04 am

UPDATE: Just realized I should probably mention that you will need to set up a rig for this guy to operate in, you will need an infrared flashlight, and a power source for this to work. I used Nintendo Switch GuiliKit 10,000 mAh external battery as my power source, my logic here was it is specifically designed to operate for long periods of time and to avoid many typical problems; such as overheating or battery drainage issues, etc... the flashlight i just found a reasonably priced IR flashlight on Amazon, pretty simple stuff. Then I rigged it all to a ViewMaster VR/AR headset that I gutted out. It's been a while since I tested the battery but it ran for something like 7ish hours (if I remember correctly) before dying running the entire camera unit. The flashlight I got rechargeable AA batteries for.

UPDATE: After testing the flashlight I purchased did not have the range I wanted, I now suggest investing in quality products for IR flashlight that states its range and radius and is suitable to what you are looking for.

UPDATE: Found a useful article discussing the best long-range IR flashlights, any one of these should vastly improve the radius of the night vision goggles ... n-reviews/

Return to “Camera board”