Sample code for interfacing with the OpenServo

Dimax U2C

Interface code in Java Interface code in Ruby Interface code in C++ Interface code in C

Linux /dev/i2c

Communication with the I2C interface is very simple, as it is handled as a file for reading writing.

Simple method to confirm the OpenServo works.

//c code here

Basic Stamp

The Basic Stamp 12p is one of the easier stamps to interface with. It has Hardware I2C support built in, and can control an OpenServo very easily.

simple example

complex example

Windows & Linux parallel port interface

Windows:- hihihi interface code Linux:- as above

AVR Host controller

example using procyon AVR lib

Using the Arduine

Here's some code that I use to control openservos (pan and tilt) (provided by ahoeben Code:

{{{#include <Wire.h>

// OpenServo registers & commands #define OPENSERVO_POSITION 0x08 #define OPENSERVO_SEEK 0x10


// servo i2c addresses #define SERVO_ADDRESS 0x20

void _openservo_write16(int i2c, byte reg, int data) {


unsigned int _openservo_read16(int i2c, byte reg) {


void _openservo_command8(int i2c, byte reg) {


void _openservo_begin(int i2c, byte reg) {

} }}}

To move a servo to a position: Code: _openservo_write16(SERVO_ADDRESS, OPENSERVO_SEEK, value);

To get the current position: Code: unsigned int value = _openservo_read16(SERVO_ADDRESS, OPENSERVO_POSITION);

To disable PWM: Code: _openservo_command8(SERVO_ADDRESS, OPENSERVO_PWM_DISABLE);


Microchip PIC

PicBasic PicC asm

DocSampleCode (last edited 2012-10-12 19:51:18 by localhost)