2

Is the Raspberry Pi 2 better at controlling RGB LEDs then then Raspberry Pi B+ due to it being faster?

Reason why I think this is because when I control my RGB LEDs I notice they change colour (both in Python and C++). Is this because the slower processor cannot turn the pin on and off fast enough? If the Raspberry Pi 2 is faster it should be able to turn the pin on and off the same time all the time?

  • Why not use hardware timing instead? It's not as if the Pi is short of methods. – joan May 30 '15 at 10:34
  • What do you mean? – iProgram May 30 '15 at 10:56
  • Use either the hardware PWM on gpios 12/13 or 18/19 or something like my pigpio library which provides hardware timed PWM on all the gpios. – joan May 30 '15 at 12:00
  • Thanks for the tip. Only issue is I need 3 PWM pins for the RGB LEDs. This means I can only control 2 or the RGB channels and if I need more RGB LEDs then I will have to use software PWM anyway. – iProgram May 30 '15 at 16:59
  • pigpio provides hardware (not software) timed PWM on all the gpios. I've driven 8 RGB LEDs from 24 of the gpios on the B+ and Pi2. – joan May 30 '15 at 19:50
2

If the output rate (the frequency) of your software PWM is at the B+ really limited by the computational load then yes, it might be possible that a faster Pi2 would be "better". But there are many ifs and buts here.

Before jumping to a new Pi2 it might be worth to profile the current code and find out why it is as slow as it is. Maybe this could be improved by honing and tweaking the algorithm. Optimization of software fell a little behind these days when upgrading hardware is cheap.

  • I made a C++ test script called speedTest that creates 3 software PWM pins and sets them all to 50% and as soon as that was done it stopped the script. To time it I done time sudo ./testScript and this is what it outputted real 0m0.085s user 0m0.020s sys 0m0.050s. I then put a 2 second delay between setting the output and stopping the script and the RGB LED did change colour still. Is that good timing or is it slow? – iProgram May 30 '15 at 10:49
2

The Raspberry Pi 2 is both faster and has four cores.

Both those increase the chance that software timing will be accurate (as there is less chance that something else needs to be run at the same moment as the timer expires).

It's all relative though, as the system get busier the timing will get less reliable again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.