A simple PWM LED approach for the Thingy:91

I'm trying to drive the RGB LED light on the Thingy:91. So far, I've not been successful. I was hoping that by listing the steps I perform I might be able to get some advice. This is the first time that I've dealt with PWM. Here are the steps I'm presently taking:

1. Using PWM0_NS (my program is insecure), assign pins p0_29, p0_30, and p0_31 having set them up as push/pull output with an initial level of high.
2. Set the period of the PWM to 500hz.
3. I then loop around wanting to toggle the LED on and off by setting the duty of all three channels to the max duty (on) and 0 (off) with about 1 second sleep in between.

Does this approach seem reasonable? I really want the simplest PWM RGB LED demo I can; think of blinky for the RGB LED.

Thanks for any help.

Top Replies

Parents
  • Hello Christopher,

    Zephyr provides a straightforward sample showing how to control an LED with a PWM peripheral.

    You can find it in your ncs folder: ../zephyr/samples/basic/blinky_pwm.

    It doesn’t work for the Thingy:91 from scratch, but you can easily get it to work with the following modifications:

    • Create an overlay file in your application root called: thingy91_nrf9160ns.overlay
    • Add the following lines to the overlay file

    / {
        pwmleds {
            compatible = "pwm-leds";
            pwm_led0: pwm_led_0 {
                pwms = < &pwm0 0x1f >;
            };
        };
    
        aliases {
            pwm-led0 = &pwm_led0;
        };
    };

    • Build and run

    The application should now trigger the blue LED colour of the lightwell LED.

    I hope this is a good starting point for you!

    Regards,

    Markus

Reply
  • Hello Christopher,

    Zephyr provides a straightforward sample showing how to control an LED with a PWM peripheral.

    You can find it in your ncs folder: ../zephyr/samples/basic/blinky_pwm.

    It doesn’t work for the Thingy:91 from scratch, but you can easily get it to work with the following modifications:

    • Create an overlay file in your application root called: thingy91_nrf9160ns.overlay
    • Add the following lines to the overlay file

    / {
        pwmleds {
            compatible = "pwm-leds";
            pwm_led0: pwm_led_0 {
                pwms = < &pwm0 0x1f >;
            };
        };
    
        aliases {
            pwm-led0 = &pwm_led0;
        };
    };

    • Build and run

    The application should now trigger the blue LED colour of the lightwell LED.

    I hope this is a good starting point for you!

    Regards,

    Markus

Children
Related