Hey,
I want to “copy” the Spark RGB LED outside of the board to mine RGB LED with the Analog out pins.
How can I do this? Do I need common anode/cathode LED?
Thanks,
Itay
Hey,
I want to “copy” the Spark RGB LED outside of the board to mine RGB LED with the Analog out pins.
How can I do this? Do I need common anode/cathode LED?
Thanks,
Itay
Well, let’s take this LED as an example, seeing as how it seems to be well documented, and it already has a handy diagram. It’s a common cathode LED, but we could use a common anode LED the same way, the only difference is what way it’s wired up. See this diagram for example.
Now, differences from the diagram are that the Spark has ‘analog’ PWM output on pins A0, A1, A4, A5, A6, A7, D0 and D1. So, choose 3 pins for our output. Also, I believe that that circuit is intended to be driven by 5V outputs, whereas the Spark runs at 3.3V. No worries, we’ll use this handy calculator to figure out the proper size resistors for the LEDs. I say LEDs, because really a tricolor LED is just 3 LEDs in one package.
If we look at the datasheet we find that the LEDs all require 20 mA of current, and the forward voltage is 2, 3.2, and 3.2V for the RGB parts respectively. So we plug our numbers in to the calculator, we find that we need one 68 ohm resistor for the red part, and a 5.6 ohm resistor for the other two parts. So, wire as shown in the wiring diagram, substituting the found resistances.
As far as coding goes, the code found in the sample is practically ready for the Spark already, with just minor changes to the pin numbers (I chose A5,A6,A7):
int REDPin = A5; // RED pin of the LED to PWM pin **A5**
int GREENPin = A6; // GREEN pin of the LED to PWM pin **A6**
int BLUEPin = A7; // BLUE pin of the LED to PWM pin **A7**
int brightness = 0; // LED brightness
int increment = 5; // brightness increment
void setup()
{
pinMode(REDPin, OUTPUT);
pinMode(GREENPin, OUTPUT);
pinMode(BLUEPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
brightness = brightness + increment; // increment brightness for next loop iteration
if (brightness <= 0 || brightness >= 255) // reverse the direction of the fading
{
increment = -increment;
}
brightness = constrain(brightness, 0, 255);
analogWrite(REDPin, brightness);
analogWrite(GREENPin, brightness);
analogWrite(BLUEPin, brightness);
delay(20); // wait for 20 milliseconds to see the dimming effect
}
Hey @mumblepins,
Thanks for the answer, but I know how to do the PWM effect.
Maybe I wasn’t clear, I want to “take out”(or copy) the Spark RGB LED. I have a box, the spark core is placed inside and I want to see the “breathing LED” outside of the box. I want to connect my RGB LED to the Analog pins and make this behave like the spark core LED. I think it should be some parameter in the core firmware, some “inside IO pins”.
Ah, I misunderstood. Well, the easy solution is one of these: http://www.mouser.com/Optoelectronics/LED-Indication/LED-Light-Pipes/_/N-b1d20
The less snarky answer is that the firmware would have to be modified, and possibly even the hardware. If you want to display your own status updates, you could probably make an alternate RGB library, and switch the core to manual control, and monitor and setup connection that way.
I ?think? that if you wanted to get down and dirty, you could probably change the TIM1 Pin output in the firmware
to point to the CH1N, CH2N, and CH3N pins as opposed to the CH1, CH2, and CH3 pins. Those outputs are connected to the SPI pins, which correspond to A3, A4, and A5 respectively. Take all that with a very large grain of salt though, I don’t have a ton of experience with the firmware or the hardware behind it, so if you try it you might fry your core.
https://github.com/spark/core/blob/master/Datasheets/Manuals/STM32F10X-reference-manual.pdf
@mumblepins, It took me a while, but I looked inside the code. I saw what you mean with the "TIM" pins. The question is if I get the brightness of each TIM and send it to the Analog output. Did you see where they are sending the value of "breathing" LED or which VOID is handling it?
Thank you for your answer.
I know this is an old thread, but someone asked me about this recently, so I wanted to suggest this solution:
extern uint32_t lastSignalColor;
extern uint32_t lastRGBColor;
//and you can break out the value with something like:
uint16_t ccr[3];
ccr[0] = ((lastSignalColor >>16) & 0xFF);
ccr[1] = ((lastSignalColor >>8) & 0xFF);
ccr[2] = (lastSignalColor & 0xFF);
Thanks,
David