Control RGB strip using PWM on a Raspberry Pi

Hello all,
I want to control a RGB LED strip using PWM but the Raspberry Pi only has one PWM output (pin 18) and I need 3 of them. Is there a way to use the RPi.GPIO library through Blynk so I can use the software PWM in any of the output pins? Or another solution?
Thanks in advance,

PWM is a hardware thing. There is, as far as I know, no way to do this in the software. You could replace the Pi with a little ESP-07 or something. That even gives you freedom of location of where to put the lights.

Thank you for your reply.
In fact after spending some hours looking around I guess my question is kind of a broad subject… meanwhile I found a couple of libraries that could do the trick but I’m getting some errors on install.
I finally found pi-blaster library that is CPU efficient and can be used by any pin to make a PWM signal.
I’m now making some tests with a C++ program using pi-blaster and blynk. It is starting to work, I’ll publish my results here when I have my test app working.

1 Like

That sounds cool. I’d like to know if this works of course. I still need to buy a second Pi for testing, but I haven’t got around to it yet, lol.

Yes, you can use the software PWM option build-in in wiringPi. And since blynk uses wiringPi you only need to include the right header files and call the right functions. But since it is a software solution, the possibilities are somewhat limited. Anyway, just try it and see if this is a solution for you.

I’ll give an example where I control a 3 color led using 3 slider widgets connected to virtual pins V10, V11 and V12. The example uses the c language, so I need to change the main.cpp file in ~/blynk-library/linux directory and then rebuild the blynk command using “make clean all target=raspberry”.

You should include the next code just above the main() function.

#include <softPwm.h>
#define LedPinRed    16
#define LedPinGreen  20
#define LedPinBlue   21

void led3CInit(void)
	softPwmCreate(LedPinRed,  0, 0xff);
	softPwmCreate(LedPinGreen,0, 0xff);
	softPwmCreate(LedPinBlue, 0, 0xff);
	softPwmWrite(LedPinRed,   0xff);	// init all leds off
	softPwmWrite(LedPinGreen, 0xff);
	softPwmWrite(LedPinBlue,  0xff);

	BLYNK_LOG("Got Color change, red= %d", param.asInt());
	softPwmWrite(LedPinRed,   0xff-param.asInt());
	BLYNK_LOG("Got Color change, green= %d", param.asInt());
	softPwmWrite(LedPinGreen, 0xff-param.asInt());
	BLYNK_LOG("Got Color change, blue= %d", param.asInt());
	softPwmWrite(LedPinBlue,  0xff-param.asInt());

You also need to add the init function led3CInit() to the main() function in order to initialise the software PWM pins.

I should indicate that I used a 3 color led with common + 3.3V connection. So in order to switch off the led I need to send a “1” (=255=0xff in PWM mode) to the output pins.