Introduction: A Raspberry Pi Multispectral Camera
A multispectral camera can be a handy tool to detect stress in plants, or recognise different species in lieu of the differences in the reflectance signatures of plants in general. If combined with a drone, the camera can provide the data for quick NDVIs (Normalised Difference Vegetation Index), create mosaics of farms, forests or woodlands, understand nitrogen consumption, create yield maps and so on. But multispectral cameras can be costly, and their price is directly proportional to the sort of technology they implement. A traditional approach to spectrometry is to use several cameras with long or short bandpass filters that allow the required spectrum to pass trough while blocking the others. There are two challenges to that approach; first, you need to trigger the cameras at the same time, or as close as possible; and second, you need to register (merge images layer after layer) the images so they can form one final composite with the desire bands in it. This means that a big deal of post-processing needs to be done, consuming time and resources (using expensive software such as arcmap, but not necessarily). Other approaches have dealt with this in different ways; recent technology developments at processor level have allowed the creation of scan CMOS sensors with band filters integrated in the sensor's layout. Another approach is to use a beam splitter (prism) that would direct the different beams of light to a different sensor. All these technologies are extremely expensive and therefore out of the reach for explorers and makers. The Raspberry pi compute module and its development board offer a cheap answer to few of these questions (not all though).
Step 1: Enabling the Cameras
Make sure you follow the steps for setting up the cameras in the CM as indicated in the following tutorials:
https://www.raspberrypi.org/documentation/hardware...
Trigger both cameras at the same time using:
sudo raspistill -cs 0 -o test1.jpg & raspistill -cs 1 -o test2.jpg
Use the following topic if for any reason it didn't work:
https://www.raspberrypi.org/forums/viewtopic.php?f...
Further instructions in case you are starting from scratch with the CM here:
Step 2: Wireless Serial Communication
Buy a set of telemetry radios like these:
http://hobbyking.co.uk/hobbyking/store/__55559__HK...
These radios have four wires: Ground (black), TX, RX, VCC (red). Peal off one extreme of the cables and use female connectors that fit the GPIO pins. Connect the black connector to ground, red to 5V, TX to pin 15, and RX to pin 14 of the J5 GPIO header of the compute module development board.
Make sure you set the baud rate to 57600, and that your host computer has recognised and added the radio as COM (in Windows use the device manager for that). If using Putty, chose serial, the COM port (3, 4 or whatever it is in your computer), and set the baud rate to 57600. Switch your CM on and after it finishes loading, click enter in your computer if you don't see any text coming through the connection. If you notice any garbled text, go and check /boot/cmdline.txt. The baud rate should be 57600. if any further problems arise, please check the following tutorial:
Step 3: The Cameras...
You can actually use the cameras in their original configuration, but if not, you will need to modify them in order to accommodate the M12 lenses. Bear in mind that the raspberry pi cameras V1 and V2 are slightly different, so, old M12 holders won't work on new cameras. Also, there was some problems when triggering the new cameras in parallel, if you experience any of this problems please check this topic in the raspberry pi forum:
https://www.raspberrypi.org/forums/viewtopic.php?t...
In any case, a sudo rpi-update should fix the issue.
The M12 lens holder can be 'grind' with a Dremel in order to fit the connector of the CMOS sensor with the camera board. Unscrew the original lens, and place the new lens over the M12 holder. For better results you can actually get rid altogether of the original lens adapter, but it might not be worth the work in light of the risk that entails to damage the sensor. I destroyed at least six camera boards before managing to get rid of the plastic holder that sits above the CMOS sensor.
Step 4: Wifi Connection and Extra Storage
The CM development board has just one USB port; as a result of that you have to use it very wisely, e.g. wifi connection. If you want to go around that, you will have to use your soldering iron skills and attach a dual USB connector under the development board, where the USB is soldered. If you are using the same I have
https://www.amazon.co.uk/gp/product/B00B4GGW5Q/ref...
https://www.amazon.co.uk/gp/product/B005HKIDF2/ref...
Just follow the cable order in the picture.
Once done, attach your wifi module to the dual port, power on the CM and see if the wifi module is working correctly.
It is easier to attach an SD card than a USB drive, so buy something like this:
https://www.amazon.co.uk/gp/product/B00KX4TORI/ref...
To mount the new external storage, follow this tutorial carefully:
http://www.htpcguides.com/properly-mount-usb-stora...
Now you have 2 USB ports, extra storage and wifi connection.
Step 5: Print the Case
Use ABS
Step 6: Put the Pieces Together
Before you assemble the camera, connect a monitor and keyboard to the CM, and focus the lenses. The best way to do that is to use the following command:
raspistill -cs 0 -t 0 -k -o my_pics%02d.jpg
That runs the camera forever, so observing your screen, tight the lens until is focused. Remember to do that with the other camera by changing the -cs command from 0 to 1.
Once your lenses are focused put a small drop of glue between the lens and the M12 lens holder to prevent any movement of the lens. Do the same while attaching the lenses to the case. Make sure that both lenses are aligned as much as possible.
Use a drill to open a hole on the side of the case and put through the radio antenna. Place the radio securely by using double face tape and connect it to the GPIO.
Place the CM development board inside the case and secure it with 4 10mm metal hexagonal extenders. Secure the camera connector adapters so they don't bounce freely inside.
Step 7: Configure Dropbox-Uploader, Install the Camera Script.
Install dropbox_uploader following the instructions provided here
https://github.com/andreafabrizi/Dropbox-Uploader
Use a script similar to that in the picture.
Step 8: Final Product
The final camera can be placed under a medium size (650 mm ⌀) drone or even smaller. It all depends on the configuration. The camera is no more than 350-400 grams.
To power the camera, you will have to provide a separate battery, or connect the camera to the power board of your drone. Be careful not to exceed the power requirements of the CM board. You can use the following items to power your camera:
https://www.adafruit.com/products/353
https://www.amazon.co.uk/USB-Solar-Lithium-Polymer...
You can also build the support, and the anti-vibration dampers according to your drone specifications.
Once you have taken the first pictures, use a GIS program such as Qgis or Arcgis Map to register your images. You can also use matlab.
Happy flight!
60 Comments
Question 5 weeks ago
Hey. Following the instructions you provided, I was able to make this multispectral camera using Raspberry Pi. Now I want to use this multispectral camera for my agricultural drone. Can you help me which cameras to use for capturing separate bandpass i-e red,blue,green, NIR,RGB and Red-edge?Plus I wanted to ask how to integrate the six mentioned cameras to raspberry pi module?
Answer 4 weeks ago
Hi.
This is a very old tutorial and a lot of things have happened in the meantime. Last time I was tinkering with it, I was using this: https://www.arducam.com/product/12mp4-quadrascopic...
I am not sure if Raspberry Pi is offering monochrome cameras now, their cameras weren't real monochrome, they simply had a filter. If you really want to separate the bands you need a monochrome sensor and a long pass filter for the specific wavelength you want to isolate. I used these in the past: https://midopt.com/filters/bandpass/
Good luck!
Question 3 years ago
Hi, I'm searching on ways to make a wild fire detector, to put in a drone. Do you think this mechanism will work?
Answer 1 year ago
Could you imagine using a 4 pixel differential PIR detector from a common motion detector? Perhaps you can let this rotate to get a angular resolution and use giering angle of drone for another short-term axis, plus a servo for calibrating the horizon.
Try getting hold of a beautiful Stirling model for cooling the sensor and e.g. one lens. Perhaps you want to collect IR light by using heated gas as lens. Common trick for high power CO2 lasers.
I could try to look up several other details from a Stirling cooled heat camera we have in a lab in university.
Reply 3 years ago
Hi,
How do you want to detect fires? thermal footprint, machine vision? That sounds complicated. I think you are better off just buying one of the flir lepton boards:
https://groupgets.com/campaigns/588-purethermal-mini-pro-with-flir-lepton-3-0
Reply 3 years ago
Hi, flir lepton seems to have a worse definition than a new version of Pi camera, why do you think it will be better to use the flir lepton board?
Reply 3 years ago
I was planning on using a Pi camera to detect fire from IR, but thanks i will take a look on this flir lepton board.
Question 1 year ago
Thanks for the explanation. What code did you use to get the noir camera to see the nitrogen? I am using a noir camera and webcam. Got them to turn on the same time. Raspberry pi 3b. Thanks again
Question 2 years ago
Is there a full list of materaisl needed some where. Looking to build one of these and then us an AI to help show areas where tree could be planted to allow our tree planting robot to know where to plant for the tree best chances of growth.
Question 2 years ago
hello, sorry if I disturb you, I read the comments and I got confused even more, I didn't quite understand the part of the filters for the cameras. The cameras can be used as purchased or you have to apply filters for the spectrum. If so, which ones? I leave you my email: vitomurgolo97@gmail.com
Answer 2 years ago
This post is old, but it answers your main question.
https://goldentreefrogblog.wordpress.com/2018/12/28/my-low-cost-multispectral-camera-spectral-pi/
Question 4 years ago
I was wondering if you added four cameras for a better multispectrum.. OR is there any advantage adding addtional cameras. I would like to build this for my drone for agriculture instead of paying for some overpriced camera that does the samething as this project. Any advice would be appricatated.
Thanks
Doug
Reply 4 years ago
Hi texacoon,
Adding extra cameras would be advantageous if you want to have more control over specific wavelengths. For example, using 4 cameras would enable you to filter the red, green, blue and NIR light down to a specific wavelength and bandwidth. The question is, do you really need that level of control over the spectrum? Maybe not. Visible light, that is, red, green and blue, might not need that level of control if you simply want to produce NDVIs to detect general stress in plants. In that case, all you need to do is to add an extra band such as NIR (840nm with a bandwidth of 20-40nm) to detect stress. That means that you can have just 2 cameras, one getting RGB, the other one getting the NIR, for you to produce NDVIs.
If you give me a little bit more of information I might be able to be more specific in the requirements you need. What drone do you use? Are you a farmer yourself? If so, what crops do you grow? What is it that you want to detect? Water or nutrient deficiencies? Maybe all you want to see is if your crop is growing uniformly across your field?
When you say overpriced camera, what sort of product have you checked/used? Most available products such as the Micasense Rededge/Sequoia cameras are not overpriced, they are simply targeting a specific niche with specific requirements.
Having said all that, I'm about to finish a second iteration of the multispectral camera so, it would be very interesting for me to add your feedback on the new specifications. The final product would be considerable cheaper than the products available on the market now.
Reply 3 years ago
Hi MaykeS1, I'm in a simililar situation to texacoon where i dont have £5000 to drop on rededge or Sequoia camera. Did you come up with the next iteration of this project by any chance??????
Reply 3 years ago
I am!
Getting nearly there. what are your requirements? My first carrier board already arrived, but I have to solve a small issue so I will have to wait for V2 to field testing.
Bear with me :)
3 years ago
Howdy, one question.
What diameter filter should I get/what is the diameter of the 16mm M12 lense? Also, what raspberry pi did you use that has two camera ports?
Cheers!
Question 3 years ago
Hi MaykeS1, very nice article. I was wondering if you had more information on the specifics of the cameras and filters you used?
Answer 3 years ago
Hi Jake,
Thank you for your comment. If you have a quick look at the comments' thread, you'll find the answers to your questions about cameras and filters.
Kind regards,
Mayke
Question 3 years ago
Hi, I love the article. One question though why did you use 2 picameras ?
Answer 3 years ago
Hello @204manal,
I use 2 cameras because one captures the red, green and blue channels, while the other camera captures the nir spectrum using a special filter. Does that make sense?
Regards,
Mayke