Archive for the ‘ Projects ’ Category

LED Matrix Displays

*Updated small bug where I forgot to enable the system afterwards…

I’ve managed to pick up a few LED matrix displays from Sure Electronics that use the HT1632 LED Matrix driver, as such, I have written a new library for the Arduino project to make use of the displays, I haven’t done anything in relation to generating characters for them or doing any scrolling, but I can now pretty much call all of the features of the handy driver. There is still some work to do on cleaning up the library and adding some more functionality, but it does indeed work as it should. Here is the source…

/*
 
    Holtech HT1632 Driver Class (Header)
    Values taken from Datasheet...
 
*/
 
#ifndef HT1632_h
#define HT1632_h
 
//Data Mode
#define HT1632_CTL_COMMAND      0x04    //Preceeds all _COMMANDS_ to the system
#define HT1632_CTL_WRITE        0x05    //Write data to the RAM
#define HT1632_CTL_READ         0x06    //Read data from the RAM
 
//Command Mode
#define HT1632_CMD_SYSDIS       0x00    //Turn off system oscillator and LED duty cycle generator
#define HT1632_CMD_SYSEN        0x01    //Turn on system oscillator
#define HT1632_CMD_LEDOFF       0x02    //Turn off LED duty cycle generator
#define HT1632_CMD_LEDON        0x03    //Turn on LED duty cycle generator
#define HT1632_CMD_BLINKOFF     0x08    //Turn off blinking function
#define HT1632_CMD_BLINKON      0x09    //Turn on blinking function
#define HT1632_CMD_SLAVEMODE    0x10    //Set slave mode and clock source from external clock, the system clock input from OSC pin and synchronous signal input from SYN pin
#define HT1632_CMD_RCMASTER     0x18    //Set master mode anc clock source from on-chip RC oscillator, the system clock output to OSC pin and synchronous signal output SYN pin
#define HT1632_CMD_EXTCLK       0x1C    //System clock source, external
#define HT1632_CMD_COM00        0x20    //N-MOS open drain output and 8 COM option
#define HT1632_CMD_COM01        0x24    //N-MOS open drain output and 8 COM option
#define HT1632_CMD_COM10        0x28    //P-MOS open drain output and 8 COM option
#define HT1632_CMD_COM11        0x2C    //P-MOS open drain output and 16 COM option
 
//Command Mode - PWM Settings
#define HT1632_CMD_PWM01        0xA0    //PWM 1/16 Duty
#define HT1632_CMD_PWM02        0xA1    //PWM 2/16 Duty
#define HT1632_CMD_PWM03        0xA2    //PWM 3/16 Duty
#define HT1632_CMD_PWM04        0xA3    //PWM 4/16 Duty
#define HT1632_CMD_PWM05        0xA4    //PWM 5/16 Duty
#define HT1632_CMD_PWM06        0xA5    //PWM 6/16 Duty
#define HT1632_CMD_PWM07        0xA6    //PWM 7/16 Duty
#define HT1632_CMD_PWM08        0xA7    //PWM 8/16 Duty
#define HT1632_CMD_PWM09        0xA8    //PWM 9/16 Duty
#define HT1632_CMD_PWM10        0xA9    //PWM 10/16 Duty
#define HT1632_CMD_PWM11        0xAA    //PWM 11/16 Duty
#define HT1632_CMD_PWM12        0xAB    //PWM 12/16 Duty
#define HT1632_CMD_PWM13        0xAC    //PWM 13/16 Duty
#define HT1632_CMD_PWM14        0xAD    //PWM 14/16 Duty
#define HT1632_CMD_PWM15        0xAE    //PWM 15/16 Duty
#define HT1632_CMD_PWM16        0xAF    //PWM 16/16 Duty
 
#include "wProgram.h"
 
