RPi 3 - Script for GPIO on startup

  • Hi to all. My knowledge of Linux, and writing code, is limited......so please bear with me

    I have built a simple 5v cooling fan for my Rasp Pi3 (yes, I know it doesn't really need one, but humour me!). It is to be switched via a NPN transistor to simply run at one speed from boot up. To do this, I need GPIO 24 to become active/high at boot up. This is for the base input of the transistor, the fan is powered from the 5v rail.

    I'm trying to devise a script/code to add to LE, in order to set GPIO 24 pin 'High' or '1' on boot up.
    I can acheive the basic function of getting the pin to go from Low/off to High/on by SSH'ing into LE and issuing the following commands at the terminal:

    Code
    echo "24" > /sys/class/gpio/export
    echo "out" > /sys/class/gpio/gpio24/direction
    echo "1" > /sys/class/gpio/gpio24/value

    After a bit of looking about, I tried creating an 'autostart.sh' script (as per the wiki) and then adding the above code to it. The script is located at /storage/.config/autostart.sh

    It fails to work at boot up (the file has maximum permissions '777', so should be executable), and if I try to run 'autostart.sh' at the terminal, it spits out several errors which roughly say:

    Can't create
    /sys/class/gpio/export
    /sys/class/gpio/gpio24/direction
    /sys/class/gpio/gpio24/value

    Sorry, I haven't got the exact output to hand at the moment, but that is very close.

    So, can anyone tell me what I'm missing and doing wrong here, please?

    Cheers.