Recently back to work on a 12V RGB LED colour controller that I haven’t worked on in a while as a break from study (actually, read as avoidance of doing any study for a day). After finally finding the current version of the code (that was an ordeal and a half – had the newer copy in a different folder). I had gotten basic colour selection, brightness control and a seven colour strobe sequence working. Now it was time to do the rest of the colours and get the ‘colour wheel’ / fade working. Easy. Well, I did a complete re-write of the code, and changed to colour mapping from hard coded RGB to using HSI, which I will talk about in another post. In a nutshell, it let me separate the colour I wanted to set from the brightness or intensity, and as a result, I can easy just set the colour, and change the brightness – and it will re-calculate the new colour codes automatically.
Also made the colour wheel exceptionally easy. So, moving from the small 9 led test strip to the full length 3m ceiling mounted strip and the moment of truth. Switched it on, and chose white. Grea…. aw… what the flicker? It’s pulsing… and quite noticably. So, is there a glitch in the code, or fluctuation of the power supply meaning I really do need to put some filter caps on it. Try some of the other colours… they’re all fine… just white, but some combinations show the flicker also.
Back to google, and a general search for ‘rgb led arduino flicker’ and ‘rgb led arduino pwm flicker’. I suspected the issue was related to the particular pwm duty cycle, so that’s why I looked for PWM related results as well. I saw a few posts which suggested the original posters problems were power related, but then I saw two posts by a chap who has done some great articles on Arduino stuff in the past. And he was having the same problem. He said he though some of his trouble was power supply related, but when he tested the output of the PWM control signals for the LEDs, he noticed that they weren’t what they should have been… and one channel was going in and out of phase… and visibly so! Great… so I wasn’t my imagination. And in his follow-up post, he had the solution… just one line of code in the setup function, and the PWM signal to the three pins in use would be in perfect sync! Eureka! The miraculous line of code is as follows:
Do I hear you ask “What does it do?” Excellent question. In a nutshell, it changes the Timer 1 setting from Phase Correct PWM to Fast PWM, which is what Timer 0 is set to. Although Phase Correct PWM may be the better quality / higher accuracy PWM mode, due to the fact that we are both using RGB leds that are connected to pins controlled by Timer 0 (5 & 6) & Timer 1 (9 & 10), they need to be set to the same mode. Otherwise, the difference in operation will result in a visible flicker. For a much clearer and detailed explanation, please check out Jean-Claude’s postings which I linked above.
After adding just this one line of code, I can happily report that the colour controller is now running without a single flicker. Now I just have to fine tune the colours and add the final touches!
After a long wait (although with study and other stuff happening I didn’t really notice), today’s post was the Digistump Digispark Pro! Plus several addon shields including an OLED display, GPS, Wifi and nrf24L01+ 2.4Ghz transceiver. And the obligatory LEDs to make blinking lights!
|Parts for I2C backpack|
Based around the MCP23008, which is a I2C 8-Bit I/O Expander, this little board allows me to control a LCD from the I2C bus of an Arduino, and even use those two pins to also talk to a real time clock (RTC) and other I2C devices! This variation of the design allows for the LCD backlight to be controlled digitally, with the contrast being set using the potentiometer and jumpers to allow one of eight hardware addresses to be set. I didn’t come up with this idea
|The finished board|
And here is a picture of the board nestled on the back of a 16×2 LCD which it now controls.
|16 x 2 LCD with I2C controller attached|
To finish off, for more information on this design, including schematics so you can create your own, visit the Arduino Playground and this forum article. My variation to this was to use a BS170 mosfet to control the backlight, and add jumpers to allow for the I2C hardware address to be changed. I use the Adafruit LiquidCrystal library to control it using a breadboard Arduino. Has been running 24 x 7 for approx two months without any issues as yet.
- 30-12-2012 – Posts to cosm.com every 15 minutes (as opposed to every 30 minutes)
- 30-12-2013 – Multiply atmospheric pressure value by 10 to report hPa rather than kPa (breaks historical data)
- 30-12-2012 – Changed analog LDR sensor for digital lux light sensor (breaks historical data)
- 27-12-2012 – Now running from a 5v mains powerpack rather than a 12v SLA battery with maintenance charger.
- LCD to display data locally
- SD card to log data locally for analysis
- Post to twitter when downtime occurs (with explanation codes – ie. loss of network connection)
Brains of the unit (microcontroller) = Atmel ATmega328
- Plug-in Network Module having W5200 & Mag Jack
- Usable without H/W design for W5200, Transformer and RJ-45
- Good for 0-100% humidity readings with 2-5% accuracy
- Good for -40 to 80°C temperature readings ±0.5°C accuracy
- Pressure sensing range: 300-1100 hPa (9000m to -500m above sea level)
- Up to 0.03hPa / 0.25m resolution
Light = TSL2561 digital luminosity / lux / light sensor
- Approximates Human eye Response
- Precisely Measures Illuminance in Diverse Lighting Conditions
- Dynamic range (Lux): 0.1 to 40,000 Lux
I have recently been having fun with a solar-energy power monitoring system, some friends live in a remote area without access to grid power. They are currently using two banks of old Telcom v2 SLA cells, with pair of solar panels on the roof for charging. There is a 600w inverter providing 240v power for the house, and a solar management unit to ensure peak charge from the solar panels. There is a 240v petrol generator providing backup power and also charging the batteries via a intelligent SLA 25A charger. To make life easier, there is also a automatic change-over switcher which will run the house off the generator whilst it is running, and automatically drop back to the batteries / inverter when it stops.
To monitor the state of the batteries and system, we have installed a Arduino clone board (Freetronics EtherMega) with a RTC, MicroSD card and custom op-amp and shunt sense board. This allows for the battery voltage, load and charge status to be tracked via a 20×4 LCD screen, as well as over the network via a custom website. Plus with data capture, the state of the batteries can be analysed on a excel graph.
This is where I came. As a result of about three weeks of off-and-on work on the system, I have taken it from a system which simply displayed the voltage, load and charge current of the batteries to a system which is network capable, with a custom website which allows access to this information plus more. There is now a real-time clock onboard as well, so the system knows the current date and time. There is also a MicroSD card which is being used to capture data for later analysis. The website allows the user to grab the data in CSV format, and easily graph it using Microsoft Excel, thus easily visualise the data over time and assess the condition of the batteries.
The website also allows for calibration of the unit, formatting of the MicroSD card, saving of calibration data and resetting to default settings. Next up is to refine and make the code more bullet-proof, and also add the ability to set the time! Then, time to work out how to track the capacity of the batteries in a reliable manner.
My Arduino is currently sat on the table next to me with a LCD screen and two analog sensors (a photodiode and thermistor – light and temperature sensors). It’s currently very dark, and approximately 21 C… not nice! I’m currently catching up on episodes of ‘The Amp Hour‘. I found the podcast a couple of weeks, back and am listening to it from the start. Currently listening to #13, only 33 to go!!
|Arduino Uno with yellow backlight LCD, thermistor (for temperature)
and photodiode (for light). There is a three colour LED on the
breadboard but it’s not being used at the moment
I haven’t posted for a while due to study, life and other commitments in general… so I thought it was time for an update.
I’m currently playing with a micro-controller prototyping system known as Arduino, which allows you to do just about anything once you get started … what you have access to and your imagination is your only limitation!!! You can make a simply program and circuit to flash a LED, or run a LCD screen that shows the current temperature and light levels, or perhaps a notifier to let you know ‘You’ve Got Mail!’?! The choice is yours (and btw, I’ve done all three and more). Next up will be motor control and switching things like lights and other circuits off and on… Stay tuned!!!