nxet
Posts: 7
Joined: Fri Jan 15, 2016 7:04 pm

wiringPi + MCP23017 + RGB LED

Sun May 08, 2016 7:25 pm

I've been trying to control a single RGB Led from Bash using the wiringPi library.
unfortunately the Soft PWM mode/output seems impossible to be used to I2C/MCP23017 pins, and I can only write 0/1 to each of the 3 leds.
any pointers on how to tackle this? am I missing some obvious point or is there more for me to understand before getting hands on this?
thanks
Raspbian, Raspberry Pi 2 Model B V1.1

User avatar
joan
Posts: 14695
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: wiringPi + MCP23017 + RGB LED

Sun May 08, 2016 7:29 pm

Software PWM only works on directly connected GPIO. You could write your own PWM to toggle the MCP23017 GPIO but I doubt it would be a satisfactory experience.

Why not connect the RGB LED directly to the Pi (with suitable resistors for each RGB leg).

nxet
Posts: 7
Joined: Fri Jan 15, 2016 7:04 pm

Re: wiringPi + MCP23017 + RGB LED

Sun May 08, 2016 7:52 pm

joan wrote:Software PWM only works on directly connected GPIO. You could write your own PWM to toggle the MCP23017 GPIO but I doubt it would be a satisfactory experience.

Why not connect the RGB LED directly to the Pi (with suitable resistors for each RGB leg).
Well then I guess I'll go down that road, luckily right now I'm only looking forward making a status indicator led so I won't run out of GPIOs anytime soon.
Out of curiosity, am I expecting any kind of Software PWM not going to work through I2C, or is it just something not (hopefully yet) implemented into the WiringPi lib? And, if the first is the case, would an hw PWM generator controlled via MCP23017 solve the issue?
Raspbian, Raspberry Pi 2 Model B V1.1

User avatar
joan
Posts: 14695
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: wiringPi + MCP23017 + RGB LED

Sun May 08, 2016 8:14 pm

nxet wrote:
joan wrote:Software PWM only works on directly connected GPIO. You could write your own PWM to toggle the MCP23017 GPIO but I doubt it would be a satisfactory experience.

Why not connect the RGB LED directly to the Pi (with suitable resistors for each RGB leg).
Well then I guess I'll go down that road, luckily right now I'm only looking forward making a status indicator led so I won't run out of GPIOs anytime soon.
Out of curiosity, am I expecting any kind of Software PWM not going to work through I2C, or is it just something not (hopefully yet) implemented into the WiringPi lib? And, if the first is the case, would an hw PWM generator controlled via MCP23017 solve the issue?
I'm not aware of anyone attempting PWM by toggling an I2C connected GPIO. Any discontinuity will cause very visible and annoying glitches on LEDs.

This device makes sense for driving LEDs via I2C, http://www.ebay.co.uk/itm/301893172030.

It's often marketed as a servo driver but really it's a PWM generator for LEDs.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: wiringPi + MCP23017 + RGB LED

Mon May 09, 2016 8:10 am

you may connect an Arduino Due or Zero to Raspi i2c
and let the Arduino do the pwm on board
https://www.arduino.cc/en/Main/ArduinoBoardDue
here I once have posted a Raspi to Arduino communication program:
http://www.mindstormsforum.de/viewtopic ... 909#p67909

Note that i2c on AVR Arduinos is not working reliably, probably because of clock stretching issues - but the ARM based Arduinos are fine with the Raspi! 8-)

(just transmit 1 Byte for Arduino dPin number
and 1 Byte(0...+255) or 2 Bytes (0...+1024) for pwm -
and let the Arduino do the ugly stuff)
;)
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

Return to “Beginners”