Welcome to Pete Brown's 10rem.net

First time here? If you are a developer or are interested in Microsoft tools and technology, please consider subscribing to the latest posts.

You may also be interested in my blog archives, the articles section, or some of my lab projects such as the C64 emulator written in Silverlight.

(hide this)

The Win7 Sensor and Location API Part 1: Introduction and Freescale Board Setup and Testing

Pete Brown - 29 October 2009

I’ve always been interested in ways that your PC can reach outside itself and interact with things in the world. That’s what fueled my interest in CNC, as well as things like Lego robotics, and the new sensor and location API.

When I was in Redmond for my first week, I sought out Gavin Gear and Dino Natucci, and chatted about the Sensors and Location platform. I saw some really cool stuff there, some of which I can talk about :)

Gavin also hooked me up with a couple Freescale sensor boards. If you don’t yet have one, they are available for order for a pretty reasonable price. As Windows 7 is still new (at the time of this writing, it has only been released for six days), you won’t find too many sensors out there yet, but this board and the API will allow you to try things out in the meantime. The location API has some companies on board and producing product already. I’ll cover that in a future post.

Sensor and Location Platform

The Windows 7 Sensor and Location platform is something completely new to Windows. It’s a framework helps eliminate the old com (or *gasp* parallel) port programming model that we’ve used for communicating with sensors in the past. It provides standards for drivers as well as a set of APIs for Sensor and Location (specialized and common sensors), and a control panel app to handle access to the sensors.

image

(image source MSDN)

The Sensor and Location APIs are COM-based APIs usable from native code, scripting languages, and anything which can talk COM. To use them from .NET code, you’ll want to use the friendly interop classes which we’ll cover in a future post.

Install the SDK

Install the Sensor Developer Kit for Windows 7. I simply unpacked the zip into a subfolder of Program Files on my machine.

Install the Sensor Diagnostic Tool. The tool comes in Visual Studio project source format, so I put that in my projects folder. It converted for use with VS2010 just fine.

We’ll cover .NET programming APIs in the next post on this topic.

Don’t have the board, get the Virtual Light Sensor from the Windows SDK.

Install the Drivers

Once you have the SDK downloaded and unpacked somewhere on your machine, open the folder and find SensorKitDriverInstaller.exe

image

Run that installer, following the directions to connect the board to the computer. Then turn the board on. You should get the two flashing lights. If you do not, you may need to update the firmware.

Configure and Test the Board

For the examples below, I’m using the 32 bit version of Windows 7. The Sensor DK includes drivers for both 32 and 64 bit versions of Windows 7.

Connect the Board

With the board switched “off” connect it to a USB port on your PC. I have a mini-usb plug always connected that I use for my camera, gps, phone, and now this board. I love standard connections. That said, the board will be easier to control if you pick a really cheap USB cable with thin wire and no ferrite toroid.

Update the Firmware

I did not need to update the firmware on the Rev D board I received, it may have been updated in a past life. If you do need to, the directions are included in the README in the SDK. It’s pretty much just a file copy like you would do with any USB stick.

Enable the Board

It took me a couple times before I remembered I had to do this. In control panel, you’ll see the applet for Location and Sensors. You want the “Enable location and other sensors” item

image

image 

You can also control security on a per-user basis using that applet, but we’ll skip that for this.

Test the Board

Once you go through those steps, you’ll want to test the board to make sure everything is working. The compiled version and C++ source code for the test application are included in the SDK. The read-to-run binaries are in Tools\DiagnosticTool\Binaries

image

That’s fun for about 2 minutes, about the amount of time it takes you to verify that everything is working. Let’s really test it with something more interesting.

Testing the Board Take 2

Let’s test using Xna.

You’ll need:

Once you install the first two, go into VS2008 (the templates don’t install under 2010 unless you manually move them) and create a new XNA racing game starter kit project

image

Inside the racing game zip file from msdn, you’ll see a Word document with instructions on how to modify the racing game starter kit project for use with the sensor API. You’ll be replacing a few files and recompiling the sample.

Now run it and try out the accelerometer!

So…..

Nothing happened, right? Well, the sky responded to the light sensor, but the accelerometer did pretty much nothing.

I ran into the same problem. Luckily, I found a person who had blazed this trail before me: Pietro Brambati. He had a few tweaks to the source code to make the accelerometer work. Scroll down to section 4 (XNA) and you’ll see some code you’ll need to add. FWIW, he also has a great write-up on the rest of the board install process. I encourage you to check it out.

Changes to the Source to Support Motion

Add to CarPhysics.cs Update() method

if (Input.IsAccelerometerConnected)
{
    rotationChange -= effectiveSensitivity * 
        (Input.AccelerometerAxisX_Force / 3.0f) * 
        MaxRotationPerSec * moveFactor;
}

 