class HT1632 {
    public:
        HT1632(byte data, byte wclock, byte chip0, byte chip1=NULL, byte chip2=NULL, byte chip3=NULL, byte rclock=NULL);
        void ChipSelect(byte chip);
        void ChipRelease(byte chip);
        void SendCommand(byte command, byte chip=0);
        void WriteBits(byte bits, byte mask);
        byte ReadData(byte address, byte chip);
        void Clear(byte chip=0);
        void WriteData(byte address, byte data, byte chip=0);
        void Init(byte chip=0);
        void BlinkMode(bool blink=false, byte chip=0);
 
    private:
        byte _DATA;
        byte _WCLOCK;
        byte _RCLOCK;
        byte _CHIP0;
        byte _CHIP1;
        byte _CHIP2;
        byte _CHIP3;
};
 
#endif
/*
 
    Holtech HT1632 Driver Class
    Some functionality inspired by westfw from this thread: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1225239439
 
*/
 
#include "wProgram.h"
#include "HT1632.h"
 
HT1632::HT1632(byte data, byte wclock, byte chip0, byte chip1, byte chip2, byte chip3, byte rclock) {
    //Set the I/O Directions
    pinMode(data, OUTPUT);
    pinMode(wclock, OUTPUT);
    if(rclock) {
        pinMode(rclock, OUTPUT);
        _RCLOCK = rclock;
    }
 
    pinMode(chip0, OUTPUT);
    digitalWrite(chip0, HIGH);
    _CHIP0 = chip0;
 
    if(chip1) {
        pinMode(chip1, OUTPUT);
        digitalWrite(chip1, HIGH);
        _CHIP1 = chip1;
    }
 
    if(chip2) {
        pinMode(chip2, OUTPUT);
        digitalWrite(chip2, HIGH);
        _CHIP2 = chip2;
    }
 
    if(chip3) {
        pinMode(chip3, OUTPUT);
        digitalWrite(chip3, HIGH);
        _CHIP2 = chip2;
    }
 
    _DATA = data;
    _WCLOCK = wclock;
}
 
void HT1632::ChipSelect(byte chip) {
    switch(chip) {
        case 0:
            digitalWrite(_CHIP0, LOW);
            break;
        case 1:
            digitalWrite(_CHIP1, LOW);
            break;
        case 2:
            digitalWrite(_CHIP2, LOW);
            break;
        case 3:
            digitalWrite(_CHIP3, LOW);
            break;
        }
}
 
void HT1632::ChipRelease(byte chip) {
    switch(chip) {
        case 0:
            digitalWrite(_CHIP0, HIGH);
            break;
        case 1:
            digitalWrite(_CHIP1, HIGH);
            break;
        case 2:
            digitalWrite(_CHIP2, HIGH);
            break;
        case 3:
            digitalWrite(_CHIP3, HIGH);
            break;
    }
}
 
void HT1632::WriteBits(byte bits, byte mask) {
    while (mask) {
        digitalWrite(_WCLOCK, LOW);
        if (bits & mask) {
            digitalWrite(_DATA, HIGH);
        } else {
            digitalWrite(_DATA, LOW);
        }
        digitalWrite(_WCLOCK, HIGH);
        mask >>= 1;
    }
}
 
void HT1632::SendCommand(byte command, byte chip) {
    ChipSelect(chip);
    WriteBits(HT1632_CTL_COMMAND, 1<<2);//3 bit command id
    WriteBits(command, 1<<7);//8 bit command
    WriteBits(0,1);//There's one extra bit in commands that dont matter...
    ChipRelease(chip);
}
 
byte HT1632::ReadData(byte address, byte chip) {
    //Do stuff here to read the data from the chip...
}
 
void HT1632::Clear(byte chip) {
    ChipSelect(chip);
    for(int i=0; i<256; i++) {
        WriteData(i, 0);
    }
    ChipRelease(chip);
}
 
void HT1632::WriteData(byte address, byte data, byte chip) {
    ChipSelect(chip);//Select the chip...
    //Send the WRITE command...
    WriteBits(HT1632_CTL_WRITE, 1<<2);  //3 bit command
    //Send the Address...
    WriteBits(address, 1<<6);   //7 bit address
    //Send the data...
    WriteBits(data, 1<<3); //4 bit data
    ChipRelease(chip);//Release the chip...
}
 
