Close

Switching between raspberry pi depending on lighting (day/night)

A project log for Elephant AI

a system to prevent human-elephant conflict by detecting elephants using machine vision, and warning humans and/or repelling elephants

neil-k-sheridanNeil K. Sheridan 09/21/2017 at 19:590 Comments

Now, if everyone recalls. There are two conditions under which we will be spotting elephants: daylight condition and night condition. In the first condition we use the IR filtered camera, in the second we use the NoIR filtered camera with IR illumination from LED array. Hence we need two raspberry pi's each having either NoIR or IR-filtered camera. Since we can't multiplex. I did think we could, but I noticed one of the raspberry pi engineers saying it was very complicated and not worth it. So we are stuck with a more clumsy solution.

So it's easy to use hardware to detect if it's daylight on night condition. Just with a digital sensor such as Adafruit FLORA Lux Sensor - TSL2561 we'd get HIGH or LOW depending on the lux.

Right well, so raspberry pi 1 (daytime) can have at the start of its loop 'is that sensor giving me HIGH for daytime lux or is it giving me LOW for night?'. ' If it gives me LOW I'll break out of the loop and run the code after that'. 

The code after that putting raspberry pi 1 as a server (using SocketServer). Raspberry pi 2 was already waiting as a client.  So now raspberry pi 1 can send a command to raspberry pi 2 'it's time for you to break out of your client waiting loop and take over from me' since it is night condition now and we want the raspberry pi 2 with the NoIR and IR illumination LED array to start spotting elephants.

I guess we can put raspberry pi 1 into another loop now which is just watching for HIGH or LOW on the TSL2561 sensor. Once it gets HIGH it can say 'hey raspberry pi 2 (client)  you are done with that loop. Break out of it and just go back to listening on your socket xxxxx until I tell you it's time to take over'.

Note: well, it's maybe not entirely clear what I mean. But that's my first thought on how to do it!  I'll update when I get to this!

Of course, we don't need the two raspberry pi's to communicate at all in an alternative scenario. They can both have respective lux sensors. The daytime raspberry pi beginning its loop when its sensor gives HIGH (stop on LOW), and the night raspberry pi beginning its loop when its lux sensor gives LOW (stop on HIGH). Presumably we can share the mobile connectivity hardware. Or in worst/ least-elegant case ,they'd each have their own.

Discussions