loading
Picture of Android G1 Serial To Arduino Robot
2010-01-24 00.05.09.jpg
2010-01-24 22.12.00.jpg
2010-01-24 22.11.48.jpg
2010-01-24 22.13.01.jpg
2010-01-24 22.15.10.jpg
Learn how your Android cell phone can control a robot using an Arduino board. The phone takes commands via telnet from another phone or a PC, so you can control the robot remotely. This project will not otherwise modify the G1 so you can continue using it as your normal phone after undocking it.

Why?
By using cheap electronic components such as Arduino boards, you can pair them with your $400 phone to make an awesome robot. It would cost hundreds of dollars to add GPS, LCD's, motion sensors, wi-fi, cellular connections, speakers, and more to a hobby bot, but your phone already has these!




Together, the Android G1 and Arduino board allow you to use inexpensive electronics such as simple servos and sensors, to build powerful devices such as robots, remote telepresence, or fun toys for kids. More information at Cellbots.com.

Notice: This project currently requires an Android G1 with root access to use serial output from the phone to the Arduino robot. You can add a $20 BlueTooth module to your Arduino board to have the phone talk to it over serial BlueTooth if you want to use the commercial Android software.

Special thanks: We have the Hacker Dojo in Mountain View, CA to thank for putting us in touch, helping with some tricky issues via their mailing list of awesome members, and for having 74LS04 chips in stock. Most of the assembly was done at the Tech Shop in Menlo Park.
 
Remove these adsRemove these ads by Signing Up

Step 1: Items needed

 To complete this tutorial you will need the following:

Hardware:
- Android G1 Dev Phone (or other Android device with root access and serial output)
- Arduino (I'm using a Freeduino SB but any one should do)
- 3.3v to 5v converter if you aren't using a 3.3v Arduino (I'm using a 74LS04 chip for under $1 but other options are available)
- HTC USB break-out board for the G1
- Soldering equipment for two quick connections
- A robot body with micro servos (cardboard, acrylic, treads, wheels, anything will do)

