Beam me up: Directional laser with Windows Phone and Netduino

TwitterFacebookRedditGoogle+EmailPinterest

Before leaving for Finland I setup this little project, but didn’t have time to finish (see what I did there?) it. Now that I’m back, between writing my Netduino book, I sometimes have time to play!

In the video, I drew shapes in the playback mode, and then recorded them being played. I used After Effects to make a time-lapse to see that it does in fact draw the shapes. The overall shapes are bad because my drawing’s were terrible, and the little angles are because the servos are cheap, and should be much better.

At our local “china-mall” I found one of those old laser pointers (with all the different lenses) going for about $0.5. I also still had the servos from the maze project setup. So what does this make? An electronically directed laser beam of course!

The objective was to make a multi-direction laser pointer positioned by 2 servos 90 degrees to each other, connected to a Netduino, and controlled from a Windows Phone over Bluetooth. Bonus points for a cool video.

What you need:

  • Netduino
  • 2 servos – the more accurate the better
  • 330 ohm resistor
  • 4.8v battery pack
  • Bluetooth module
  • Laser pointer
  • P2N2222A transistor

Mechanism:

This works pretty much exactly like the maze. You have two servos connected together but at right angles to each other, and then the laser is connected to one of them. This gives you X and Y movement.

The image above is straight from the maze post, and the laser is placed where the white bracket is.

 

Netduino:

The electronics are pretty simple. Two servos are connected up to the Netduino with a separate battery pack (with the grounds tied). and then the laser is powered directly off the 3.3V pin, and can be turned on and off from the Netduino because with the NPN transistor.

board_bb

In the diagram above, I’ve used an LED to represent the laser.

I won’t go into detail about getting Bluetooth hooked up – go back to this post to see how to do that.

Above the Main method we need to create some class variables:

And then inside the Main method we initialize them:

Notice that the laser is controlled by switching digital pin 11 high and low. To control the servos I used a nice little class by Chris Seto.

The final part of the Netduino code is to make stuff happen when the phone sends various messages through. Each message will either be an “off”/”on” command which should turn the laser off or on, or an X and Y value (comma separated) to move the servos.

So here is the code that takes care of the messages that the BT module receives (check source for rest of BT code):

 

And that’s all for the Netduino!

Windows Phone:

The Windows Phone app has two functions; “Live” mode where you move your finger on the screen and the laser will move around in real-time, and “playback” mode when you can first draw something, then hit the play button in the AppBar to playback.

wp_ss_20130506_0001

The UI consists of two radio buttons, a really jarring red InkPresenter (I made it so bright to show up nicely on the video), and an AppBar with a play button. The AppBar will only appear when playback is selected.

Input is gained through the InkPresenter which is a very easy control to draw lines onto, and has the standard UIElement touch events. To track movement we listen to three events: MouseLeftButtonDown, MouseLeftButtonUp, and MouseMove. [Yes, your finger is a mouse due to legacy SL stuff]. When the finger goes down we start tracking it, and capture it’s movements to the InkPresenter (no other control will get touch events even if the finger moves off the element), and release the capture when the finger leaves. Each movement fires the Move event, so we record the new position and add the point as a StylusPoint to a stroke (to display the line in playback mode).

If live mode is selected then instead of recording the strokes, we just send the position to the Netduino.

In playback mode, when the user hits the play button, we loop through all the previously recorded strokes, and their StylusPoints and send each one to the Netduino. Because each stroke was done as a separate movement (they lifted their finger), when moving onto the next stroke we need to instruct the laser to turn off > move to the start of the next stroke > wait a bit > turn the laser back on. All of this is done in a DispatcherTimer.

The formatting of the positions before sending is done in this method:

First we divide by 10 (to scale the movement down), and then minus 24 because we want the full swing of the servos to be 48 degrees, and the center being 0.

And that’s it! Download the source below to see the code that wasn’t discussed here, or if you’re confused.

WP + Netduino Source code: Click Me

If you’ve got question you can ask me here or on the Twitter machine: @roguecode

TwitterFacebookRedditGoogle+EmailPinterest
  • http://gordonbeeming.azurewebsites.net/ Gordon Beeming

    This is epic, reminds me of the MS Muscle car :)

  • http://netduinoblog.wordpress.com/ Tobias Vandenbempt

    Tech is like SpectraBeat: http://spectrabeat.com/ But love the thought of building and programming it myself! :) It’s on my To Do List.