Raspberry Pi in the NoIR - Part VII - control the lights
Updated: May 24, 2020
If you don't know what this blog is about, go back to Part I to find out.
You are almost finished. Let's recap. You formatted the SD card, assembled the Pi, connected the lights, tested the OS and made your connection wireless. Now, let's work out how to control those lights. Note: if you only want diurnal cameras you can skip ahead to assembling the container housing.
Test the lights:
Connect to your Pi unit using ssh and the router.
> ssh email@example.com
> curl -sSL https://pisupply.ly/brightpicode | bash
This will clone the BrightPi code into the Pi unit and then reboot the system.
Connect to the Pi again using ssh.
You should now see a BrightPi directory in the Pi.
If you were to change directory and snoop around in the BrightPi directory (> cd Bright-Pi/) you would find a README file that contains detailed info on what lights do what. Here's the slightly confusing part. One part of the documentation says the white LEDs should be numbered 1-4 and the IR LEDs should be numbered 5-8 (in pairs). But elsewhere in the documentation it says the white LEDs are numbered 2, 4, 5, 7 and the IR LEDs are numbered 1, 3, 6, 8.
Anyway, let's test the BrightPi lights using a python script that comes with our installed directory (Bright-Pi/build/scripts-3.7). You can run this script from the 'home' directory.
Make lights and camera 'talk':
At this point you will be mesmerized by blinking and strobing lights. Once you pull yourself away, you can select the interfacing options to make the camera and lights 'talk' to one another.
> sudo raspi-config
Select option 5, then P5 12C, then enable.
Once you reconnect to the Pi test your 12C connection.
>sudo i2Cdetect -y 1
This will show the devices using the 12C pins.
Control the lights:
I found some basic python scripts to control the lights. Install them using:
> sudo git clone https://github.com/raspberrycoulis/brightpi-control.git
You should now see a bightpi-control directory.
In this brightpi-control directory are scripts for running the white LEDs only (white-on), the IR lights only (IR-on) and turning all lights off (all-off). Alternatively, you could make your own scripts using something like:
> sudo i2Cset -y 1 0x70 0x00 0x5a
This is all great, I hear you say, but this means my lights are either on or off all the time. Fear not! We will control that (loosely) too.
For my purposes, I really only want the IR lights on when it starts getting dark. I made a script that calls on crontab to activate and deactivate the lights at certain times. If it gets dark at 10:30 pm that's when I want my lights to come on, then I want them to shut off around 5 am. Crontab.guru can give you more information on use of crontab.
> sudo crontab -e
At end of file add the schedule you want. For example:
> 0 21 * * * /bin/sh /home/pi/brightpi-control/IR-on.sh
>0 8 * * * /bin/sh /home/pi/brightpi-control/all-off.sh
Now, you can put all your components in their field housing.