Feature Request: Camera Manual Focus and Exposure

As the borescope camera was not in stock in the FarmBot shop I ordered a similar USB camera with the same dimensions. It worked in principle bit the pictures had a very low resolution, darkened to the corers and were very blurry.

So I ordered a better but bigger camera (5MP) and designed a new camera mount for this bigger HD-camera.
Here is the Link to my onshape design: https://cad.onshape.com/documents/0c7a2ad4d38ff17d7fad60fa/w/a4eeb42e08bde05944e14301/e/1dc0903a1bc512e4f9d094fc
Here is the link to the camera: https://www.amazon.de/gp/product/B07T6TS55Q/ref=ppx_yo_dt_b_asin_title_o04_s00?ie=UTF8&psc=1
This new camera takes much better pictures which do not get darker at the corners. That alone makes it more suitable for scanning the whole beet. Here is an example:

However the camera greatly struggles with daylight. During the whole day it always takes very blurry photos which are overexposed. I believe this is because it is designed to inspect small dark spaces and photos during the day are out of the range of expectations for the automatic mode. Here is an exaple of a photo during daylight:

My Question: Is there any way to manually set camera settings?

USB borescope cameras connect like normal webcams to Linux. You can access the via v4l2 which includes tools to manually set the settings:
The command v4l2-ctl --list-devices will list all the attached camera devices. At a FarmBot there should be only one: /dev/video0. The command v4l2-ctl -d /dev/video0 --list-ctrls will print out which settings can be set for the attached camera model and prints out most of the set values. Each can also be read with --get-ctrl (Example: v4l2-ctl --get-ctrl=white_balance_temperature).
The best part is that all the settings can also be written with --set-ctrl. Here is an example:
v4l2-ctl -d /dev/video0 --set-ctrl=exposure_absolute=166

The FarmBot could improve the quality of beet scans by setting the exposure after the first image to manual mode and resetting it after the last image. In my case manually setting focus, exposure, gain and white balance would allow me to take much better photos during the day. With therse better photos the weed detection would also work more reliably.

If there was an easy way to connect to the Linux on the Raspberry Pi via SSH I would have tested this myself. As I understand that’s not possible with FBOS. So an alternative solution would be to integrate some manual controls in the web interface which run the v4l2-ctl commands on the Pi. I hope this is not hard to implement.


Not a direct answer to your question about camera settings.

I take photos early morning or late afternoon, when there is only indirect sunlight on my FarmBot. This has a couple of benefits:

  • Photos are not overexposed.
  • The wooden raised garden bed frame does not reflect too much yellow / orange / brown into the photo, which otherwise shifts the white balance (this messes with your plant detection calibration). When I took photos in direct sunlight, photos that included the garden bed frame were white balanced differently to photos of the centre of the garden bed.
  • Photos are not sensitive to clouds passing in front of the sunlight, which also messes with your plant detection calibration.
  • Photos do not include the shadow of the gantry.

Try taking your photos in “bright twilight” so you get the most evenly lit garden without any cast shadows. Calibrate plant detection using these photos and lighting.

Then schedule a sequence to photograph your garden during these times every day (or however often you need).

This looks great! Thanks for sharing your camera mount design. We have been considering replacing the current design of the camera in future versions, but we often find that alternatives are not quite right for our use case. The camera shown in your link is new to me and I have passed it along to the rest of the team for further investigation.

Is there any way to manually set camera settings?

Currently, there is not, but you bring up a valid use case. This could be very useful for advanced developers.

If there was an easy way to connect to the Linux on the Raspberry Pi via SSH I would have tested this myself. As I understand that’s not possible with FBOS. So an alternative solution would be to integrate some manual controls in the web interface which run the v4l2-ctl commands on the Pi. I hope this is not hard to implement.

It is possible to SSH into a FarmBot but there are a few things to keep in mind:

  1. You must enter an SSH key at configuration time. If you did not add one, you must re-flash your SD card and start over.
  2. When you SSH into a device, you will not get a standard shell. Instead, the system shell is iex, an interactive Elixir programming environment (similar to Ruby’s pry or the Javascript debug console).
  3. When you enter SSH, you can use Toolshed which will enable the Toolshed utility. Toolshed exposes a cmd("echo 'hi'") utility.
  4. It is still possible run system commands from iex. I have included an example below.
  5. SSH exists for FarmBot employees and Elixir programmers modifying FBOS. Many things are not expected to behave like a normal Linux SSH session. I mention this because we occasionally get feature/update requests for SSH and our intent is not to provide an SSH environment for advanced users. It is there to help employees debug system problems.
$ ssh

iex(farmbot@farmbot-000.local)1> use Toolshed
Toolshed imported. Run h(Toolshed) for more info.
iex(farmbot@farmbot-000.local)2> cmd("v4l2-ctl --list-devices")
USB2.0 PC CAMERA: USB2.0 PC CAM (usb-3f980000.usb-1.2):

iex(farmbot@farmbot-000.local)3> cmd("v4l2-ctl -d /dev/video0 --list-ctrls")
            brightness 0x00980900 (int)    : min=0 max=255 step=1 default=128 value=128
              contrast 0x00980901 (int)    : min=0 max=255 step=1 default=148 value=148
            saturation 0x00980902 (int)    : min=0 max=255 step=1 default=90 value=90
                  hue 0x00980903 (int)    : min=-127 max=127 step=1 default=0 value=0
                gamma 0x00980910 (int)    : min=1 max=8 step=1 default=4 value=4
  power_line_frequency 0x00980918 (menu)   : min=0 max=2 default=1 value=2
            sharpness 0x0098091b (int)    : min=0 max=15 step=1 default=3 value=3
backlight_compensation 0x0098091c (int)    : min=1 max=5 step=1 default=1 value=1

I will discuss your idea with the team today. Thanks for the feedback and please do continue sharing your mods and ideas!


Thanks for post @pinae. I’m trying to troubleshoot why my camera only takes black photos, so I learned some useful things. I had been wondering whether ssh into the pi would help. (It is not a camera issue or connection issue; it could be due to low voltage on the Farmduino and on the GPIO pins - I haven’t ruled this out.)

From what you and @RickCarlino say, it sounds like I’m not going to learn much from what I’d be able to see via iex.

@zmek Can you review this video regarding the camera connection, also check to make sure that the connector ring is tight. Double check and make sure that there isn’t any evidence of corrosion in the connector pins.

Also please review the camera troubleshooting page on our website:

Hi @Marc thanks for getting back to me on this. The connection is not the problem. I can connect the camera to a different computer or rasbperry pi via this connector (ie by disconnecting the cable inside the box that goes into the Farmbot pi and connecting it to another pi) and the camera works fine. I have had this issue with black photos from the beginning of setting up Farmbot, so corrosion is not an issue. I have tested the power across the GPIO pins and this is low.

I sent you an email about this GPIO voltage issue on 2 May, and you kindly sent me another camera but that has not solved the issue. Is there anything else I can try?