MindField

This weekend April 29th to May 1st I’ll be helping to run a hardware hacking area in the Hackerspace Tent at MindField – International Festival of Ideas. Taking place inside Merron Square park in Dublin’s city centre MindField offers a diverse programme of talks, debates and workshops covering various topics on culture, technology, politics and inspiration.

Members from Irelands hackerspaces and makerspaces have been invited to build a temporary hackerspace in the park over the weekend. Giving visitors the opportunity to experience the possibilities of hacker and maker culture in Ireland. We’ll be showing off existing projects, teaching new skills through activities and workshops, and working on new projects with visitors and the resources we’re bringing over the weekend.

In MindField Hackerspace I’ll be helping to run a hardware hacking area teaching people to solder repair and re-propose, and giving a free Introduction to Arduino Workshop. I’ll also be talking part in the Hack the Planet! panel discussion on hackerspaces.

In the hardware hacking area I’ll be selling some of my kits including the Mini Mood Light v1, Dual LED Matrix Display and other LED based displays. All along with Arduino Uno’s, TI LanuchPad’s, electroluminescent wire and hundreds of LEDs.

One very special item I’ll have for sale is a basic I Can Solder kit which is in the form of a badge. The I Can Solder badge was inspired by the Electronic Merit Badge from Make:. Which I had the pleasure of using to help teach hundreds of kids and adults to solder during the Maker Faire UK in March in New Castle, England.

Linux development environment for TI LaunchPad

The MSP430 LaunchPad development kit from Texas Instruments is very interesting. It includes a development board, two DIP micro controllers, a Mini USB cable, four headers connectors, a crystal and two stickers. But the most exciting part is that you get all this for $4.30 from TI.

I’ve also been using the LaunchPad to program the MCU in the Mini Mood Light v1 which also uses a MSP420G2211.

To get the LaunchPad working with Linux you need a suitable toolchain (assembler, compiler, library and debugger) and flash programing software. Unfortunately the required software isn’t packaged with current Linux distributions, so we need to compile the software ourselves.

In the past it was a complex task setting up a cross compiler. Having to download individual source archives, finding required patches, providing suitable command line options and all that in a specific order. Today we have the MSPGCC4 project which provides and maintains an interactive script which preforms most of the heavy lifting required. We can also use the MSPDebug tool to program and debug the flash on the LaunchPad.

My preferred distribution is Debian but I hope my description is significantly generic to be useful to other distribution users.

The first step is to install as root the required programs, libraries and dependencies which are required to compile the toolchain. On Debian the following command can be used to install the required packages.

# apt-get --no-install-recommends install bzip2 dialog gcc gcc-4.4 \
gzip libc6-dev libncurses5-dev libreadline6-dev libusb-dev \
make patch tar texinfo wget zlib1g-dev

If you want to use the graphical interface to gdb call Insight, also install the X windows libraries. The libx11-dev package on Debian.

My preference is to install and run toolchains inside a sub directory of my home directory, which also allows for easier backups and upgrades in the future.

~$ cd ~
~$ mkdir msp430
~$ cd msp430
~/msp430$ wget http://downloads.sourceforge.net/project/mspgcc4/mspgcc4/mspgcc4-20101114.tar.bz2
~/msp430$ tar jxf mspgcc4-20101114.tar.bz2
~/msp430$ cd mspgcc4-20101114
~/msp430/mspgcc4-20101114$ perl buildgcc.pl

We now need to answer some questions about what versions of tools we will include in our toolchain.

Select GCC version to build: gcc-4.4.5
Select GDB version to build: gdb-7.1
Select Insight version to build: none
Select libc version to build: ti_20101114
Strip debug information from executables after install? Yes
Enter target toolchain path [HOME]/msp430/toolchain (Replace [HOME] with the full path of your home directory i.e. /home/robert)
Create binary package after build? No
Do you want to start build right now? Yes

The build script will now download, configure and compile the required source packages which might take some time depending on the speed of you internet connection and computer.

Once the script as finish you can save some space by deleting the build directory.

~/msp430/mspgcc4-20101114$ rm -rf build
~/msp430/mspgcc4-20101114$ cd ..

Now we’ll install the flash programmer.

