Controlling keyboard leds

I have just finished reading Cryptonomicon , without any spoilers I can say that at a certain point a character controls the led's on his keyboard. This morning I found the kbdled utility via a forum post. It looks like a nice simple way to make the keyboard do something useful.

Using portmaster to bulk install ports

As I write this there are not any packages available for FreeBSD arm. That means on the Raspberry Pi I have to build the things I need from ports. Ports gives a lot of control about how the software is built, but right now I just want the tools I need installed.

It is hard to set up ports to install a collection of tools in a oner, but we can use portmaster to do this for us. The Pi is quite slow and will take a long time to build a small number of tools and their dependencies.

Normally portmaster will prompt for configuration for each package as it builds, it will then build a list of packages and prompt again to install these. The following line will install the listed tools without any prompting.

$ portmaster -mBATCH=yes --no-confirm -y sysutils/tmux editors/vim
  • The -m flag will pass options to make
  • --no-confirm will disable the 'install' prompt
  • -y will answer yes to any prompts

Reading analog values on the msp430

I finally got all the components to use the bag of electret microphones I got last year. Using a LM36 audio amp I set up a simple circuit to read values from the microphone and set LED's corresponding to the value read.

I had trouble finding a solid example of doing analog reads in a loop for the msp430. This program, sets up LED's(On P1.1 and P1.6), sets up the ADC, then sits in a loop. If the value on the ADC is grater than 512 the LED will go red.

I tested this by shouting at the micro controller, something I have done many times before, but never with such satisfying results.

#include <msp430g2553.h>

unsigned int adcvalue = 0;

void configureADC(void);

int
main(void)
{
    WDTCTL = WDTPW + WDTHOLD;       //Stop the Watch dog

    P1DIR |= 0x41;                  //Enabled P1.0 and P1.6
    P1OUT = 0x41;

    BCSCTL1 = CALBC1_1MHZ;          //Set range
    BCSCTL2 &= CALBC1_1MHZ;         //SMCLK = DCO = 1MHz

    P1SEL |= BIT3;

    configureADC();
    __enable_interrupt();

    while(1) {
        __delay_cycles(20000);
        ADC10CTL0 |= ENC + ADC10SC;         //Sampling and conversion start
        adcvalue = ADC10MEM;                //Read from the ADC

        if(adcvalue > 512)
            P1OUT = 0x40;
        else
            P1OUT = 0x01;

    }

    return 0;
}

void
configureADC(void)
{
    ADC10CTL1 = INCH_3 + ADC10DIV_3;
    ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE;
    ADC10AE0 |= BIT3;
}

Attaching a debugger to mspdebug

The cool thing we get with the msp430 and the Launchpad is on chip debugging. This goes a long way to pave over the warts of writing straight C for the 430. We will load up the blink program from last time , run it with the debugger and pause execution.

Start up mspdebug as before, this time we pass a command for mspdebug to run directly. The "gdb" command will cause mspdebug to listen on port 2000, gdb can then connect and control the debugger.

$ mspdebug rf2500 "gdb"

Next we are going to start up msp430-gdb, load the program from before and start it running.

$ msp430-gdb
(gdb) target remote localhost:2000
(gdb) file led.elf
(gdb) load led.elf
(gdb) continue
^C
(gdb) break main.c:14
(gdb) c                 #We can shorthand commands
Now between each continue we will see the LED's toggle, red then green.
(gdb) continue

From gdb we can send mspdebug directly with the monitor command.

Tech seen debugging bus sign

In Aberdeen we have digital displays mounted in most of the bus stops, in fact most major cities in the world probably have similar signs. The signs get their data via radio broadcasts, these broadcasts have in fact been captured before and reverse engineered.

For a long time I have been thinking about doing a similar thing and figuring out the bus information that is in the air. I am sure I will get to it one day.

Well this morning as I headed off to work I caught a technician in the act of debugging one of these signs. I grabbed a quick picture of the guy working, but I didn't want to bother him.

It looked like the tech was using a serial cable from his laptop up to the display. The antenna on the bus shelter looked much larger than the normal ones.