Serial Controlled RGB LED PWM Driver PIC12F629 based PWM controller for RGB LEDs




Description

If you want to build your own multiple RGB LED display that you can control from either a PC or a dedicated controller then this project will let you do just that.

The project on this page came about when while I was developing a more complex intelligent driver. During that work I put together a simple Red/Green/Blue Pulse Width Modulation LED driver that has a serial interface.  The RGB values to control the LED brightness are sent to the PWM driver over this serial interface.

With both the original and revised versions of the RGB PWM driver there was one big shortcoming when you want to have several drivers working together.  Even when they’re running the same sequence, the small differences in the frequency of the internal RC oscillator cause some to run the sequence slightly faster, others slower.  The result, well sometimes it’s quite effective, but mostly it just looks awful.

With the controller / driver presented here it is possible to connect multiple drivers to the same serial cable, all attached units then appear to operate synchronously since they’re all receiving the same control data.  The PCB for the RGB PWM Driver has been designed so that it can be used with both the serial control firmware on this page, or the standalone firmware here

Serial Controlled RGB LED PWM Driver

The serial data can be sent from the serial COM port of a PC or using a small dedicated controller that I’ve put together. The Controller code is based on the standalone RGB driver code described elsewhere on this website.  The controller uses the same format for the sequence data as the standalone RGB driver so any SequenceData.inc files you have for the standalone driver can be used with the Serial RGB Controller.

The pictures below show an RGB Driver placed inside a 6″ opal glass light fitting.  I bought this from a DIY store for £4.99 (see here).  When the LED driver is fitted in the base it illuminates the whole globe.  Because most 5mm LEDs have quite a narrow viewing angle you tend to got ‘hot spots’ in the top but overall it’s very effective and makes for great mood lighting.   (In case it isn’t obvious you do not connect the light fitting to the mains electricity supply when used with the RGB Driver!!!)

Also check this mood light by Pete Rus which is based on the Standalone PIC controller
http://www.instructables.com/id/E5A6O59KDPEUSZO1BK/?ALLSTEPS


How it works

Back to the RGB LED Driver.  Depending on which firmware you program into the PIC this PCB and hardware can operate as either a serial controlled driver or a stand-alone driver (see here). 

Version Firmware
PC Controlled ssrgbdrv.zip
Serial RGB Controller ssrgbdrv.zip
Stand Alone RGB Code rgbsa_inet.zip

Serial Data Format

Serial Data is sent to the RGB PWM Driver using a standard 2400bps asynchronous serial data stream (like you get from the COM port of a PC).  The serial frame format is 1 start bit, 8 data bits, 1 stop bit.   RS232 devices, including the PC COM port, always generate a start bit so when you look at the serial port parameters in Windows you won’t see it as an option.  Use 8N1 for the COM port settings.

 The RGB values for the PWM driver are sent in a five frame packet.

  • The first frame must always contain the value 0x81 (129 decimal)
  • The next three frames contain the 8-bit Red, Green and Blue data for the PWM driver. 
  • The last frame is the checksum.  It should contain the 2’s compliment of the sum of the previous four frames, modulo 256.
    The code snippet below shows the checksum computation in PIC assembler.

movlw     0x81
addfw     RedPWM, W
addfw     GreenPWM, W
addfw     BluePWM, W
sublw     0x00
movwf    
chksum

The Serial RGB Controller will take care of all this for you. However, if you write an application to generate the data from a PC the application itself will need to take care of this.

Controlling from a PC

During development of the Driver I put together a couple of short Perl scripts for testing purposes. The first one takes user entered RGB values and sends them through the PC serial port to the driver.  The second one sends a continuous stream of RGB data to the driver that generates a ‘wave’ effect.  (Both scripts are hard coded to use COM1)

At this point I need to make it clear I am not supporting the Perl scripts.  The ability to send data to the Driver from a PC is a bonus.  If you don’t know Perl or have no previous programming experience you will probably be unable to make use of them.
PLEASE DO NOT e-mail me asking for help with these scripts
I don’t like having to say that, but PIC programming I do for fun; Perl I do not. 

The scripts are written for ActivePerl and require the module Win32::SerialPort. 

Some Perl resources – if you want to learn Perl.

If you write some code for the PC to control the driver boards and you’re prepared to share it, let me know and I’ll be happy to link to it from here.


Addressable version of the Serial controlled RGB PWM driver  (added January 2011)

IMPORTANT: Please be absolutely clear about this: it’s available, it’s free, it does work and has been tested but I will not support it, modify it, or help you implement any application with it. Please don’t email me asking for any support – really.

The project on this webpage is a based on code I wrote for an addressable RGB controller, it’s just a cut down version.  At the time I wrote it I didn’t have any supporting software to send data to the addressable modules, for that reason I didn’t make the addressable code available.  I still don’t have any code other than that I used for my own application.  I actually went on to develop the the Serial Addressable RGB PWM LED/Servo Driver which was much better, if a bit more complex.

However over the last four years I’ve been contacted by email on many occasions asking for an addressable version of this project and I’ve let people have the code I’m now making available here on request.

The packet format is described in detail in the PDF file download: Packet format

The source code for the addressable version of the Serial controlled RGB PWM driver can be download from here

 

For more detail: Serial Controlled RGB LED PWM Driver PIC12F629 based PWM controller for  RGB LEDs




Current Project / Post can also be found using:

  • rgb led controller with pic12f675
  • pwm project
  • pwm rgb driver
  • rgb led dimmer pic controller

Leave a Comment

*
= 5 + 5

Read previous post:
[Simple] Generating Pulse Width Modulation using PIC Microcontroller – Mikro C & Proteus Simulation

How to generate Pulse Width Modulation (PWM) using PIC microcontroller? This is going to be a continuation of our microcontroller online tutorial...

Close
Scroll to top