topamax once a day

Android + IOIO + Servo Control

  

A simple dual servo controller for Android.  The IOIO based device uses slider bars to control two hobby servos.

For additional background information on interfacing Android with IOIO, check out my other introductory tutorials:

Android + IOIO + Simple Digital Output
Android + IOIO + Simple Digital Input
Android + IOIO + Simple Analog Output
Android + IOIO + Simple Analog Input

Background on Android development, IOIO, and electronics:

Meet IOIO
IOIO for Android Beginners Guide
IOIO Wiki
Android Developer’s Guide

 

Hardware

Parts needed:

  • Android Device (1.6+, 2.1 for Bluetooth)
  • IOIO (available at Sparkfun)
  • 2x Hobby servos
  • 2x 10k ohm resistors
  • Breadboard
  • Power supply
  • Hook-up wire

 

Assembly

Connect the red, power lines of the servos to +5v, the black ground lines to GND, and the yellow signal lines to the desired output pins, 3 and 6 in the example.  Other pins can be used as long as they support peripheral output (for PWM, marked with the letter ‘p’ on the back of the IOIO) AND are 5V tolerant (marked with a black circle around the pin). This leaves pins 3-7, and 10-14 as the only potentials.  Also, connect the same signal lines to +5V, with a 10k ohm resistor in series.  This allows use of the pins in 5V open drain mode, required since the IOIO operates with 3.3V.  Here is a diagram of the completed circuit (created with Fritzing):

 

Software

Get the source

With the circuit assembled, the next step is to get the demo application on the Android device. You can either download the pre-built .apk or checkout the source from Github:

git clone git://github.com/mitchtech/android_ioio_servo_control.git

If you are building from source, you will also need to import the IOIO Library project, and optionally the IOIO Bluetooth library projects, both available here:

git clone git://github.com/ytai/ioio.git

 

Install, connect, profit!

Finally, upload the app to the Android device (or browse to this page on the device and download the apk above). Connect the device to the IOIO, and start up the app.

 

15 Comments

  1. i couldn’t slide using the seekbar in sync with the servo help pls!

    • civicexa

      I have the same problem,..:(

      • Looks like there was a problem in my code. The circuit was wired for open drain mode, but was not enabled in the code. In ServoControlActivity.java:

        panPwmOutput = ioio_.openPwmOutput(PAN_PIN, PWM_FREQ);
        tiltPwmOutput = ioio_.openPwmOutput(TILT_PIN, PWM_FREQ);

        needed to be:

        panPwmOutput = ioio_.openPwmOutput(new DigitalOutput.Spec(PAN_PIN, Mode.OPEN_DRAIN), PWM_FREQ);
        tiltPwmOutput = ioio_.openPwmOutput(new DigitalOutput.Spec(TILT_PIN, Mode.OPEN_DRAIN), PWM_FREQ);

        I have updated the code in the Github repo to reflect the necessary changes.

        • Hi Michael,
          I love everything You’ve posted! I have a question – is the pre-built .apk fixed from this problem, and if it is, why do I experience it on my galaxy 3?
          Thank You!
          Nick

        • hi
          i still got the problem in this line
          here the log

          Description Resource Path Location Type
          The method openPwmOutput(DigitalOutput.Spec, int) in the type IOIO is not applicable for the arguments (Spec, int) ServoControlActivity.java /IOIOServoControl/src/net/mitchtech/ioio line 36 Java Problem

          Description Resource Path Location Type
          The method openPwmOutput(DigitalOutput.Spec, int) in the type IOIO is not applicable for the arguments (Spec, int) ServoControlActivity.java /IOIOServoControl/src/net/mitchtech/ioio line 37 Java Problem

  2. Neil Gibbons

    Really nice tutorial. As a beginner I’m sorry to bother you with such an obvious question but I was wondering how one could modify the above example to control a dc motor (I think that is what you need for controlling remote controlled cars etc.).

    Loving the website,

    Neil

    • Hi Neil, the code might not actually need to be modified… you can vary the duty cycle of PWM signals to control the speed of DC motors too! However, it is recommended not to directly connect the IOIO to motors, but to use a motor driver breakout board in between. Here is example using a: TB6612FNG Dual Motor Driver

  3. Can you explain further why the single outputs need to operate in ’5v open drain mode’?

  4. what should i do..
    its deprecated and it doesn’t recognize AbstractIOIOActivity

  5. I second the depreciation of the AbstracIOIOActivity as it causes the app to now force close when I try to build via Eclipse.

  6. I seem to have problems related to ioio library linking.

    DigitalOutput cannot be resolved to a type
    Mode cannot be resolved to a variable
    ServoControlActivity.java
    Java Problem

    On project import > I re-linked ioioLib as ioioLibAndroid because ioioLib is no longer listed that way. Should that work?

    also: I copied the github project to my workspace manually and impored with “copy to workspace” UN-checked to avoid directory structure corruption in ioioLibAndroid. https://github.com/ytai/ioio/wiki/Eclipse-Troubleshooting#corrupt-directory-structure-for-ioiolibandroid

    Am I off base, or no where near the ballpark?

    thanks
    keith

  7. Hey there! Thanks a ton for the tutorial :)

    tI’d just like to ask, looks like you used a dongle to connect to the IOIO wirelessly. What dongle did you use? Bluetooth?

    Did it require anything special to setup?

  8. Hi,
    Is the apk built for Android or Google API? And what level?
    Thanks.

  9. how can we turn right or left a servo as simple?

  10. Where i can buy

Leave a Reply