Have you ever walked through a meadow, gazing at all the flowers around you, wondering why there are so many different types of flowering plants? So far, more than 352000 different species have been described, and there are still many more out there awaiting discovery. One of the main reasons for this diversity is the often very specific interaction of flowering plants with the animals that visit and pollinate their flowers. Pollinators often have very clear preferences regarding flower colour, scent, and shape, and slight changes in these signals can dramatically change the attractiveness of a flower.
We are a bunch of biologists studying the fascinating world of plant-insect interactions. Our study system is the plant Gorteria diffusa, a daisy from South Africa with a particularly nifty pollination trick: It has bright orange flowers speckled with black, hairy spots, which attract both males and females of the bee-fly Megapalpus capensis. While female flies are mainly interested in slurping nectar, the males are (how else could it be), mainly interested in females. Sometimes, they mistake one of these black flower spots for a female and start copulating (yes, copulating) with the flower.
Gorteria diffusa flowers with black spots waiting for horny pollinators
In summer 2019, we went to South Africa to to get some footage of this scandalous pollinator behaviour. Unfortunately, Gorteria grows rather remotely in the semi-desert of Namaqualand. So instead of grilling some poor students under the African sun, we decided to build and program autonomous Raspberry Pi-based photo and video cameras. As we were far off the beaten track, and our coding usually makes computer scientists cringe, we decided to keep this project as simple as possible.Camera version I (pre-fieldwork)Camera specifications
To capture both the preferences and the behaviour of pollinators, we aimed to build cameras with the following specifications:
- Switch between photo and video mode
- Adjust image resolution and video length
- Take photo or video sequences at predefined time intervals (time-lapse)
- Time-stamp images and movies, and save each run in its own folder
- Run on batteries for up to 6 hours, and power off the Pi after execution
- Shield all hardware from the elements
The main focus of the project was to get as much flexibility and runtime as possible while keeping down the price, dimensions, and environmental impact. We thus opted for the Raspberry Pi Zero with its proprietary camera, and evaluated the runtime of several rechargeable batteries. Initially we opted for a system with a voltage regulator allowing to connect both Li-ion and Li-Polymer batteries, but since most Li-ion power banks are now fairly cheap and have an output of exactly 5V, we decided to drop the regulator to reduce the risk of failure.Camera assembly and programming
Since we are only using pre-assembled parts, the assembly and programming are a piece of cake:
- Give the power bank a good charge overnight.
- Set up the Pi and SD card according to the generic tutorial.
- Connect the Pi to the camera according to the generic tutorial.
- Create a new folder "Camera"
pi@raspberrypi:~ $ mkdir /home/pi/Camera
- Create a new file "camera_script.py" and paste the content of the python camera script (or download and move the script from here).
pi@raspberrypi:~ $ nano /home/pi/Camera/camera_script.py
- For initial testing, adjust the variables to something that is executed quickly (see "Camera usage" below for explanation).
pi@raspberrypi:~ $ nano /etc/profile
- Add the two lines below at the bottom of the profile. This enables running the script upon startup in headless mode.
- Reboot the Pi for testing.
pi@raspberrypi:~ $ sudo reboot now
- If everything went well, the Pi should now reboot and automatically take 3 Photos in an interval of 5 seconds. In headless mode, camera activity can be checked by observing the red LED on the ribbon cable. To allow for a smooth booting of the Pi, the script includes a lag time of 50 seconds until the first photo or video is taken. The photos should now be in a folder called "BOOT1", and there should be a file called "NR.TXT" containing the counts for the folder naming.
pi@raspberrypi:~ $ ls /home/pi/Camera/BOOT1
- Now to some hardware assembly: Add cut to size pieces of double-sided foam tape (UV-resistant) to the underside of the Pi, as well as a strip of tape over the back of the camera. Don't put any tape on the ribbon cable!
- Tape the camera and Pi in place as shown in the photo. Make sure that all ports and the SD card slot are still accessible. In our case, the box was transparent enough to still get a decent image without compromising sealing. However, one could drill a small hole for the camera lens and seal it with silicone.
- Connect the charged power bank to the Pi, close the box, and aim at your target of desire.
Camera "assembly" in the lid of the box. As simple as it gets for working in a remote place.
The behaviour of the camera is controlled by adjusting the input variables in the
camera_script.py script. Consider power bank capacity and SD card size when choosing parameters to prevent SD card corruptions. Also, remember that the pictures and videos will be saved in a new folder whenever the Pi is rebooted. In the field, we would simply access the script by popping the SD card in a laptop with a Linux OS, but other options such as ssh into the Pi, or connecting a small LCD screen to the GPIO pins might also be worth a try.
VID is a boolean operator,
False enables picture mode,
True enables camera mode
Picture mode variables
VID = False
NP defines the number of pictures per series
PWT defines the interval between pictures within a series in seconds
NPX defines the number of picture series
DTP defines the interval between picture series in seconds. Set to
0 for continuous shooting
crot (generic) defines the image orientation in
cres (generic) defines the image resolution in dpi
Video mode variables
VID = True
VWT defines the length of individual videos in seconds
NV defines the number of videos per series
DT defines the interval between videos in seconds
To reset the system after downloading the photos and/or videos, delete the BOOT folders and the NR.TXT file.
Fieldwork experiences with the camera
pi@raspberrypi:~ $ rm -r /home/pi/Camera/BOOT*
pi@raspberrypi:~ $ rm /home/pi/Camera/NR.TXT
After 42 South African sunrises, 3500 Km pad, 36 experimental plots, 540 flower arrays, 3356 sheep, 7 eagles, 4 snakes, and 53 l rooibos we can state that we were positively surprised about the overall performance of the cameras (and especially the power banks!). We have experimented with various photo and video settings, and decided to do 3 × 30 min intervals of 1 frame/sec photo series in our final experiment. This has left us with more than 400000 flower photos, mounting up to more than 3.5TB of data, which are now awaiting processing.
Our field setup (here with an array of flowers mounted on a beer crate): The camera box is attached to a shelf bracket mounted to a fence post with plumbing clamps.
However, it would not be fieldwork if everything went according to plans, and we obviously learned various lessons down there:
Camera version II (post fieldwork)Camera improvements
- Lesson #1: Food boxes are unhandily. After plundering a local farm shop, we attached the camera boxes with velcro and rubber rings to shelf brackets connected with plumbing clamps to metal fence posts. This construction was sufficiently windproof, but made aiming at target flowers relatively difficult. Also, the glue of the velcro strips tended to melt down in the sun.
- Lesson #2: Climate change is real. During our field time, South Africa endured an exceptional winter heat wave with temperatures up to 35°C. On some sampling days, there was thus considerable buildup of heat in the camera cases, leading to a reduced processing performance of the Pi computers.
- Lesson #3: SD card ≠ SD card. Due to delivery problems, we had to acquire the 32GB SD cards from various manufacturers. Surprisingly, we encountered manufacturer-specific performance problems, ranging from a slight decrease in processing speed to total lack of compatibility. The SD cards which worked best for us all came from SanDisk.
- Lesson #4: Africa is not for sissies. The optics of the Pi zero camera module was on the lower limit for the designated task: Images were often blurry, adjusting the focal length was tedious, and the rough roads and desert sand damaged some lenses beyond repair.
After fieldwork, we tried to learn from these lessons, and built a new version of the camera that should address all observed issues:
- The camera is now housed in a proper camera case, which is available online as "dummy cctv camera" for little money. The model we chose has a couple of useful features: It is accessible from the top, has a real glass window to protect the camera lens from the environments, an adjustable arm that allows for easy mounting and aiming, and even some solar cells on the top to power a small LED (we've tried to come up with a use for them, but they are too weak for most tasks).
- To reduce the buildup of heat, we have added an aluminium heat sink to the Pi processor, and installed a small fan in the case. We will see whether running the fan within the case will provide enough cooling, or whether we will need to add a hole to actively blow hot air out.
- The easiest improvement: Swap all incompatible SD cards with SanDisk cards.
- To improve the image quality, we've exchanged the generic Pi zero camera module with 160° zoom lens cameras from Pimoroni. These have an easily adjustable focus, and the glass slide of the camera case will give some additional protection.
Once these corrections were done, we got a little nuts, and started adding more functions to the camera. These things obviously increase the power consumption of the unit, but the power banks should be able to deal with this.
Camera assembly and programming
- The first thing we added was a small environmental sensor. The camera is now able to measure temperature, humidity and barometric pressure, and write the data in the file names of the photos.
- The next thing added was a tiny LCD screen. Currently, this is able to display the measured environmental variables, but ultimately we would like to also display the photos or videos taken to facilitate aiming with the camera.
- We are also planning to add a real-time clock to the system, so the actual time is stamped in the file names.
The assembly of the second camera version is a bit more tricky, but still doable by anyone who managed to assemble the first version:
- Gather all the parts for the hardware assembly.
Pretty much all the parts needed for the assembly
- Opening the camera case shows a battery holder and a cable from the solar cells leading to the holder and to a small led in the front.
The intestines of the dummy cctv camera, featuring a battery holder and cables from the solar cells to power a tiny led in the front and fool all those criminals
- Unplug the cable, unscrew the battery holder, and remove both the holder and the black front cover.
- Also remove the small black fake lens insert and led in the front panel and the fake cable in the rear. Sadly, we have not found any good use for the cool but weak solar panel yet...
The camera with all the unnecessary parts gone
- Recycle the bottom of the fancy plastic box the Pi camera came in: Make four tiny holes in one side and screw both the screen and the fan in place. (One could alternatively drill a hole somewhere in the bottom of the camera case and attach the fan there to get more cooling power at the cost of water-resistance.)
Screen and fan mounted to the bottom of the silly plastic box from the Pi camera. Yes, we recycle here.
- Fit the plastic box in the camera and screw it to the rear pin of the battery holder.
The plastic box screwed down to the camera body.
- Next, add a small piece of velcro to both the box and the bottom of the Pi, attach the camera, stick the heat sink on the processor, and put everything on top of the box inside.
This time we are using velcro instead of tape to be able to move the Pi around a bit, giving access to all the USB and HDMI ports.
- Fit the camera lens through the hole in the front panel, and attach it with tape as in the instructions for camera version 1.
Front of the camera: The taped real Pi lens surrounded by many fake led's
- Now some wiring: Attach the red cable of the fan to the first outer 5V pin, and the black cable to the ground pin next to pin 4. A map of the pins can be found here.
- If needed, solder the header pins to the environmental data sensor, or use solderless header pins instead.
- Close the camera and turn it around. Put six wires through the rear hole where the fake cable was attached before, and connect them to the sensor. (Alternatively, one could also install the sensor inside the case and seal the hole in the back. This would make the system more waterproof, but the measurements less accurate).
Environmental sensor sticking out of the camera rear. Take notes of the cable colouring!
- Now a tricky step: The other end of the cables have to be connected to the correct Pi gpio pins. From left to right on the image above: White: the 3.3V pin next to pin 22, grey: grounded pin next to pin 11, brown: pin 11, blue: pin 9, green: pin 10, yellow: pin 5. If unsure: there is a very good documentation available for this sensor.
This image shows the correct wiring of the sensor to the Pi. Refer to the image above this one for the colour code.
- Last assembly step: hook up the display. Connect the four cables to the display pins, and then to the correct Pi gpio pins. Orange: pin 2, red: pin 3, brown: 3.3V pin next to pin 3, black: ground pin next to pin 14.
This image shows the correct wiring of the display to the Pi.
The complete unit from above.
- Connect the charged power bank to the Pi, close the camera case, and have fun!
Getting a bit tight in here with the 5000 mAh power bank.
- Now to the software: Boot the Pi and install the Adafruit_Sensor and Adafruit_BME280 libraries for the environmental sensor (we will add more detailed instructions for this here soon).
- Follow the software programming steps of camera version 1 above, but download and install the script for camera version 2 instead (a new version will be uploaded soon).