Bright Bright Bright LED (s) – Controlled by the QPM Board
At SwitchDoc Labs, we love LEDs. They help us debug complex circuits and let us know when something is going wrong. As we have been building our new solar powered robot, SunRover, we have been wanting to add one of the new 3W RGB LEDs from Adafruit (https://www.adafruit.com/products/2530). We want this super bright LED to be mounted under the Pi Camera so we can take pictures at night. The tricky part was figuring out how to control it. This LED takes up to 350ma per each LED (for a total of ~1000ma) which is a lot more than you can sink with a GPIO from a Raspberry Pi (16ma MAX! from the Pi).
We decided to use our new product, the Quad Power Management I2C Board, to switch the current for each of the RGB LEDs in this device. The QPM Board will switch up to 2.3A per switch at up to 20V, so we are well within the capability of the board.
Since the LED is a common anode LED, this means that all the + sides of the 3 LEDs in the device are hooked up in common to the + (5V) voltage (through a current limiting resistor – see below) and we will then switch each of the cathodes (- side) of the LEDs to ground using the QPM board. Below is the circuit diagram of the LEDs and the QPM Board.
What can we do with this?
Since all of the LEDs are controlled by the Raspberry Pi via I2C bus, we can do lots of different special effects. We can strobe the lights, change the colors and even set the brightness (by switching the load switches on an off very much like a PWM system). All done through the Raspberry Pi and Quad Power Management Board via the I2C bus. Very fun.
Sizing the Resistor
The calculation for the size of the resistor is straight forward. At maximum current, the formula is R = (5V -Vfw)/1A. For these LEDs Vfw (V forward drop) is about 3.4V, yielding ~2 Ohms. Since we wanted to limit the current for each of the LEDs separately and SunRover is solar powered!, We used a 5 Ohm resistor which limits us to about ~320mA max. Using P=VI, we came up with P=(5V-Vfw)*1A or P(5V-3.4V)*1A or ~2W. Which is the minimum power dissapation of the resistor we need. Since we had a 5 Ohm 50W resistor in our tool box (from our wind power project), we used that.
Here is the QPM Board perched on the top board of the Circuit Condo inside the equipment bay in SunRover.
Here is a close up of the 3W RGB LEDs right under the Pi Camera in the Bubble Boy tower in SunRover.
The Software
This software below is a modification of the QPM Pure Python Drivers for the Raspberry Pi. It cycles through the three LEDs including the unused switch.
#!/usr/bin/env python # # # Test case for QPM # SDL_Pi_QPM Library for Rasbperry PI # # SwitchDoc Labs, August 2015 # # imports import sys import time import datetime import random import subprocess import SDL_Pi_QPM i2ccommand = "sudo i2cdetect -y 1" output = subprocess.check_output (i2ccommand,shell=True, stderr=subprocess.STDOUT ) print output # Main Program print "" print "Test SDL_Pi_QPM Version 1.0 - SwitchDoc Labs - Cycles LEDs for SunRover" print "" print "Sample uses 0x21 I2C Address" print "Cycles through all the four loadswitches" print "Program Started at:"+ time.strftime("%Y-%m-%d %H:%M:%S") print "" filename = time.strftime("%Y-%m-%d%H:%M:%SRTCTest") + ".txt" starttime = datetime.datetime.utcnow() QuadPower = SDL_Pi_QPM.SDL_Pi_QPM() print "-----------------" # enable all four channels # Enable Channels QuadPower.enablePowerChannel(QuadPower.QuadPower_POWER_CHANNEL_IO0, QuadPower.QuadPower_ENABLE) time.sleep(0.100) QuadPower.enablePowerChannel(QuadPower.QuadPower_POWER_CHANNEL_IO1, QuadPower.QuadPower_ENABLE) time.sleep(0.100) QuadPower.enablePowerChannel(QuadPower.QuadPower_POWER_CHANNEL_IO2, QuadPower.QuadPower_ENABLE) time.sleep(0.100) QuadPower.enablePowerChannel(QuadPower.QuadPower_POWER_CHANNEL_IO3, QuadPower.QuadPower_ENABLE) QuadPower.setDirectionGPIOChannel(QuadPower.QuadPower_REG_IO7, QuadPower.QuadPower_OUTPUT) time.sleep(0.100) value = QuadPower.readGPIO() print("------>>>> Initial GPIO Value =",value) # turn on I07 too QuadPower.writeGPIO(0x80) while True: print("----------------") # turn on I07 too QuadPower.writeGPIO(0x80) print("Turn on LSW0") time.sleep(0.100) QuadPower.setPowerChannel(QuadPower.QuadPower_POWER_CHANNEL_IO0, QuadPower.QuadPower_ON) time.sleep(3) print("Turn on LSW1") time.sleep(0.100) QuadPower.setPowerChannel(QuadPower.QuadPower_POWER_CHANNEL_IO1, QuadPower.QuadPower_ON) time.sleep(3) print("Turn on LSW1,2") time.sleep(0.100) QuadPower.setPowerChannel(QuadPower.QuadPower_POWER_CHANNEL_IO2|QuadPower.QuadPower_POWER_CHANNEL_IO1, QuadPower.QuadPower_ON) time.sleep(3) print("Turn on LSW1,2,3") time.sleep(0.100) QuadPower.setPowerChannel(QuadPower.QuadPower_POWER_CHANNEL_IO3|QuadPower.QuadPower_POWER_CHANNEL_IO2|QuadPower.QuadPower_POWER_CHANNEL_IO1, QuadPower.QuadPower_ON) time.sleep(3) QuadPower.setPowerChannel(QuadPower.QuadPower_POWER_CHANNEL_IO3|QuadPower.QuadPower_POWER_CHANNEL_IO2|QuadPower.QuadPower_POWER_CHANNEL_IO1, QuadPower.QuadPower_OFF)