~/msp430$ wget http://downloads.sourceforge.net/project/mspdebug/mspdebug-0.13.tar.gz
~/msp430$ tar zxf mspdebug-0.13.tar.gz
~/msp430$ cd mspdebug-0.13
~/msp430/mspdebug-0.13$ make PREFIX=[HOME]/msp430/toolchain all install
~/msp430/mspdebug-0.13$ cd ..

So that we can compile code for the LaunchPad we’ll add the toolchain executables to our path.

~/msp430$ export PATH=$PATH:[HOME]/msp430/toolchain/bin

We can make the toolchain permanently accessible by adding the above export command to our ~/.bashrc startup file.

To test our new toolchain we’ll compile a very simple example program which just blinks the red and green LEDs on the LaunchPad. Save the following as blink.c.

#include "msp430g2231.h"
#include "signal.h"

void main(void) {
        WDTCTL = (WDTPW | WDTHOLD);  // Disable Watchdog timer+

        P1SEL = (0x00);              // Port 1 Select GPIO
        P1DIR |= (BIT6 | BIT0);      // Direction 1.[60] Output
        P1OUT |= (BIT6);

        TACCTL0 = (CCIE);            // Enable interrupt on compare match
        TACCR0 = (0xFFFF);           // Compare value
        TACTL = (TASSEL_2 | MC_1);   // Sub system clock source | Up mode

        _BIS_SR(GIE | CPUOFF);       // General interrupt enable | Turn off CPU
}

interrupt(TIMERA0_VECTOR) TIMER_A0(void) {
        P1OUT ^= (BIT6 | BIT0);
}

To compile the code you can use the following command.

~/msp430$ msp430-gcc -g -mmcu=msp430x2231 -o blink.elf blink.c

To flash the MCU we can use the following command as root.

# [HOME]/msp430/toolchain/bin/mspdebug rf2500 "prog [HOME]/msp430/blink.elf"

If the programming is successful the red and green LEDs should now rapidly turn on and off.

Introducing the Mini Mood Light v1

Over the coming months I will use this site to try and document some of my previous electronics projects, as well as covering my future work and activities.  Kicking things off I’ll introduce the Mini Mood Light v1 kit.

Most of my recent projects have involved light emitting diodes (LEDs), you could possibly go as far as saying I’m obsessed. Some of my recent projects required hundreds and thousands of LEDs.

For the beginner working with a standard LED is relatively simple. It just requires a LED, a voltage source (battery) and a resistor with the correct value (ohms law is your friend). Working with a Tricolour or RGB (Red, Green and Blue) LED is a bit more complicated.

To achieve the larger range of possible colours with a RGB LED you can use pulse-width modulation (PWM). PWM is used to control the intensity of the LED by rapidly turning it on and off and by varying the amount of time that the LED is on or off. With a RGB LED the human eyes and brain are able to combine the different intensity of the individual red, green and blue LEDs into a particular colour.

The Mini Mood Light v1 provides a simple way for you to experiment and learn about working with RGB LEDs. The circuit combines two independent RGB LEDs, four buttons and a micro controller (MCU) on a small circuit board.

The Mini Mood Light v1 uses a MSP430G2211 MCU from Texas Instruments (TI). This MCU doesn’t contain any PWM hardware, but it’s relatively straight forward to implement PWM functionality in code using a loop and a comparison. The following fragment of C gives a very simple implementation.

int pwm = 128;
while (1) {
    enable_led();
    for (int i = 0; i < 256; i++) {
        if (i == pwm) {
            disable_led();
        }
    }
}

The combined pins of the MCU have a maximum source or sink current of 48 milliamperes. Reasonable luminous intensity for a typical LED is achieved at about 20 milliamperes. Which for the six LEDs in the Mini Mood Light that make up two RGB LEDs would exceed the maximum current rating of the MCU. To overcome this a Darlington transistor array (ULN2003A) is used as a switch to control the LEDs. With a suitable resistor setting the current for each LED to 20 milliamperes.

Four tactile buttons are connected directly to the MCU and can be sampled and debouched by polling or using a timer interrupt within the MCU. A 3.3 volt low dropout linear regulator (MCP1702), reverse polarity protection diode and a number of decoupling capacitors round out the circuit.

The Mini Mood Light v1 kit is being used as a hands on activity during a set of electronics workshops I’m giving in the TOG Hackerspace in Dublin. The workshops called Building it! are part of their Science Week 2010 and Innovation Dublin Festival 2010 activities.