Wednesday, January 13, 2010

Communicating with Light

I just discovered something really cool!

I use RobotC and one of the major drawbacks is that the people at RobotC haven’t released a way for the NXT bricks to communicate with more than one brick at a time. So while I am building this big robot with 4 NXTs, I have to come up with a way to communicate between them. My idea was to use a PF LED as the transmitter in a motor port and a Lego light sensor as a receiver on two bricks. As it turns out, this is a very effective way to communicate.

My first thought was that I could turn the light on for 100 ms and the light sensor could read how long it is on and that time length would be the signal. Then I could string together several blinks as a “code.” For example, one signal with three messages may be 100 ms, 250 ms, and 150 ms. My thought was that it takes time for the LED to come on and turn off, plus the light sensor has some lag time too.

But it turns out that the light sensor and the PF LED can be operated faster - MUCH faster. The LED can be turned ON full strength and completely OFF very quickly and the light sensor can read it nearly instantaneously. I am able to consistently send and receive a five digit code that looks like this: {15, 20, 15, 20, 15}. The message that is typically received is something like {16, 21, 16, 22, 16} I have never had a time reading error of more than 3ms! Not bad!  The ON/OFF cycle can't be seen with the naked eye, so all I see from the LED is one short blink that shimmers a little bit.

Each blink is separated by a 15 ms “off” time, so the total send time is 145 ms. So it’s not nearly as fast as Bluetooth, but it’s not far off. Plus I sent 5 messages in that time period.

1 comment:

  1. I hadn't thought of trying to send signals in quite that manner, but I do use a similar system for my robot band project (which still isn't YouTube ready, I'm afraid...)

    My RCX's can't easily communicate with NXT's without external additions - most people using both apparently use an IR adapter for their NXT's. I've been using lights at various intervals in my experiments - a flash of light when the program turns on, when the music changes to a different section, or for beats when time needs to be kept synchronized more precisely between devices. Light sensors on all platforms pick it up just fine, and there's no need to deal with IR or bluetooth. The big advantage for me is that I'm not needing to buy any new equipment and I can actually put more of the old equipment to use (before this, I can't remember the last time I wanted to use an RCX light sensor...)