We have upgraded the community system as part of the upgrade a password reset is required for all users before login in.

GPIO PWM



  • I'm building my own expansion board for Omega2+ so I'm testing my circuit which uses PWM to control some WS2812B RGB LEDs. On Omega2Pro I can test with omega2-ctrl command:

    omega2-ctrl gpiomux set uart2 pwm23

    then use ledchain:

    echo -en '\x00\x00\xff' > /dev/ledchain2 #make RGB turn blue

    Since I am using an Omega2+ with my custom PCB I'm using GPIO18 so the command would be

    omega2-ctrl gpiomux set pwm0 pwm

    Correct?

    Just want to check I am not missing something obvious before I need to look at my board.



  • I answered my own question, using this doc

    https://docs.onion.io/omega2-docs/generating-pwm-signals.html



  • @crispyoz On Omega2 with an OpenWrt 18.06 based firmware using
    ledchain0 (ie. /dev/ledchain0)
    PWM channel 0 (ie. pwm0 - GPIO18)
    number of LEDs 1
    LED type WS2812 or WS2812B

    rmmod /lib/modules/4.14.81/p44-ledchain.ko
    insmod p44-ledchain ledchain0=0,1,1

    omega2-ctrl gpiomux set pwm0 pwm

    After these commands you could use - for example - a WS2812 RGB LED at GPIO18:
    echo -en '\xff\x00\x00' > /dev/ledchain0 # red
    echo -en '\x00\xff\x00' > /dev/ledchain0 # green
    echo -en '\x00\x00\xff' > /dev/ledchain0 # blue
    echo -en '\x00\x00\x00' > /dev/ledchain0 # off

    # Omega2+ FW v0.3.2 b232
    
    # unload (deactivate) the default ledchain2 driver
    root@Omega-5BE1:/# rmmod /lib/modules/4.14.81/p44-ledchain.ko
    [14897.611820] ledchain: cleaned up
    
    # load (activate) the driver for ledchain0
    root@Omega-5BE1:/# insmod p44-ledchain ledchain0=0,1,1
    [14990.854231] ledchain: pwm_base=0xB0005000
    [14990.858538] ledchain: v2 - Device: /dev/ledchain0
    [14990.863311] ledchain: - PWM channel    : 0
    [14990.867512] ledchain: - PWM buffer size: 12
    [14990.871752] ledchain: - Number of LEDs : 1
    [14990.875916] ledchain: - Inverted       : 0
    [14990.880132] ledchain: - LED type       : WS2812
    [14990.884742] ledchain: - Max retries    : 3
    [14990.888891] ledchain: - Max Tpassive   : 10000 nS
    

    Good luck!



  • @crispyoz said in GPIO PWM:

    I answered my own question, using this doc

    https://docs.onion.io/omega2-docs/generating-pwm-signals.html

    This is another story.



  • @György-Farkas said in GPIO PWM:

    rmmod /lib/modules/4.14.81/p44-ledchain.ko

    Thanks @György-Farkas yes had the commands correct but seems there was some issue with my reflow oven, dry joins all over the place. 😞 Got everything working now, 2 x WS2812B looks really amazing in my casings.



  • For the record, you can cause ledchain to load the module with the required parameters by modifying the file
    /etc/modules.d/91-p44-ledchain



  • @crispyoz said in GPIO PWM:

    For the record, you can cause ledchain to load the module with the required parameters by modifying the file
    /etc/modules.d/91-p44-ledchain

    The firmware loads the 'p-44-ledchain.ko' module and makes the default 'ledchain2' without this file too.

    But you are right, we can modify the default ledchain and load the module with this file.
    For example if the edited file contains these parameters
    p44-ledchain ledchain0=<inverted>,<numberofleds>,<ledtype>[,<maxretries>[,<maxTpassive>]]
    then after a system restart (with a reboot command, press the RESET BUTTON or whit a power OFF - ON cycle) 'ledchain0' will be the default one.

    Question: Can you restart the 'p-44-ledchain.ko' module without restart Omega2?


    It's possible to use and modify on-the-fly more than one ledchain with the following commands and without restart Omega2:
    rmmod /lib/modules/4.14.81/p44-ledchain.ko
    insmod p44-ledchain ledchain<PWMno>=<inverted>,<numberofleds>,<ledtype>[,<maxretries>[,<maxTpassive>]]

    For example:
    omega2-ctrl gpiomux set pwm0 pwm
    omega2-ctrl gpiomux set pwm1 pwm

    rmmod /lib/modules/4.14.81/p44-ledchain.ko
    insmod p44-ledchain ledchain0=0,8,1
    echo -en '<string of bytes>' > /dev/ledchain0

    rmmod /lib/modules/4.14.81/p44-ledchain.ko
    insmod p44-ledchain ledchain1=0,8,2
    echo -en '<string of bytes>' > /dev/ledchain1
    and so on ...

    Unfortunately I can't restart the module without unload and reload it again 😞


    Did you know?

    You should use a 3.3V to 5V level shifter between the Omgea2/MT7688 PWM pin and the LED chain for reliable operation. Direct connection sometimes works, but the high level from the 3.3V output seems to be just on the minimum edge of what a 5V WS281x recognizes as high. Tiny differences in supply voltage for the LED chain can make it work or not.
    / @luz /



  • I would add that rmmod will fail if the module is in use, the error is not very useful "unloading the module failed". you need to kill any process that may be using the module.



  • @crispyoz Give us an example how do you use this module please.



  • @György-Farkas

    #include "include/ledutils.h"
    #include "include/gpiomux.h"
    #include "include/gpio.h"

    void init_multi_led(){
    // set GPIO to muxing so we can control the multi-colour LED
    gpiomux_mmap_open();
    // int mux_result = gpiomux_set("uart2", "pwm23");
    int mux_result = gpiomux_set("pwm0", "pwm");

    syslog(LOG_INFO, "GPIO Mux returned %d", mux_result);
    gpiomux_mmap_close();
    
    multi_led_fd = open("/dev/ledchain0", O_RDWR);
    

    }


Log in to reply
 

Looks like your connection to Community was lost, please wait while we try to reconnect.