Pi based scientific camera setup
Posted: Tue Oct 23, 2018 11:57 pm
Hi all! I've spent a few weeks hacking together a system for monitoring animal behavior longitudinally. It seemed to be working well through all our initial tests, but when actually deployed in an experiment it all fell apart haha. I have a few weeks till our next use of the system, so I have some time to improve it, but I'd very much appreciate some best practices advice. Issues I've run into include power-regulation, corruption of HDD filesystems, and some problems with the picamera library. If these sound like interesting problems to you, keep reading! (also, I'm a biochemist/neurobiologist, not an EE, so I apologize in advance for incorrect terminology) Below I lay out a few issues, and any advice on any individual issue would be great, so if you get bored reading, no worries.
Basically, I'm using the [url = http://www.arducam.com/multi-camera-ada ... pberry-pi/]arducam multicamera [/url] adapter to cycle through multiple cameras and save the images to a hard drive. We went with the multicamera adapter vs individual pi's to try and reduce the number of components needed and keep costs lower for other labs. The multicamera adapter basically takes GPIO input to select which of 4 CSI port feeds through to the pi. By stacking two of these boards on top of each other, I was controlling 6 cameras.
OK FIRST ISSUE.
First of all, having multiple cameras plugged in invariably leads to a low-voltage warning. No matter what amp wall plug we used, going into the usb power supply never seemed sufficient. I measured ~4.6v on the 5V GPIO pins. Eventually, I just soldered some wires to a 5.3V power supply, and went directly to the 5V rail. I still was only reading 4.8v across those same input pins with load, with the occasional dip to 4.6, but we don't have an oscilloscope, so that's just off a voltmeter. This helped a bit, but obviously makes me nervous as I'm bypassing the protection of the power supply circuit. I'm planning to upgrade to a switching 20A 5V power supply, as lots of problems seem to coincide with voltage drops. Any advice on why this might be happening? ALSO it feels like performance is degrading over time when I use the pi's, but I havent been able to give them a couple days to cool off and reset. All I know, is that when I first used my jerry-rigged 5V direct power supply the pi was just screaming along, capturing images well and with noticeably faster performance. The next day, after about 10 hrs of image capture and a crash it behaved much more sluggish and I got more frequent low voltage warnings.
EXPLANATION INTERMISSION
We were aiming for 1hz capture rate off of 6 cameras, which meant acquiring images needed to happen on the order of 0.167s. In order to achieve that, I used the picamera continuous_capture function, which can be used as an infinite generator. the code basically goes as follows, and as far as I can tell the capture event happens at the start of each loop:
for cam in continuous_capture():
change gpio pins to activate next camera
check time since last loop
sleep till the next camera should capture, unless its already been too long
This generally works well, especially over short captures. However, there are occasional hiccups where a loop takes 2 seconds or more. I'm not sure what the bottleneck is that's causing those hiccups.
This generates a HUGE number of individual files, that I will concatenate into videos. Another strange occurrence is that occasionally, I get two pics in a row from the same camera, despite the GPIO pin swap. Its rare, but is going to make collecting the images that belong to each camera much more difficult.
OK NEXT ISSUE.
Sometimes the python code running the cameras hangs, and I cant seem to disconnect from the cameras after a keyboard interrupt. I am using a with Picamera() as cam call to try and mitigate these communication issues, but when it happens I cant even reboot the pi. it hangs on shutdown and I need to manually unplug it.
OK NEXT ISSUE.
I'm getting very inconsistent connections to our data storage HDDs (4TB, exFAT). I think this is related to the low voltage issues I'm having. Sometimes, if images are capturing, and I try and open the folder where the images are being saved, the pi kind of half-way crashes and all of the folder windows close. Then, I lost the ability to read one of the HDDs on my Mac, even though it's read just fine on the pi.
OK THANKS!
Hey, if you read all that, thanks so much! Any advice on any little issue would be greatly appreciated. I'll gladly pay anyone back with beer, or tutoring in biology.
Basically, I'm using the [url = http://www.arducam.com/multi-camera-ada ... pberry-pi/]arducam multicamera [/url] adapter to cycle through multiple cameras and save the images to a hard drive. We went with the multicamera adapter vs individual pi's to try and reduce the number of components needed and keep costs lower for other labs. The multicamera adapter basically takes GPIO input to select which of 4 CSI port feeds through to the pi. By stacking two of these boards on top of each other, I was controlling 6 cameras.
OK FIRST ISSUE.
First of all, having multiple cameras plugged in invariably leads to a low-voltage warning. No matter what amp wall plug we used, going into the usb power supply never seemed sufficient. I measured ~4.6v on the 5V GPIO pins. Eventually, I just soldered some wires to a 5.3V power supply, and went directly to the 5V rail. I still was only reading 4.8v across those same input pins with load, with the occasional dip to 4.6, but we don't have an oscilloscope, so that's just off a voltmeter. This helped a bit, but obviously makes me nervous as I'm bypassing the protection of the power supply circuit. I'm planning to upgrade to a switching 20A 5V power supply, as lots of problems seem to coincide with voltage drops. Any advice on why this might be happening? ALSO it feels like performance is degrading over time when I use the pi's, but I havent been able to give them a couple days to cool off and reset. All I know, is that when I first used my jerry-rigged 5V direct power supply the pi was just screaming along, capturing images well and with noticeably faster performance. The next day, after about 10 hrs of image capture and a crash it behaved much more sluggish and I got more frequent low voltage warnings.
EXPLANATION INTERMISSION
We were aiming for 1hz capture rate off of 6 cameras, which meant acquiring images needed to happen on the order of 0.167s. In order to achieve that, I used the picamera continuous_capture function, which can be used as an infinite generator. the code basically goes as follows, and as far as I can tell the capture event happens at the start of each loop:
for cam in continuous_capture():
change gpio pins to activate next camera
check time since last loop
sleep till the next camera should capture, unless its already been too long
This generally works well, especially over short captures. However, there are occasional hiccups where a loop takes 2 seconds or more. I'm not sure what the bottleneck is that's causing those hiccups.
This generates a HUGE number of individual files, that I will concatenate into videos. Another strange occurrence is that occasionally, I get two pics in a row from the same camera, despite the GPIO pin swap. Its rare, but is going to make collecting the images that belong to each camera much more difficult.
OK NEXT ISSUE.
Sometimes the python code running the cameras hangs, and I cant seem to disconnect from the cameras after a keyboard interrupt. I am using a with Picamera() as cam call to try and mitigate these communication issues, but when it happens I cant even reboot the pi. it hangs on shutdown and I need to manually unplug it.
OK NEXT ISSUE.
I'm getting very inconsistent connections to our data storage HDDs (4TB, exFAT). I think this is related to the low voltage issues I'm having. Sometimes, if images are capturing, and I try and open the folder where the images are being saved, the pi kind of half-way crashes and all of the folder windows close. Then, I lost the ability to read one of the HDDs on my Mac, even though it's read just fine on the pi.
OK THANKS!
Hey, if you read all that, thanks so much! Any advice on any little issue would be greatly appreciated. I'll gladly pay anyone back with beer, or tutoring in biology.