Software:
- Android Scripting Environment (ASE)
- Telnet client for your PC (I'm using PuTTY on Windows)
- Arduino development environment
- (optional) Serial client for your PC (I'm also using PuTTY on Windows for this)
- (optional) Android SDK

If you can follow instructions you can complete this tutorial with little knowledge of Python, Arduino, Android, or electronics. You'll want to know those things if you want to go beyond a blinking LED but this will get you started.

Step 2: Android G1 with serial output enabled

Picture of Android G1 with serial output enabled
cyanogenlogo.png
ttyMSM2.jpg
G1's do not ship with the ability to send serial commands out of the USB port and there is no native option to enable it. If you are an advanced Android SDK user you could make your own build but I chose to use the Cyanogenmod 4.2.13. If you know of other Android devices with serial out working, add them to the comments.

Optionally, you can follow the links there to this instructable on talking to your G1 over USB from your PC. That serial to USB connection isn't required for this tutorial but I used it as a nice sanity check to verify the phone was sending serial out.

If you don't use the other intructable to verify serial output is working, you can try this simple check:
1. Open the Terminal app on the G1 (comes with Cyanogen but download one from the Market if you have a different image)
2. Navigate to the /dev/ directory by typing in cd /dev/
3. Type ls (that's an L) and look for ttyMSM2 in the list returned

The Python script we'll use later sends commands to '/dev/ttyMSM2' in order for them to go out the serial connection. Since that requires root access, you'll need to change permissions on that every time you reboot the phone. To do that:

1. Open the terminal app on the phone
2. Enter 'chmod 777 /dev/ttyMSM2'

Then you can run the Python script from the Android Scripting edit in the next step and it will have access to send serial output.

Step 3: Install the Android Scripting Environment (ASE) with Python

Picture of Install the Android Scripting Environment (ASE) with Python
qrcode to ASE.png
The scripts we'll be using to create an open socket connection on the phone and send commands out is written in Python. To run this on the G1 we'll need the Android Scripting Environment. If you don't see it in the Market you can download it by scanning the barcode on that page which links to the apk file on this page.

Once you install and run ASE you will want to add on the Python module from the menu:
1. Open ASE and make sure you have a working internet connection (wi-fi or 3G)
2. Press the menu button on the phone and select Interpreters
3. Press menu again and select Add
4. Select Python (currently v2.6.2 as of writing this) and it will download some zip files

You may want to explore creating, opening, editing, and running scripts to become familiar with Python via ASE but it isn't required.

Step 4: Copy and run the cellbot.py script to launch the Python program

Picture of Copy and run the cellbot.py script to launch the Python program
This tutorial uses a Python script to be the "brains" of the robot. Get the latest code from our open source Google Code project. You only need the cellbot.py file but others may help with various things you want to explore. I simply plugged the phone into my PC's USB connection and mounted the drive before copying the file to /sdcard/ase/scripts.

The program creates an open socket connection to accept an incoming telnet session. It also prints the received commands to the screen while sending them out the serial port. Put this file on the phone's SD card in the /ase/scripts/ directory.

Detailed steps to load and run the scripts:
1. Copy the cellbot.py script to the SD card's /ase/scripts/ directory
2. Be sure to dismount the SD card from your PC if you copied them that way since the phone can't access the files at the same time your PC is.
3. Open the Android Scripting Environment app
4. Click on cellbot.py to launch it

You should see a confirmation that the device is ready at this point to accept incoming telnet sessions on port 9002.

Tip: Be sure to run the "chmod 777 /dev/ttyMSM2" command from step #3 first. See step #5 for finding the phone's IP address.

Step 5: Telnet into the G1 and test sending it commands

Picture of Telnet into the G1 and test sending it commands
receiving commands over telnet.png
PuTTY telnet commands.jpg
The phone should be ready for you to telnet into it and send it commands from your PC. It will print them to the phone's screen to confirm what it receives. I used PuTTY on Windows but we've confirmed that minicom works great on Macs as described in this instructable.

You will first need to find your phone's IP address. This is available by going to Menu > Settings > Wireless controls > Wi-Fi settings and then pressing the currently active connection. A pop-up toast message will come up with the current IP address on the local network. Write this down as you'll use this every time you want to open a telnet session from your PC. IP assignments typically expire after a certain number of days so you may need to check this again.

Note: This tutorial assumes your PC and phone are on the same local network. Routing to the phone from outside of the local network should be possible but is not covered here.

Open your telnet client of choice and connect to the IP of the phone on port 9002. From a command line you do this as "telnet 192.168.1.1 9002" using the actual IP of the phone. Type in some characters and hit enter to see them show up on the phone's screen. You can type a q to cause the Python script to quit, which should close your terminal session.

If for any reason you can't connect via telnet and need to kill the program, a simple reboot of the phone should do the trick. Advanced users may want to find the process ID via ps and then use kill to stop it.

Advanced: A future version of this could run a local web server from the phone rather than accepting commands via telnet. We're also exploring XMPP to chat with your robot.

Step 6: Connect a 3.3v to 5v level shifter to the Arduino

The Arduino used in the this tutorial is a 5v model so we need to convert the 3.3v signal coming out of the G1 using a level shifter. It should be possible to connect directly to a 3.3v Arduino but that was not something I tested.

There are several ways to approach this but we'll use a 74LS04 chip in this example. You can search for one here and they are likely under $1. Tim and I picked ours up from the Hacker Dojo in Mountain View, CA but these are VERY common and should be plentiful wherever chips are sold or donated.

At a high level we're simply going to send the TX signal from the HTS USB breakout board into pin 1 of the 74LS04 chip. To make it work we go through the chip twice and come out pin 4 to the RX pin on the Freeduino SB (your serial pin may be different if you have another Arduino board but all should support this).

Follow these steps to wire up the level shifter and connect the HTC USB board (do not plug it into the phone yet and unplug power to the Arduino):

1. Insert the 74LS04 chip onto your breadboard. Make sure the chip hurdles the center break so the pins aren't shorted (a dumb move I made at first)
2. Soldier two wires to the HTC USB board as described in this instructable, but we'll only be using pins 7 (Ground) and 8 (TX0) since we're only doing one-way transmission for this tutorial.
3. Connect the other end of the ground (pin 7) wire to a ground on your breadboard (which should be connected to a ground on your Arduino)
4. Connect the other end of the TX0 (pin 8) wire to the breadboard where it runs into pin 1 of the 74LS04 chip. (do an image search for a full diagram of the chip)
5. Use a wire to connect pin 2 and 3 of the chip
6. Connect pin 4 of the chip to the Arduino RX point (pin 0 on the Freeduino SB and Arduino Duemilanove)
7. Connect pin 7 (GND) on the chip to the ground for your breadboard (which also connects to the Arduino ground)
8. Connect pin 14 (VCC) to the 5v power on your breadboard (which gets the power from the Arduino 5v output)

You should now be ready to plug in the HTC USB break-out board into the bottom of the phone and power on the Arduino. Check for sparks and smells and touch things to make sure they are cool.

Note: The current cellbot code turns on LED #13 when the servo motors of the robot should be running. If you don't have a robot yet you can check to see that the LED turns on and off to confirm it is working.

Step 7: Load the Cellbots program on the Arduino

Picture of Load the Cellbots program on the Arduino
SerialMonitor.jpg
Get the Arduino source code from our Google Code project site. Open the Cellbots.pde Arduino program in the Arduino editor. Then push it to your Arduino board.

You can test talking to the Arduino code by opening the serial monitor in the Arduino editor. This is a great way to test your robot or device by talking directly to the Arduino before hooking everything up to the phone. The code sends serial commands back to the serial monitor to confirm what it is doing even if you don't have your robot built yet.

Note: You can't load programs onto the Arduino while the wire is connected to the RX serial input pin. So you might want to put this one a switch but I simply unplugged it when I needed to load a new program.

Step 8: Run the whole process

Picture of Run the whole process
2010-01-24 22.14.56.jpg
2010-01-24 00.05.09.jpg
ddms adb shell putty.jpg
tank.jpg
You should be able to connect the HTC USB board to the phone, fire up the cellbot.py file in ASE, and open a terminal sessions into the phone. Type "H" to have the phone say hello or any other commands from the README.txt file.

A "q" will quit the Python script on the phone and close the terminal socket.

Here is a recap of how it all works:
1. The Python script opens a socket to accept incoming telnet connections and echo the commands out the serial port
2. We connect from our PC to the phone via telnet on port 9002 and send it commands that we see on screen
3. The HTS USB board interfaces with the G1's USB port and sends the 3.3v signal into the 74LS04 pin 1.
4. The signal comes out of the chip on pin 2, goes back in on pin 3, and comes out again on pin 4 at 5v
5. Our Arduino accepts the serial signal on RX pin 0 and process it via the Cellbot.pde program
6. We can type 'q' to kill the Python script and close the telnet connection

Now that you've completed this very complicated process to send basic commands to an Arduino robot, it is time for you to hack it to be more awesome! We don't yet have 2-way serial working so the Arduino can't send commands back into the phone but we're working on that.

Stay current by subscribing to our blog at Cellbots.com.

About the Authors:

Tim Heath
Lead researcher who first put this process together at the Tech Shop in Menlo Park, where he is a member.

Ryan Hickman
Programmer who worked on the Python and Arduino code and authoered this Instructable.

1-40 of 44Next »
DanaS33 months ago

hi great work , i need to controll my Microconroller Atmega8 with Serial communication in android any API or Links please ?

netwavex6 months ago

i am using cyanogenmod11 ported to chinese phone. i only see ttyMSM0 when i grep /dev/. will ttyMSM0 works too?

vince0862 years ago
Can't seem to get "chmod 777 /dev/ttyMSM2" to work.
Keep getting "Operation not permitted".

I am rooted and running Cyanogenmod 6.1.0 on my G1.

Would love to get this working for a personal project.

I know this is way old, but in case people follow the same steps and end up with what vince086 had, simply enter super user by typing

"su"

This will allow access to enter the command "chmod 777 /dev/ttyMSM2"

steaknonio1 year ago
Hey, so I'll be trying this out soon, but wanted to let you and others know about other, cheaper and possibly useful options for the extUSB breakout board. I picked up three of these headphone charger combos hoping they'd be all pinned out, and they certainly are! (http://www.amazon.com/HTC-Multifunction-Adapter-T-Mobile-Shadow/dp/B001QD3MQE) I do enjoy sparkfun's products but it seemed the breakout board just had a bit of too much breakability for my clumsy fingers. a simple squeeze with some channel locks opened up the top and gave access to the inner workings.
Sorry, forgot pic
audio_and_charger.JPG
mabster9252 years ago
can i do this with another android phone running cygenmod 10 and i a micro usb slot
lok.khanal2 years ago
I want to try this but don't have much ideas on coding for this kind. anybody can help me out? I am new so just little help would be great.
jeffhorton2 years ago
Ok.. Cellbot.py is running on HTC Thunderbolt.. BUT it freezes phone when telnet connection made from computer. Any ideas?
Awesome ! :D
I'll try it with my Samsung Galaxy Mini. Many thanks !
jeffhorton2 years ago
Hello,
I am trying to use an HTC Thunderbolt with my Arduino project. I have rooted the phone, I have cellbot.py running on the phone. But when I try to send a command to the Arduino, the phone freezes up. The command is never relayed to the Arduino. Any suggestions on how to cure this. I read in another blog that multithreading the python program will help. Not sure if that is true. I am not that familiar with Python. I am trying to learn multithreading on python now. Am I wasting my time?
Much thanks in advanced.
asmuransyah2 years ago
Hi??? this project can use android experia 10 mini pro???
it looks nice sir,,we would like to implement this project...from wher we can get the components for this project?
sdfgeoff3 years ago
Do you have to have the arduino at all?
Could you not just have the phone do all the processing (after all, they do have pretty good processors) and have the micro-controller just relay the commands to the motors etc,
haroonbms3 years ago
my android phone doesn't have serial port. Can i use a usb to srial converter to
connect it to the arduino... please reply
No android phone has a direct serial port, heck, I don't think you can buy a proper computer with a serial port anymore.
What some android phones do have is the usb port used for connection to a computer, can be used the other way by the phone. This means that you take a special plug (the HTC usb break-out board) that lets your phone talk to a micro-controller.

So google your phone and see it if has a "proper" usb port. Mine doesn't, and I think they are quite rare, but you may be lucky.

(I think, someone correct me if I'm wrong)
haroonbms3 years ago
i have a samsung galaxy y s5360. how to connect this phone serially to robot. is it hrough usb data cable.. i desprately want to this project.. please provide with a solution.
Kryptonite3 years ago
This is brilliant, I plan to do a similar thing though have it controlled via the left and right channels of the headphone jack. It's not an original idea, though it's certainly an easy way out.
techmind483 years ago
I have HTC Wildfire Android mobile.

Is it possible to built with this phone?

A. S. Bhasker Raj
Secunderabad
India
Mobile: +919247332574
mahendar3 years ago
i don't see /dev/ttyMSM2 on my phone. It is rooted though. what can I do?
Rendydevara3 years ago
how did you connect android to arduino ? using serial ttl ?
does android has a serial ttl port ?

sorry, because i only have symbian s60 5th
bsoares4 years ago
great work!
ynk064 years ago
Nice Project! i think i will build this!

But just got a question before i build that

1) i just have a look on the datasheet of 74ls74, isnt that the 74ls04 have a output level of 3.3v but not 5v???So are we converting 3.3v(from phone) to 3.3v(to aridno) agian using the 74ls04?

2) And will G3 and upper version not works with that? since they are using the standard usb again and separate the audio(tx) + Switch(rx) pin to an 3.5mm jack ?

Thank You
Beginning of 2011 inopiaaardbei made a solution called: "Microbridge" using the Arduino USB host bridge and wrote the software to use the Android Debug Bridge to communicate from and to the Arduino.

See more here - http://wp.me/pCAFq-h5. Links to his google code solution are in the post.

A direct link to the google code repository is here: http://code.google.com/p/microbridge/
mertaxoy4 years ago
is it possible with HTC Wildfire. Wildfire has another USB break-out.. Can you please help me about this.,
rex3584 years ago
hey, can i run my camera app that i have built using the ecclipse , the same time when this appp on python is running....illl be glad if some body helps me on this
Chowmix124 years ago
For the newer generations of android electronics (phones and tablets) including the Droid. They come with USB host already built in> Could i use the same programing cable for my arduino to connect to an android tablet? If i did, what app would i need to accomplish a serial port to the arduino?

Chow.
it not goes nothing?
radhoo4 years ago
One of my last projects was a 4x4 differential drone, built from scratch, remotely controlled via Bluetooth using an Android smartphone.
Schematics / demo video here: http://www.pocketmagic.net/?p=1398
Besides ultrasonic sensors, the robot is about to be equipped with a homemade geiger counter sensor to detect "exotic" environment parameters
like the dangerous ionizing radiation. There are quite a few possibilities since the robot has an ATmega microcontroller that can easily
support additional sensors.
The data is sent back to the Android device, via bluetooth.
carterson25 years ago
Can I buy a kit?
wenjiun5 years ago
You can also choose the latest Super D 1.10.2 as well while older version 1.9.3 does not support the feature.
roadog5 years ago
COOL!I wanna try it! 
is it necessary for the phone on the bot to have service turned on??

are there ways to control the bot through satellite instead of using cellphone service. that way you wouldn't be dependent on a service.

Is there any way to bypass the use of cell phone towers all together???
mranalytical (author)  christian2gothic5 years ago
 We typically test with phones that have no SIM card and use wi-fi for local communications.
what if you wanted the bot to travel across several states?

and i've been looking into flying bots, it's been hard to find anything here on instructables.

how hard is it to send live video and sound feed from the bot to your PC??

i'm trying to gather info for a different project i'm working on??
mranalytical (author)  christian2gothic5 years ago
 We just added XMPP support so as long as the phone has a data connection (any kind will do), you can command it from anywhere.

Feel free to start a thread here with ideas: http://groups.google.com/group/cellbots
captFuture5 years ago
Thanks for this nice Tutorial - I can confirm that the latest kernels of Cyanogen have Serial enabled. (I'm personally using a HTC Magic - not a G1)

I did a bit of research as well and found out that Arduino sees 3,3V from the Phone as valid "high" state, so you would not need the 74LS04 in between for sending the data to the arduino.
This is of course different in the other direction - there you have to reduce from 5V to 3,3V :)

Cheers
mranalytical (author)  captFuture5 years ago
Great find captFuture. I'll update the instructable to reflect that. Still trying to get two-way working but the issue isn't hardware so much as making an incoming serial socket using Python when pySerial isn't in ASE.
 Maybe it would be an option to do it in java - some guys are developing a serialport API for the SDK.

code.google.com/p/android-serialport-api/



 but you need the serialport dll..... can you send me?? i can't compile it!!! (rice103@gmail.com)
1-40 of 44Next »