17

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?

  • 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
11

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.

11

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

6

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
  • +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 7:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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