If you are interested in robotics and automatic control, then you probably know the www.robot-electronics.co.uk site where you can purchase lot’s of good devices for your robots. Company with name Devantech offers sensors, servo drivers, motor controllers and other fine circuits. Most of these devices are connected to I2C bus which has good support in .NET Micro Framework.

Ready to serve

While I’am working on my .NET Micro Framework powered robot, I wrote class libraries to implement functionality of some of the Devantech devices. I’ve tried to implement best practicies and design patterns, so all sonars implements ISonar interface as well as all I2C devices that’s support address change, implements IChangableAddress. Ranging distance with popular SRF02 ultrasonic range finder is as easy as this:

using(SRF02Sonar sonar = new SRF02Sonar(0x70))
    // Range distance in centimeters
    int distance = GetRange(SonarRangeUnits.Centimeters);

To operate HS 311 servos in extended mode with SD20 servo driver you need a few lines of code

using (SD20ServoDriver SD20 = new SD20ServoDriver())
    // Set servo to operate from 0 to 180 degrees (HS 311)
    SD20.SetExtendedMode(530, 1920);
    // Set servo to the highest position
    SD20.SetServo(1, 250);

To this day I’ve implemented functionality for the following devices

  • SRF02 Ultrasonic Ranger
  • SRF05 Ultrasonic Ranger
  • CMPS03 Compass Module
  • SD20 Servo Driver

I2C easier

I2C communication is usual source of confusion for the beginners. The way that .NET Micro Framework implements I2</supC is powerful but a bit hard to handle. Driver project contains class I2CSlave which implements I2</supC communication in way that is usual for most devices. It means register reading and writing. See how easy it is.

// Device on address 0x70 = 0xE1 in 8 bit
using (I2CSlave slave = new I2CSlave(0x70))
    // Write value '120' to register '1'
    slave.WriteRegister(1, 120);
    byte[] dataBuffer = new byte[2];
    // Read from register '5'
    slave.ReadRegister(5, dataBuffer);
    // Turn byte array into value
    int registerValue = Endianity.GetValue(dataBuffer, ByteOrder.BigEndian);

Where to download?

I’ve setup web page for this mini-project. At this address http://bansky.net/devantech/ https://github.com/pavelbansky/microframework/tree/master/devantech you can download source project for Visual Studio 2005 and documentation in Visual Studio style. Happy roboting!