26

I am trying to use the raspi camera on a minimalized version of wheezy. The command raspi-config is not available. I have been able to do everything without it so far by editting /boot/config.txt or installing missing software with apt-get.

Unfortunately, everywhere I look, all tutorials on the camera (including the official RaspiCam-Documentation.pdf) say to first enable it with raspi-config. So, what does raspi-config actually do to the Pi that I can reproduce manually?

2
  • 2
    FYI Using start_x=1 in config.txt stops my xbian from booting and causes sd card corruption meaning a whole new image has to be flashed to the sd card.
    – gazhay
    Commented Jan 15, 2016 at 16:42
  • Adding start_x=1 and gpu_mem=128 to the /boot/config.txt file on a Ubuntu 20.10 arm64 for Raspberry Pi 4 leads to an unfixable boot failure where it hangs on the splash screen indefinitely.
    – kreddkrikk
    Commented Mar 10, 2021 at 4:56

5 Answers 5

18

OK. raspi-config is actually a bit of bash, so it's quite easy to see what it does:

# $1 is 0 to disable camera, 1 to enable it
set_camera() {
  # Stop if /boot is not a mountpoint
  if ! mountpoint -q /boot; then
    return 1
  fi

  [ -e /boot/config.txt ] || touch /boot/config.txt

  if [ "$1" -eq 0 ]; then # disable camera
    set_config_var start_x 0 /boot/config.txt
    sed /boot/config.txt -i -e "s/^startx/#startx/"
    sed /boot/config.txt -i -e "s/^start_file/#start_file/"
    sed /boot/config.txt -i -e "s/^fixup_file/#fixup_file/"
  else # enable camera
    set_config_var start_x 1 /boot/config.txt
    CUR_GPU_MEM=$(get_config_var gpu_mem /boot/config.txt)
    if [ -z "$CUR_GPU_MEM" ] || [ "$CUR_GPU_MEM" -lt 128 ]; then
      set_config_var gpu_mem 128 /boot/config.txt
    fi
    sed /boot/config.txt -i -e "s/^startx/#startx/"
    sed /boot/config.txt -i -e "s/^fixup_file/#fixup_file/"
  fi
}

Apparently there's an entry in /boot/config.txt called start_x that needs to be set to 1 to enable the camera, There also needs to be at least 128 MB of memory for the gpu (gpu_mem). Double check seems to confirm it.

1
17

edit your /boot/config.txt file and make sure the following lines look like this:

start_x=1             # essential
gpu_mem=128           # at least, or maybe more if you wish
disable_camera_led=1  # optional, if you don't want the led to glow

reboot

7

What raspi-config does is changing the /boot/config.txt. There is a string inside that file which says start_x=0 when camera is disabled. By changing that to start_x=1 will enable the camera. You will have to reboot after you edited the file.

I made a script that searches the /boot/config.txt for the string "start_x=0" and if it finds it changes it to "start_x=1". Use the following code, and don't forget to chmod +x and run with sudo.

#!/bin/bash
grep "start_x=1" /boot/config.txt
if grep "start_x=1" /boot/config.txt
then
        exit
else
        sed -i "s/start_x=0/start_x=1/g" /boot/config.txt
        reboot
fi
exit
2
  • +1 What is the first grep for? And Is it possible that before the first startup there is no such line as start_x=* ?
    – Gabber
    Commented Jun 15, 2017 at 21:24
  • The first grep might be useful for debugging purposes. It is not required for the script's operation. In my Raspbian stretch config.txt file I cannot find a start_x line in config.txt, so this script will not work as it is. Commented Dec 26, 2017 at 7:55
7

raspi-config seems to support noninteractive mode: you can use nonint command to set the camera

# raspi-config nonint do_camera %d
# %d - Integer input - 0 is in general success / yes / selected, 1 is failed / no / not selected

sudo raspi-config nonint do_camera 0

For more details please check the full list of options: https://github.com/l10n-tw/rc_gui/blob/master/src/rc_gui.c#L50-L100

0

For the Raspberry Pi 4 with Ubuntu 20, to enable v4l2 for CSI run

sudo nano /boot/firmware/config.txt

and add these lines:

gpu_mem=512
disable_camera_led=1
start_file=start4x.elf
fixup_file=fixup4x.dat
1
  • Not sure why but this doesn’t work on Ubuntu 22.04.1 LTS.
    – sunknudsen
    Commented Feb 1, 2023 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.