0

Running NOOBS

Raspberry pi 3b

Standard Camera from Pihut

So, my grand idea is to have a camera taking still images (raspistill) that I can then stitch together later, to make a short movie seen out through the windscreen of our motorhome.

So I have managed to make a script that works perfect for this, if I run the script after booting and logging in to my PI.

Now, obviously I do not want to login to my pi to start the script every time, I want it to work as I power on my pi. Here starts my problems. After searching high and low, I have found that the way to do that in NOOBS (at least with still logging in) is to call the script in .bashrc - So I did. I can run every script fine, but if I want to use the camera I now get this error.

mmal: mmal_vc_component_enable: failed to enable component: ENOSPC
mmal: camera component couldn't be enabled
mmal: main: Failed to create camera component
mmal: Failed to run camera app. Please check for firmware updates

And if I try to close the script and restart it (or others with camera code) I keep getting this error until I reboot with out the script being run on boot.

I have spend a lot of time trying to figure out what I do wrong. I have even tried to make a separate script that I run from .bashrc that will then sleep 100 seconds (just to be extra extra sure) and then opens my camera script, still same problem.

What am I doing wrong? Is it just NOOBS that are unable to do what I ask or am I doing something completely wrong? My real goal is to have a script start when I power on the Pi, without logging in, that I can start taking pictures with a push of a button.

Here is the code of the camera script I use: (yes I am using raspistill instead of timelaps)

import RPi.GPIO as GPIO
import time
import os
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(24, GPIO.OUT)

x = 0

def runner(x):
        print("***** RUNNER: " + str(x))
        if x < 5:
                StorageLeft = os.popen("df -Ph /dev/sda1 | grep -Po '\d+(?=%)'").read()
                print("Storage left: " + str(100-int(StorageLeft)) + "%")


                for p in range(0,int(StorageLeft)):
                        GPIO.output(24, True)
                        time.sleep(0.5)
                        GPIO.output(24, False)
                        time.sleep(0.5)

        if x > 4:
                t = 0
                while True:
                        print("Picture: " + str(t))
                        os.system("raspistill -w 640 -h 480 -o /media/pi/TEST/" + str(t) + ".jpg")
                        GPIO.output(24, True)
                        t += 1
                        time.sleep(1)
                        input_state = GPIO.input(18)
                        if input_state==False:
                                print("Break")
                                break
                        GPIO.output(24, False)
                        time.sleep(4)
                        StorageLeft = os.popen("df -Ph /dev/sda1 | grep -Po '\d+(?=%)'").read()
                        print("Storage left: " + str(100-int(StorageLeft)) + "%")
                        if 100-int(StorageLeft) < 99:
                                print("***** Card full, script ended")
                                break

while True:
    input_state = GPIO.input(18)
    if input_state==False:
        x += 1
        print(x)
        time.sleep(1)
    else:
        if x > 0:
                runner(x)
                x = 0
  • What version of OS are you running? – MatsK Feb 7 '18 at 15:41
2

You want to run a script/program at startup without login. This is usually done with a service and managed by systemd. This isn't really a raspi specific question but here is a very short snipped to give an idea. Create a new service for camera.service:

pi ~$ sudo systemctl edit --force --full camera.service

Insert this statements with your settings, save them and quit the editor:

[Unit]
Description=Camera script

[Service]
ExecStart=/path/to/camera.py
StandardOutput=null

[Install]
WantedBy=multi-user.target

Then enable this service:

pi ~$ sudo systemctl enable camera.service
pi ~$ sudo systemctl start camera.service

Of course this will not fit your specifc needs. You may need to start other services and start your script before or after them. This can be defined in section [Unit]. There are many examples out there on google. Please have a look at them. You may look here for starting after "network-up".

  • Okay, thank you. I will have a look into it tonight . – Hudlommen2 Feb 7 '18 at 21:19
0

.bashrc is NOT intended to run scripts.

It is run each time a shell is started.
~/.bashrc: executed by bash(1) for non-login shells.

There are may ways of running scripts, but it unclear what you are trying to do. The listing does not look like a bash script but looks like Python

See https://raspberrypi.stackexchange.com/a/47537/8697 for an example.

  • You are right, it is a .py file, i could just only find the .bash method. But as you say, its mixing the wrong things. – Hudlommen2 Feb 7 '18 at 21:17
0

I found that it all worked with using @reboot in crontab. Much easier way to get around my problem.

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.