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?

Octopus
  • 797
  • 1
  • 9
  • 19
  • 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 Jan 15 '16 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 Mar 10 '21 at 04:56

5 Answers5

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.

JoSSte
  • 147
  • 10
Fred
  • 4,552
  • 18
  • 29
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

Octopus
  • 797
  • 1
  • 9
  • 19
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

Pankaj
  • 171
  • 1
  • 2
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
mpromonet
  • 1,124
  • 18
  • 37
Diego
  • 1,259
  • 10
  • 14
  • +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 Jun 15 '17 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.

    – Diomidis Spinellis Dec 26 '17 at 07:55
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
Dmitry Grigoryev
  • 27,928
  • 6
  • 53
  • 144