void HT1632::Init(byte chip) {
    SendCommand(HT1632_CMD_SYSDIS); //Disable system
    SendCommand(HT1632_CMD_COM11); //PMOS drivers
    SendCommand(HT1632_CMD_RCMASTER); //Master mode
    SendCommand(HT1632_CMD_SYSEN); //System Enable
    SendCommand(HT1632_CMD_LEDON); //Enable the display
    Clear(chip);
}
 
void HT1632::BlinkMode(bool blink, byte chip) {
    if(blink) {
        SendCommand(HT1632_CMD_BLINKON, chip);
    } else {
        SendCommand(HT1632_CMD_BLINKOFF, chip);
    }
}

Just a general update…

It’s been quite a while since I’ve posted  anything, I’ve been very busy lately but since I’m out sick now for a few days, I have a bit of time to update…

If you have tried to play Fallout 3 using an Asus branded NVidia card, and it crashes stating “Fallout 3 has stopped working” every time you try to load a new game, check and see if you have Asus Gamer OSD installed, if you do, get rid of it. Something the overlay does interferes with the game  and causes this to happen…

I have been doing some more work on the lighting for the man cave so I have some Python code that will pull the Average color (not the most predominant, yet, wont be hard, but I am lazy) so here it is, please keep in mind its not nice, fast or clean… for high res images it takes a few seconds to do its thing…

#!/usr/bin/env python
 
#
# PIL Image Module Handbook - http://www.pythonware.com/library/pil/handbook/image.htm
#
 
from PIL import Image
from optparse import OptionParser
 
def processImageAverage(imageFile):
    image = Image.open(imageFile)     #open the image for processing
    pixels = list(image.getdata())    #break the image down into a list of pixels, each pixel contains a list of red,green,blue
 
    totalpx = 0 #set some default values to start counting...
    redpx = 0
    greenpx = 0
    bluepx = 0
 
    for pixel in pixels:    #loop through the lists and build the values.
        totalpx += 1
        redpx += pixel[0]
        greenpx += pixel[1]
        bluepx += pixel[2]
 
    redavg = redpx / totalpx   #generate the averages
    greenavg = greenpx / totalpx
    blueavg = bluepx / totalpx
 
    print "\nTotal Pixels:\t", totalpx     #and write them out.
    print "Red Average:\t", redavg
    print "Green Average:\t", greenavg
    print "Blue Average:\t", blueavg
    print "HEX Color:\t#%x%x%x" % (redavg, greenavg, blueavg)
 
def main():
    parser = OptionParser("Usage: %prog source")
 
    (options, arguments) = parser.parse_args()
    if len(arguments) != 1:
        parser.error("Please specify a single input file.")
 
    processImageAverage(arguments[0])
 
if __name__ == "__main__":
    main()

I have a new job now, I’m no longer a software validation engineer (tester), I’m now an IT Support Engineer (IT Techie…) which is kinda nice….

Well… that is for now…

New addition to the ManCave for the bar…

http://img519.imageshack.us/img519/8719/p140210164301.jpg

€1366.07 down…

