A Robot With A CCTV Camera ? That You Control via The Internet?
The idea was to use a Pan / Tilt HAT and then add a camera to make a CCTV system, make it accessible / controllable from the Internet and contain it in something unusual looking; something that I wouldn’t mind having on a shelf (maybe a robot?).
It’s a good starting point in getting a pan / tilt Hat working and sending images to the Internet.
All of the bits for the robot CCTV build
Some partially assembled pieces:
- 1 x Pi 3A
- 1 x Pan / Tilt HAT
- 1 x Camera module
Not shown are:
- 1 x NeoPixel Stick
- A diffuser (which came with the NeoPixel Stick)
RasPi3A and PanTilt Camera
Some extra long nylon bolts were added so that the Pi could be mounted underneath the HAT.
These were far too long but needed.
I could have trimmed them but as the finished unit was never going to be visible I left them alone.
Pi3A Board and Extension Screws
You can see that the bolts are too long but as I mentioned I decided to leave them untrimmed.
Assembled Side View
It’s quite a squeeze but it all fits.
Tight Squeeze!
The fully assembled top view with the clearly visible NeoPixel Stick.
The stick was a late build decision but it does look good!
It was always an option that then provided me with the opportunity to write a neat menu system for the lights.
Assembled Top View
As the whole thing is to be encased and impossible to adjust or repair, I made sure that the connectors wouldn’t budge.
Hot Glue Keeping Wires Secure
Did I mention hot glue? Here again making sure that the nylon bolts on the camera module stay in place.
Hot Glue Keeping Camera Module Secure
Finished
The whole unit in its final resting place, standing tall!
Screwbot Standing Tall
Bit of a close up of the Pan / Tilt unit and camera.
It’s a odd looking CCTV system for sure being housed in a recycled robot.
A big thank-you to ScrewedSculpts for his work on the robot, I just did the nerdy bits.
Screwbot Closeup
Making the robot move and operate the CCTV remotely
There are quite a few guides on how to do this, and I also found some of them a bit too confusing.
After a few bungled attempts then, I distilled them into a few simple commands.
The obvious starting place is to install the Pimoroni libraries:
curl https://get.pimoroni.com/pantilthat | bash
And then check that it’s all working:
cd /home/foo/Pimoroni/pantilthat/examples<br></br>python smooth.py
The RPi-Cam-Web-Interface is also needed:
NOTE – Enabling the Camera
Bullseye OS has replaced the camera stack which stopped the raspimjpeg working.
Legacy camera support should be enabled.
Do this within raspi-config under Interface.
If this shows just “Enable camera” then update raspi-config itself from its menu item.
The interface option should now show enable Legacy camera support.
The Pi will reboot.
The install.sh script will detect a Bullseye OS, set the right PHP version and create a missing directory needed by this software to run.
To do this you will need to clone the code from github and enable and run the install script with the following:
git clone https://github.com/silvanmelchior/RPi_Cam_Web_Interface.git<br></br>cd RPi_Cam_Web_Interface<br></br>./install.sh
Configure accordingly with the cam folder at ‘/html/wherever-you-like’.
OK & Wait for ‘Start’.
Locally, at ‘http://Your-Pi-IP-Address/html/wherever-you-like’ there should be an image.
Also on the Pi, in a browser, at URL ‘http://127.0.0.1/html/wherever-you-like’ there should be an image.
Configure the pan and tilt Hat for RPi-Cam-Web-Interface
This part can be confusing but if the following steps are taken, a working image should appear on a web page of your choice.
Firstly, rename pipan_off to enable the browser direction arrows (needs a browser refresh):
cd /var/www/html/wherever-you-like<br></br>sudo mv pipan_off pipan_on
Add a FIFO pipe:
cd /var/www/html/wherever-you-like sudo mknod FIFO_pipan p sudo chmod 666 FIFO_pipan
Create a pipan-pipe.py on the Pi:
nano pipan_pipe.py
The one I used came from this post: https://forums.pimoroni.com/t/rpi3-camery-pimioroni-adafruit-pan-tilt-rpi-cam-web-interfac/3263/13
The important line is this one:
pipein = open("/var/www/html/wherever-you-like/FIFO_pipan", 'r')
Save it somewhere sensible (mine went in my Home folder).
Check that it’s working:
cd /home/foo python pipan_pipe.py
Edit /etc/rc.local and add the following line above the exit-command:
(Change the path to the directory where you saved the pipan-file).
sudo nano /etc/rc.local python /home/foo/pipan_pipe.py &
If you see this, then put the above lines ^^ above it.
#START RASPIMJPEG SECTION
Finally, it may need a reboot but the Pan / Tilt HAT should now be operable via a browser.
Connecting to the outside world
As the ‘RPi-Cam-Web-Interface’ comes with a web server, it can serve requests from the internet.
However, on my router port 80 traffic goes to a web server where it determines where to send that request internally.
An easier route would be to direct port 80* traffic to the Pi where all of the above magic takes place.
(This only applies if it was port 80 that was chosen to serve requests when installing ‘RPi-Cam-Web-Interface’.)
Adding the NeoPixel stick menu
I then added a bash menu to control the lights.
At the moment all the options link to the Pimoroni examples, apart from the ‘Sleep’ which turns the pixels off and returns the head back to its starting position.
The menu
#!/bin/bash
HEIGHT=15
WIDTH=40
CHOICE_HEIGHT=4
BACKTITLE="robotcam Neopixel Lights"
TITLE="Neopixel Stick Examples"
MENU="Choose one of the following options:"
OPTIONS=(1 "360 White"
2 "360 Rainbow"
3 "Smooth Sweep"
4 "Staggered Sweep"
5 "Sleep")
CHOICE=$(dialog --clear \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--menu "$MENU" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${OPTIONS[@]}" \
2>&1 >/dev/tty)
clear
case $CHOICE in
1)
python ~/Pimoroni/pantilthat/examples/grbw.py
;;
2)
~/Pimoroni/pantilthat/examples/neopixels.py
;;
3)
~/Pimoroni/pantilthat/examples/smooth.py
;;
4)
~/Pimoroni/pantilthat/examples/timeout.py
;;
5)
~/Pimoroni/pantilthat/examples/sleep.py
;;
esac
The ‘Sleep’ bit
#!/usr/bin/env python
import pantilthat
pantilthat.light_mode(pantilthat.WS2812)
pantilthat.light_type(pantilthat.GRBW)
r, g, b, w = 0, 0, 0, 0
while True:
for x in range(18):
pantilthat.set_pixel(x, r, g, b, w)
pantilthat.show()
p = 0.00
t = 0.00
pantilthat.pan(p)
pantilthat.tilt(t)
I hope that the above helps anyone also looking to do something similar.
It’s not a straightforward process, especially getting the ‘RPi-Cam-Web-Interface’ up and running; it is however worth the effort.
And Finally
These are both excellent reading and flesh out the above a bit more:
All of the Pan-Tilt-HAT code examples can also be found on Forgejo .