Hi. I have a Pi4 with a multi-camera module. Connected to it I have two 2.1 Cameras, one is a NoIR camera, and the other is a normal one.
The NoIR one takes a timelapse all night with raspistill, then in the morning it switches to the normal camera, and does its time lapse, and then after dusk it switches back to the NoIR.
Before a switch, the script kills raspistill with a sigterm. A python script switches cameras by running :
import RPi.GPIO as gp
import os
gp.setwarnings(False)
gp.setmode(gp.BOARD)
gp.setup(7, gp.OUT)
gp.setup(11, gp.OUT)
gp.setup(12, gp.OUT)
gp.setup(15, gp.OUT)
gp.setup(16, gp.OUT)
gp.setup(21, gp.OUT)
gp.setup(22, gp.OUT)
gp.output(11, True)
gp.output(12, True)
gp.output(15, True)
gp.output(16, True)
gp.output(21, True)
gp.output(22, True)
i2c = “i2cset -y 1 0x70 0x00 0x04”
os.system(i2c)
gp.output(7, False)
gp.output(11, False)
gp.output(12, True)
And the script to switch to the other camera is exactly the same except for this :
i2c = “i2cset -y 1 0x70 0x00 0x06”
os.system(i2c)
gp.output(7, False)
gp.output(11, True)
gp.output(12, False)
Every single time it tries to switch, raspistill just stalls. It creates a file with a ~ and seems to wait for sensor data. Typically I just have to kill raspistill, and run the script again which invokes the python switch command again, and then raspistill works fine.
The weirder thing is, that if a few minutes have not passed since the switch first happens, it freezes regardless. I have to wait for a while before trying to switch again and then it will work. I have no idea why. I have checked my cables, they are connected well, and at no other time in the 24 hours a day the cameras run do they cause any issues. It is just the switch. It needs a long break before invoking a second switch command, and trying again.
Can someone help me figure this out? I posted one of the switch scripts, and like i said the other is exactly the same, just different numbers to switch to port C instead of A.
Here is my bash script, you can see where I try to run a dummy raspistill to sacrifice itself to overcome the crash, but my wait time was only 45 seconds, I have increased it to 2 minutes to try again. It is very annoying.
#!/bin/bash
date &>> ~/log/daylapse.log;
killall raspistill;
sleep 5;
killall -9 raspistill;
sleep 2;
python ~/bin/camnorm.py;
sleep 2;
raspistill -th none -n -w 1920 -h 1080 -ISO 100 -awb off -ss 100000 -o ~/WeatherLapse/throwaway.jpg &>> ~/log/daylapse.log &
sleep 120;
killall raspistill;
sleep 2;
killall -9 raspistill;
sleep 2;
python ~/bin/camnorm.py;
sleep 2;
rm ~/WeatherLapse/throwaway.jpg;
rm ~/WeatherLapse/.jpg~;
raspistill -th none -n -ae 48,0x00,0x8080FF -a 12 -w 1920 -h 1080 -tl 15000 -awb off -t 90000000 -sh 30 -co 20 -sa 10 -awb cloud -mm matrix -o ~/WeatherLapse/day%05d.jpg &>> ~/log/daylapse.log &
ffmpeg -loglevel error -nostdin -r 30 -i ~/WeatherLapse/night%05d.jpg -c:v libx264 “/mnt/Share/Capture/WeatherLapse/Complete/$(date +”%y-%m-%d")-1-Night.mp4" &>> ~/log/nightvideo.log;
mkdir /mnt/Share/Capture/WeatherLapse/$(date +"%y-%m-%d");
mv ~/WeatherLapse/night.jpg /mnt/Share/Capture/WeatherLapse/$(date +"%y-%m-%d")/ &>> ~/log/daylapse.log &