So I have been doing some serious work on my mancave during my two weeks off, so far I have all of the walls battened, the new door fitted, and two of the walls wired for mains sockets. I have even been picking up some additional parts that we are not quite ready yet, such as a roll of CAT6 cable, CAT6 wall outlets with faceplate’s, 17 double gang switched sockets and much much more… all in all its coming along nicely. No photo’s taken as of yet though, I really should have taken some at the start and all the way through as it would have been quite a good evolution slide show, but alas its too late now… we did run into a few issues though, the garage is still crammed full of stuff and there is not much room to move around in it so that has been slowing us down a lot, however there is nowhere else to put it so it has to be this way for now I’m afraid :(

Another issue we’ve encountered was that the cavity blocks haven’t aged all that well and are quite hard, like flint even, so masonry nails havent been working out too well on that, so as a more expensive, and time consuming work-around, we have been using nail-anchors and manually drilling for each baton… not the most fun thing in the world, but at least its progress…

As a side note, from working out in the cold weather all week I seem to have gotten another cold :(

Embedded Linux Development

I work for a company that is currently utilising Linux on an embedded platform, now I am a big fan of Linux, and I do really like embedded systems… so the natural progression was to go and learn about embedded Linux development. I managed to find a really good book called the Embedded Linux Primer: A Practical Real-World Approach which really is very good. So, as a kind of training exercise, I will be attempting to build my own customer miniture linux distribution (borrowing some things from other projects) for an embedded system. The board I have chosen is the BifferBoard which is available from http://www.bifferboard.com and is a very cheap x86 based system with a lot of handy features such as UART, JTAG, GPIO, Ethernet, really good board and again, really cheap, I paid around €30 for mine…

I do have a few goals that I intend to accheive in the proccess of doing this project and a few additional tools will be imported from other projects… the main requirements that I have are…

  • Very small footprint.
  • Custom compiled kernel that has the bare essentials to support all of the hardware on the board natively, no KLM’s allowed.
  • A working shell environment, Busybox is my target at present.
  • A port of UCI which is extensively used throughout OpenWRT, that really is an awesome configuration utility.
  • A port of the LUCI framwork, again, used extensively throughout OpenWRT.
    • LUCI is a MVC based framework written in LUA that provides superb interaction with the UCI configuration tool.
  • A method of automatically ‘provisioning’ a unit with a set of configuration files
    • Most likely the provisioning will be handled on a back end server somewhere (read: webserver) where the unit it’s self simply checks the server on first boot and will grab the config files if they exist.
  • Support for V4L and webcams. This provides the potential to take a cheap webcam, and a cheap board, and have a cheap IP camera.

More will be added to this list as some of the items are checked off or as a need arises for them. One thing that I cant think of, and I have never been very good at it, is a name for the project. Any ideas? Please do let me know in the comments, one idea I heard was ic-linux…

Since committing to doing this I have built a small development area for myself using my Laptop and some other equipment I had that would be useful, USB hub, old router with DHCP disabled as I dont have a small switch, various tools, memory sticks etc… unfortunately I was doing some work on my room and ended up making a mess of it all so its not exactly picture worthy at the minute, but I will get some put up soon.

Anyway, thats enough rambling on for now…

New project…

Being constant tinkerer that I am, I have a new (old) project in the pipelines! Im actually revisiting an older project of mine that fell by the way-side to make room for constant gaming and neglect of wanting to actually do anything. It all started when I ordered some books from a site that I like and actually read them instead of leaving them sitting on my shelf for a change. And so it begins, in an effort to prove to myself that I can read a book and really learn from what it has to say, BuildFunStuff v2 is in the works. The project is going to consist of the following milestone goals…

  • Designing a custom theme for wordpress that is HTML 4.01 Strict compliant.
  • Writing a full, comprehensive legal disclaimer
  • Writing an accessibility statement
  • Writing a number of fun projects you can build at home with minimal tools
  • Integrating wordpress with Google Adsense
  • Integrating wordpress with Twitter
  • Making a few short video’s to advertise the site and its projects

Of course, not all of these milestones are going to be in the order they are listed in here, in fact the disclaimer has been drafted and is awaiting review. Even the accessability statement is a work in progress, of course the statement cant be finalised until the theme is comlete because who knows what type of whacky accessability stuff I’m going to integrate into it. The theme is most likely going to be based off the 160gs CSS system as I think that would be a useful learning exercise. The projects can all be done in the background as Im working on the rest of the bits and pieces, all in all at present, I’d say I have around 10% of the total work drafted… which really means around 0% of it done since its all going to have to be re-visited… but hey, you have to start somewhere dont you?

Anyway, thats enough jibber jabber for now…