RGB LED module script

I am testing a 3 color LED module KY-016 commomly found in Arduino Sensor packages.

I would like to see anyones scripts for GPIO LED's.

I am using 3 GPIO Pins on RockPro64 for 6 colors. Header Pin 11,13,15 and Pin 9 for ground.

Hear is my script rgb.sh:
Code:
#!/bin/sh
####### FreeBSD RGB LED Display Script ######
#
#### Assign board pin variables ####
redPinbus="/dev/gpioc1"
redPin="22"
greenPinbus="/dev/gpioc1"
greenPin="18"
bluePinbus="/dev/gpioc1"
bluePin="1"
#
#### Initialize the pins as an outputs ####
gpioctl -f ${redPinbus} -c ${redPin} OUT
gpioctl -f ${greenPinbus} -c ${greenPin} OUT
gpioctl -f ${bluePinbus} -c ${bluePin} OUT
gpioctl -f ${redPinbus} -p ${redPin} 0
gpioctl -f ${greenPinbus} -p ${greenPin} 0
gpioctl -f ${bluePinbus} -p ${bluePin} 0
#
#### The 6 color Loop ####
#### Red, Green, Blue, Green Blue, Green Red, Blue Red ####
while true
do
gpioctl -f ${redPinbus} -p ${redPin} 1
sleep 2
gpioctl -f ${redPinbus} -p ${redPin} 0
gpioctl -f ${greenPinbus} -p ${greenPin} 1
sleep 2
gpioctl -f ${greenPinbus} -p ${greenPin} 0
gpioctl -f ${bluePinbus} -p ${bluePin} 1
sleep 2
gpioctl -f ${greenPinbus} -p ${greenPin} 1
sleep 2
gpioctl -f ${bluePinbus} -p ${bluePin} 0
gpioctl -f ${redPinbus} -p ${redPin} 1
sleep 2
gpioctl -f ${greenPinbus} -p ${greenPin} 0
gpioctl -f ${bluePinbus} -p ${bluePin} 1
sleep 2
gpioctl -f ${redPinbus} -p ${redPin} 0
gpioctl -f ${bluePinbus} -p ${bluePin} 0
sleep 2
done
 
I have this in my /etc/rc.local to signalize me when the board is ready for ssh
Code:
(gpioctl -f /dev/gpioc1 PC7 1 && sleep 1 && gpioctl -f /dev/gpioc1 PC7 0)

PWM works but I am using it for LCD backlight or CPU fan, not LEDs, eg /etc/rc.local:
Code:
pwm -f /dev/pwm/pwmc1.0 -E -p 50000 -d 3%
 
This is why I wanted to see others work.
So JohnnySorocil how did you end up with pin names like PC7 ? Is this a label you applied?

How about pin groups? Do we have such a thing. I want to operate on a group of pins.

What about PULSATE ? I see in source some GPIO pins have that capability. This is per board capability?

(gpioctl -f /dev/gpioc1 -t PC7 && sleep 1)
 
GPIO1_C7 is the name in schematic for that LED.

PC7 came from this:
Code:
gpioctl -f /dev/gpioc1 -l | grep PC7
pin 23: 0       PC7<OUT>

I did change my dtb, but not sure if it is necessary for gpioctl.
Code:
leds {
    compatible = "gpio-leds";
    pinctrl-names = "default";
    pinctrl-0 = <&leds_pins>;

    green {
        u-boot,dm-pre-reloc;
        label = "green";
        gpios = <&gpio1 RK_PC7 GPIO_ACTIVE_HIGH>;
        default-state = "off";
    };
};

kernel module gpioled(4) was not loaded. After loading this became available:
Code:
echo 1 > /dev/led/green
echo 0 > /dev/led/green

Pulsating should be available via led(4):
Code:
echo f9 > /dev/led/green
 
Thank You. That is most useful for setting a pin for LED system duty.

My reading says there are no pin groups. On the ToDo list for GPIO.

I had no idea you could use the root name for the pin like that. That is very useful information.

But when I look at the output on hummingboard appears longer.
# gpioctl -f /dev/gpioc0 -l
pin 00: 0 GPIO1_IO00<OUT>
pin 01: 1 GPIO1_IO01<IN>[/CODE]

So in this case the whole name is needed. GPIO1_IO01 I assume.

The gpioctl program does have a '-n' name feature for pins.
I wonder where it stores its values???

Can I assign multiple pins the same name for a pseudo pin group.
 
Can I assign multiple pins the same name for a pseudo pin group.
That didn't work well. No go.

So when you change the name with -n it shows up in the list.
# gpioctl -f /dev/gpioc0 -l
pin 00: 0 GPIO1_IO00<OUT>
pin 01: 0 LED0<OUT>
pin 02: 1 GPIO1_IO02<IN>

Where the gpio names exist on the OS is unknown. Not a sysctl or kenv.

I do like how it works for the blink script.
./gpio-blink.sh 0 LED0 &
 
Well i dug into the gpioctl source to see what it was doing with -n name pin option.

Code:
int
str2cap(const char *str)
{
    struct flag_desc * pdesc = gpio_flags;
    while (pdesc->name) {
        if (strcasecmp(str, pdesc->name) == 0)
            return pdesc->flag;
        pdesc++;
    }

    return (-1);
}

I have found the pin name setting is not saved and a reboot will clear the name.
So this name setting is just saved in memory?
 
Back
Top