9

I would like to enable the raspberry pi camera without using raspi-config, as I need to do this in an automated bash script.

Anyone know how?

ended up pulling this out of raspi-config

#!/bin/bash

set_config_var() {
  lua - "$1" "$2" "$3" <<EOF > "$3.bak"
local key=assert(arg[1])
local value=assert(arg[2])
local fn=assert(arg[3])
local file=assert(io.open(fn))
local made_change=false
for line in file:lines() do
  if line:match("^#?%s*"..key.."=.*$") then
    line=key.."="..value
    made_change=true
  end
  print(line)
end

if not made_change then
  print(key.."="..value)
end
EOF
mv "$3.bak" "$3"
}




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

set_config_var start_x 1 /boot/config.txt
set_config_var gpu_mem 128 /boot/config.txt
sed /boot/config.txt -i -e "s/^startx/#startx/"
sed /boot/config.txt -i -e "s/^fixup_file/#fixup_file/"

3 Answers 3

3

Raspi-Config is pointing at /boot/config.txt where the string start_x=# is located in the bottom of the document. the "#" represent either a "0" or a "1". 0 = Camera disabled and 1 = Camera enabled.

I solved this by making a script as follows:

#!/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

Don't forget to chmod the script so that you can execute it, and after that run script as root.

1
  • Why would starting X have anything to do with the camera?
    – nmichaels
    Commented Jan 17, 2019 at 20:23
2

Generally you can use lsmod command for listing kernel modules names and after that you can install module with insmod [module_name]. rmmod [module_name] command is for removing modules.

2
  • 4
    I think modprobe would be the command of choice. It resolves dependencies, if there are any.
    – Arne
    Commented Oct 28, 2013 at 12:35
  • I agree with you @Arne .
    – cagdas
    Commented Oct 28, 2013 at 14:47
2

Based on How could one automate the raspbian raspi-config setup? this should work:

sudo raspi-config nonint do_camera 0

(Also, it works for me.)

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.