Then to the same method, down in the “Handle Speed” section add

else if (Input.IsAccelerometerConnected)
{
    if (Input.AccelerometerAxisY_Force > 0)
        newAccelerationForce += maxAccelerationPerSec;
    else
        newAccelerationForce -= maxAccelerationPerSec;
}

Finally, in the Graphics\BaseGame class add this code right below Sound.Initialize();

Input.Initialize();

Run the App

NOW run it, and it should behave as you would expect.

image

From the video I recorded (link to be posted shortly) you’ll see I am a horrible driver. I’m thinking I should stick to Pole Position on the C64 :)

image

Uses for Sensors

Just considering the sensors available on the Freescale board, I can think of a few ways you could use them in your own applications or hardware:

  • Adjust application theme (contrast, colors, font size) based on ambient light. For example, if you’re out in the full sun, you may want to bump up the UI size and increase the contrast. This would be great for field applications, especially on tablets. In fact, here’s a great whitepaper on that very topic.
  • Accelerometer based games: use your whole laptop/notebook/tablet as a controller, or have an external device you hold, like the video I did along with this posting.
  • A friend of mine in DPE suggested controlling music based on the light level in the room. (Presumably if the lights go out, it’s Barry White time <g>)
  • I’d be curious to see if you could hang this on your car dash and get larger-scale acceleration readings. Worth trying out, but probably don’t want to tell your SO about this one.
  • Accelerometers are crucial in laptops that still use the soon-to-be-outdated spinning platter form or storage. If you can park the heads before the crunch, your data will have a better chance of staying safe.
  • Of course, environmental sensors (temperature, , pressure, humidity, etc.) have a ton of uses from IT to museums to portable weather stations.

I’ll have the video walkthrough of this and the test apps up shortly. For grins, here’s the setup I used to record the board:

image

Dig that high-tech camera stand :)

The XNA game I recorded with a Canon HD camera on a tripod to my right.

Update 11/25/2009 The video is located here.

       
posted by Pete Brown on Thursday, October 29, 2009
filed under:        

9 comments for “The Win7 Sensor and Location API Part 1: Introduction and Freescale Board Setup and Testing”

  1. Ansonsays:
    Sir,
    I am working the Sensor platform driver. And it works.
    But I have a question about the "install"!
    I can use SensorKitDriverInstaller.exe to install my sensor driver.
    But when I write my inf to install it, it always can not install success.
    Would you give me any suggestion or idea about " What SensorKitDriverInstaller.exe do ?"

    Thanks very much,
    Anson
  2. JafeasekHashysays:
    Greatings all people,

    Very first apologise if this is not the exact category. Please transfer it if necessary. I'd like to ask all of you Folks if you ever tried expire domain search resources and if yes could you share some very good tools to seek out expire domains and backorder it.

    The best application would get the job done like that: browsing domains by Pagerank, Alexa rank, targeted visitors values and date to run out. It could fetch final results from google or other search engine.

    At the moment I'm utilizing [url=http://www.expirednamesniper.com]Expired Domain Name[/url] website and it operates really wonderful but I need a lot more sources like that. Please post on this thread or drop me a pm if you own any software program but do not like to share in public.
  3. Eugeneelsays:
    Наконец-то мне удалось взломать последнюю версию Хрумера 12.0.8. Можете скачать и пользоваться все кто хочет: http://turbobit.net/s7dk9cvafdmn.html Или можете заказать готовый прогон тут: http://betgame.ru/index/progon_khrumerom/0-181
  4. LurryGefesays:
    Hi, visit my cool sites please
    [url=rckakpkmuom.freevar.com]rckakpkmuom.freevar.com[/url]
    [url=eiljrxbpjh.noads.biz]eiljrxbpjh.noads.biz[/url]
    [url=zaqhdrggj.coolpage.biz]zaqhdrggj.coolpage.biz[/url]
    [url=pbzccmvm.coolpage.biz]pbzccmvm.coolpage.biz[/url]
    [url=vbvbjwk.6te.net]vbvbjwk.6te.net[/url]

Comment on this Post

Remember me

4 trackbacks for “The Win7 Sensor and Location API Part 1: Introduction and Freescale Board Setup and Testing”

  1. progg.rusays:
    Thank you for submitting this cool story - Trackback from progg.ru
  2. POKE 53280,0: Pete Brown's Blogsays:
    This is part 2 of a series. If you don’t yet have the Freescale board configured and tested with Windows
  3. Windows Client Newssays:
    Windows 7 introduces the Sensor and Location API which enables access to all sorts of cool things like
  4. POKE 53280,0: Pete Brown's Blogsays:
    Windows 7 introduced the Sensor and Location API. I’ve previously blogged about the sensor API, but couldn’t