motioneyeos icon indicating copy to clipboard operation
motioneyeos copied to clipboard

Mech. IR-CUT Filter uses Camera Led I/O to switch

Open bigplums opened this issue 8 years ago • 14 comments

Hi, I have this camera which uses the camera on led I/O to actuate the mechanical IR-CUT filter. I wanted to know if there was anyway to be able to have this automatically switch over to 'Night mode' (led I/O = LOW) without any human intervention when the camera is in low light?

Im using this camera on a Pi Zero W.

Many thanks in advance Ross

bigplums avatar Jun 29 '17 07:06 bigplums

@bigplums I'm interested in trying out the same camera that you have. Optically detect light level and controlling the IR-cut filter via camera red LED would be an elegant solution if achievable.

First, we need to workout, on the Pi Zero W, which GPIO controls the camera red LED. There's some information about controlling the camera LED here, but no info about Pi Zero W. Controlling the LED via GPIO is simple.

Second, we need to modify motion software to optically detect light level. This is the difficult part. How do you optically detect "day light" reliably? The problem is, we need to detect "day light" by filtering out infra-red because we have IR LED light for "night vision". We don't want to false detect this IR LED light as "day light" and activate the IR-cut filter at night. Is comparing the red channel in the image against blue and green going to be reliable enough? (red sensors in camera are most sensitive to IR) Maybe a much easier solution is to add an LDR like this: fi8904w-sensors Notice the LDR has an IR-cut filter?

jasaw avatar Jul 18 '17 02:07 jasaw

In the end I ended up keeping it simple and just used a CdS cell, transistor and resistor to trigger the IR-CUT Filters I/O which is shown here

It would be nice if there was some built in way of triggering the Pi I/O on an event in MotionEyesOS I would think it could have quite a few handy uses - maybe thats something for the Devs to mull over one day if they get time from fixing the more important bits first!

Ross

bigplums avatar Jul 18 '17 11:07 bigplums

Landed here looking for a solution to the same problem - Being able to use camera action buttons to manually switch to/from IR mode would be a start. It's all dependant on being able to map a GPIO on the Pi Zero to the camera LED. Has anyone else tried this on a Pi2 or Pi3 while running Motioneyeos? Failing that I was looking at the IR led board circuit and was wondering if there was suitabl point on that board to take a logic signal from to patch over to the camera I/O pad. @bigplums could you post a link to a schematic for the circuit you used as a workaround please?

charemer avatar Aug 04 '17 09:08 charemer

Camera LED can be controlled from software. This may be too technical for some, so a pull-request would be nice. :-)

Pi-B

echo 5 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio5/direction
echo 1 > /sys/class/gpio/gpio5/value
echo 0 > /sys/class/gpio/gpio5/value

Pi-B+, Pi2

echo 32 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio32/direction
echo 1 > /sys/class/gpio/gpio32/value
echo 0 > /sys/class/gpio/gpio32/value

Pi3 Control via the Mailbox interface (/dev/vcio) This C program can be used to control the camera LED.

Pi Zero W I haven't found any information, but from the schematic, it looks very similar to Pi3, so I would try the Pi3 method first.

jasaw avatar Aug 04 '17 16:08 jasaw

I've found the answer the Pi Zero W camera led can be controlled from gpio40.

echo 40 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio40/direction
echo 1 > /sys/class/gpio/gpio40/value
echo 0 > /cys/class/gpio/gpio40/value

I should add a thankyou to @jasaw for posting the Pi3 answer which led me to the dt-blob.dts file.

charemer avatar Aug 07 '17 10:08 charemer

@charemer Thank you for sharing the information.

jasaw avatar Aug 08 '17 02:08 jasaw

It is now possible to buy the Raspberry Pi Camera with IR-CUT filter that automatically switches to night mode when it gets dark.

It eliminates the need to manually control the IR-CUT filter.

See the inserted link.

https://www.aliexpress.com/item/Latest-Raspberry-Pi-3-Model-B-IR-Cut-Camera-5MP-Night-Vision-Automatic-Day-and-Night/32831967873.html

ir-cut

SuneBielefeldt avatar Sep 09 '17 14:09 SuneBielefeldt

Hey Bielefeldt, works good with this cameramodel which you posted? Have you a Link to a Forum? Thanks,

davimas avatar Jan 22 '18 12:01 davimas

Hey Davimas No, I do not know other MotionEye forums than this, but it works well too.

Have now used the ir cut camera for some months and am fully satisfied with it.

SuneBielefeldt avatar Jan 22 '18 13:01 SuneBielefeldt

Hey, Thanks. I bought Yesterday in AliExpress this IR CUT RaspiCam. When you use it in Motioneye with MDetection, you became a Alarmmessage when the Cam Switch the Filter? I think yes, every picture change send me a Message.......

davimas avatar Jan 23 '18 17:01 davimas

Hi, I want to bump this a little. The solution from @charemer worked perfectly so far but has to be done manually, obviously. An Expert option where you can enable when the picture gets too dark to run a command and vice versa when it gets bright again would be a real awesome thing for this! :)

EpicLPer avatar Apr 26 '18 10:04 EpicLPer

@EpicLPer Using the camera image to determine when to enable/disable the IR-cut filter would be very tricky (assuming you have IR lights) because the IR light will interfere with day-light detection. Read my earlier comments for more details. You're better off using a different method to detect day-light.

I'm also using this camera with manual IR-cut filter, and I've built a simple light-dependent resistor (LDR or CdS) with small IR-cut filter to detect light, and some IR-LEDs for illumination. I've also written a simple LDR reader program that reads the LDR and sets GPIOs to high/low and runs commands. It has been working well for me.

jasaw avatar Apr 27 '18 00:04 jasaw

On 2018-04-26 11:39, EpicLPer wrote:

Hi, I want to bump this a little. The solution from @charemer [1] worked perfectly so far but has to be done manually, obviously. An Expert option where you can enable when the picture gets too dark to run a command and vice versa when it gets bright again would be a real awesome thing for this! :)

-- You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub [2], or mute the thread [3].

I used incron and the program remind to automate setting dusk and dawn times each day at which to switch the IR filter.

One job runs just after noon each day to set the following dusk dawn cycle. by creating new at tasks.

Links:

[1] https://github.com/charemer [2] https://github.com/ccrisan/motioneyeos/issues/1013#issuecomment-384594160 [3] https://github.com/notifications/unsubscribe-auth/AdTBdYGv_bhft1pervhJ-TiFamWoNqCuks5tsaP_gaJpZM4OI7yh

charemer avatar Apr 27 '18 09:04 charemer

I've found the answer the Pi Zero W camera led can be controlled from gpio40.

echo 40 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio40/direction
echo 1 > /sys/class/gpio/gpio40/value
echo 0 > /cys/class/gpio/gpio40/value

I should add a thankyou to @jasaw for posting the Pi3 answer which led me to the dt-blob.dts file.

Unfortunately, for the Pi Zero 2 W, Pin 40 is now "Camera shutdown" . https://github.com/raspberrypi/firmware/blob/master/extra/dt-blob.dts has the following in the "pins_pi02w " section

pin_define@CAMERA_0_LED { type = "absent"; };

Unfortunately, this is no longer an option :(

Edit : confirmed here : https://forums.raspberrypi.com/viewtopic.php?t=339824

Confirmed with the hardware guys - CAM_GPIO1 is not connected on Pi02W.

fschlaef avatar Dec 28 '23 01:12 fschlaef