smumpy
Posts: 12
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
and;

Code: Select all

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

you will want to disable the screensaver first you can accomplish by either of the below methods
3.1 – Install xscreensaver
xscreensaver is a screen saver utility for X Windows. Run the following command to install it:

$ sudo apt-get install xscreensaver
Once installed, go to Preferences option in the main desktop menu. You should find the screen saver application. Launch it and search for the option to disable it completely.

– via.

3.2 – Updating LXDE-pi/autostart
In root mode, edit the following file: /home/pi/.config/lxsession/LXDE-pi/autostart and add the following lines:

@xset s off
@xset -dpms
@xset s noblank
These lines are the same than section 1. This technique should be persistant.

these were taken from:
https://www.geeks3d.com/hacklab/2016010 ... -raspbian/

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 :

https://github.com/rgrokett/RaspiTherma ... 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;

https://learn.adafruit.com/adafruit-pit ... -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 ~
wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/adafruit-pitft.sh
chmod +x adafruit-pitft.sh
sudo ./adafruit-pitft.sh
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 thepihut.com; 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;
https://thepihut.com/blogs/raspberry-pi ... -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

./stream
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);

https://github.com/scruss/shutdown_butt ... _button.py

First, create a file;

Code: Select all

nano shutdown_button.py
in it write the following code and save the file;

Code: Select all

#!/usr/bin/python3
# -*- 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

held_for=0.0

def rls():
        global held_for
        if (held_for > 5.0):
                check_call(['/sbin/poweroff'])
        elif (held_for > 2.0):
                check_call(['/sbin/reboot'])
        else:
        	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 shutdown_button.py
sudo cp shutdown_button.py /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;

http://www.raspberry-projects.com/pi/pi ... 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

@/home/pi/stream
and

Code: Select all

@/usr/local/bin/shutdown_button.py
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 Thu Oct 31, 2019 1:29 am, edited 30 times in total.

smumpy
Posts: 12
Joined: Tue Oct 16, 2018 7:09 pm

Re: Night Vision IR Camera Live Local Stream

Thu Oct 03, 2019 3:59 pm

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

https://thegunzone.com/best-ir-illumina ... n-reviews/

UPDATE: After installing the new flashlight onto the gear I have accomplished sufficient short-range IR night-vision (about 20-40 feet clear visible range), however long-range has yet to be accomplished (though flashlight is capable of projecting up to 100-yards, it is not a sufficient enough beam to see clearly)
- will continue testing new ideas and see if I can solve the problem, will update with future advancement
Last edited by smumpy on Thu Oct 31, 2019 3:17 pm, edited 2 times in total.

smumpy
Posts: 12
Joined: Tue Oct 16, 2018 7:09 pm

Re: Night Vision IR Camera Live Local Stream

Wed Oct 30, 2019 9:45 pm

UPDATE: 10-30: Wondering if there is an alternative power source that would be more compact for the project ? Maybe rechargeable batteries that could be rigged to the unit? The Nintendo battery pack I purchased is quite clunky and heavy

EDIT: found a flaw in my setup, screensaver activates after a set amount of time and shuts the unit down, going to find fix and update later

smumpy
Posts: 12
Joined: Tue Oct 16, 2018 7:09 pm

Re: Night Vision IR Camera Live Local Stream

Thu Oct 31, 2019 3:16 pm

UPDATE: after trying to implement the fix for the screensaver it now appears that there is some glitch not allowing me to download the pitft adafruit installer scripts from

https://raw.githubcontent.com/adafruit/ ... t-pitft.sh

i initiate
cd ~
wget https://raw.githubcontent.com/adafruit/ ... t-pitft.sh

and am met with:
connecting to raw.githubcontent.com (raw.githubcontent.com)...
. failed: Connection timed out.
Retrying

I also have run into
Connection refused

does anyone know why this is or run into the same issue when trying to download the pitft setup?
Last edited by smumpy on Thu Oct 31, 2019 3:26 pm, edited 1 time in total.


smumpy
Posts: 12
Joined: Tue Oct 16, 2018 7:09 pm

Re: Night Vision IR Camera Live Local Stream

Thu Oct 31, 2019 3:25 pm

@DirkS
That is the same link I posted, I am unsure what you are suggesting to do, i have read through it but this error is not listed, this seems to be a network issue if i had to guess

one suggestion i've found online is that this error can be caused by the raspberry pi disabling ssh by default so add a ssh file on pc then boot the pi from ssh, i will try doing this if i cannot find another fix
https://www.raspberrypi.org/forums/view ... p?t=170636

DirkS
Posts: 10363
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Night Vision IR Camera Live Local Stream

Thu Oct 31, 2019 3:38 pm

smumpy wrote:
Thu Oct 31, 2019 3:25 pm
@DirkS
That is the same link I posted,
No it isn't...
it's githubcontent vs githubusercontent.

smumpy
Posts: 12
Joined: Tue Oct 16, 2018 7:09 pm

Re: Night Vision IR Camera Live Local Stream

Thu Oct 31, 2019 5:14 pm

aaaaah snap, thanks my dude! damn these crooked old eyes of mine, gotta head out atm, thanks @DirkS

Return to “Camera board”