GPIO PWM
-
@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 WS2812Brmmod /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!
-
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
-
For the record, you can cause ledchain to load the module with the required parameters by modifying the file
/etc/modules.d/91-p44-ledchainThe 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 areboot
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 pwmrmmod /lib/modules/4.14.81/p44-ledchain.ko
insmod p44-ledchain ledchain0=0,8,1
echo -en '<string of bytes>' > /dev/ledchain0rmmod /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.
-
#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);
}
-
Gents, having some issues with the P44 module to control a Ring of LEDs
https://www.amazon.ca/gp/product/B0774JNSCF/ref=ppx_yo_dt_b_asin_title_o01_s01?ie=UTF8&psc=1
It is connected to the Omega2 via the expansion module to GPIO18
I belive everything in the omega is configured. I'm starting to suspect that the issue is with the expanison module.
-
@manuel-vera How are you testing? Please show all steps you are using.
You need to set the GPIO muxing, like so:
omega2-ctrl gpiomux set pwm0 pwm
Now test like this:
echo -en '\x00\x00\xff\x00\x00\xff\x00\x00\xff\x00\x00\xff' > /dev/ledchain0
This should make the first 4 LED change to blue colour.
-
I think I found the problem. I'm using PWM0 but in the Expansion board those seem to be GND.
I'm going to try to use UART1 as PWM. I will need to reconfigure the module (91-p44-ledchain to point to ward UART1 (PWM01)
Then I should be able to use TX1 as the Data line for the Ledchain.
Will report back
-
Failure again.
P44-ledchain only allows PWM channels 0-3, thus it would not let me load the module when I try UART1 (PWM01) or UART2(PWM23)
Runnning out of ideas and frankly frustrated.
The Power expansion board seem to be my limiting factor.
Any help would be appreciated
-
root@Test02-00000000:~# cat /etc/modules.d/91-p44-ledchain
p44-ledchain ledchain0=0,4,1,20,15000root@Test02-00000000:~#omega2-ctrl gpiomux set pwm0 pwm
set gpiomux pwm0 -> pwmroot@Test02-00000000:~#echo -en '\x00\x00\xff\x00\x00\xff\x00\x00\xff\x00\x00\xff' > /dev/ledchain0
Red wire if VDD, Green is GND, Grey is on GPIO18
First 4 LED on the board turn blue.
-
@manuel-vera Just ran the same test on PowerDock2, same result. Are you using Powerdock or Powerdock2? Looks like PowerDock. I don't have this to test.