Mobile Arduino with Mobile.Processing
Using Mobile Processing and a Motorola cell phone to relay arduino data to and from a website.
I have recently cleaned up and simplified the original sketches from this project - both on the arduino and the phone. . . The changes should make it a bit easier to adapt an existing project to use the phone app as a gprs gateway for an arduino board.
The most significant change is in the way the arduino sends the server info to the phone. . . as of this version, we just add that info to the payload (vars or querystring) sent to the phone. . . So, in effect the arduino is just dumping [server,/path/file.ext,var1=value1&var2=value2 . . . ] to the serial port as it would if it had been communicating to the serial monitor or any other device connect to its serial port. The phone sketch on the other hand has been changed to read the info from the arduino and find the server address and path to a web page from the stream of strings. Make sure to check the comments in the .pde files for more info.
The main shortcoming remains - the arduino initiates the data transfer. . . no direct access from the web to the arduino yet - but that may change soon.
The schematics provided below are still relevant. . .
Here are the new files:
compiled jad/jar for phone
001 - 03/12/2008
I've been playing with Mobile Processing for a few months now and I recently wrote a little sketch that can be used to shuttle bytes from an arduino board to a website and back. It is based on this example I saw on the Mobile Processing website. Nothing new here so far, except that I tweaked the code a bit to use the phone serial port for the source and output of the data the phone sends and receives from the web. . . Then, after a few trips to radioshack, I managed to connect my arduino to my cell phone. Arduino Mobile anyone?
It is quite simple to adapt an existing arduino sketch into something that can be used with the phone app. Besides the usual serial stuff, we just have to make sure the arduino tells the phone what website to send and fetch data from. . .
Here are some videos of it in action:
| Send milliseconds, receive text and print it on LCD
||Request variables and pass it to a RGB LED|
w/o LCD: web2LED.txt
|Adapted from Aduino Playground LCD example||Adapted from Todbot Ambient Orb|
|Both examples use the same Mobile Processing sketch for the phone:
Download Compiled Jad/jar files: Phone.zip
How the mobile sketch works:
The brain of the system is really on the arduino or the web page the phone requests. . . The phone just passes any data it sees back and forth. . .
For the phone app to run, it needs the URL of a server and the path to a web page. Once that information has been made available by the arduino board, the phone will request that web page anytime it sees a # on its serial port. . . Additionally, any results from the web page requested are sent back to the arduino via the serial port.
So, if you just need to request data from the web at a set time frame, the arduino sketch needs only to send a # from time to time and wait for the result.
If you need to pass variables to a website, the arduino must pass a string with those variables and end the string with a #.
Arduino NG board
Motorola i415 Iden phone
Serial cable for phone
DB9 gender changer
RadioShack null modem adapter
SparkFun serial LCD
RS232 interface board from Anykits.com
RadioShack full-Color LED
I used a cheap Motorola Iden i415 phone with a pay as you go plan from boostmobile. . . It has unlimited data for 33c/day. It is quite convenient since I can just reboost the account when I need to use it. . .
Debugging this sketch on the phone was a real pain because the phone emulator I use with Mobile Processing does not really have any serial ports. . . Additionally, uploading it to the phone required a trip to an old pc in order to use the Motorola Java Application Loader. So, once I got it all working, I moved all variables off onto the arduino. That way I (or you) wouldn't have to recompile the phone app should the server address change. . .
There is so much more that can be done with Mobile Processing. Just as an example, Mobile Processing has bluetooth and SMS capable libraries. Those could add a whole new level of interactivity to an arduino board and they are definitely in the list of features I'd add to the sketch. Additionally, using bluetooth would make it compatible with more phones. . . seems like getting access to the hardware serial port is restricted on some devices. . .
Website and webpage:
On that note, you can/should add lots of logic to the web component of this system. The page requested by the arduino can be the result of some preprocessing. . . like this example from Tom Igoe where his php does some page scraping before giving the results back to his arduino.
The length of the messages passed back and forth are limited by the arduino serial buffer which I think is about 128 bytes. I'm sure there are ways around it but I have not gone that far.
The speed at which the phone and arduino communicate is limited by the phone serial port - In my case I used 9600bps, which is fast enough if all you have to toss around is 128 bytes. . . Some phones my not operate at that speed so your mileage may vary.
Credits and other info:
The mobile and arduino sketches here use a mix of tutorials, sample code and anything else I could get my hands on from the web. . . All I did was stitch them all together to send and receive data from my arduino to a webserver using the serial port and the gprs connection from the phone. There is plenty to be improved in the code provided and I'm sure most of you will find quite a few things to point out. . . Just use the comments at the end of the page and let me know if you find anything.
Since this is all just a mashup of other people's code i found online, I cannot take any credit (or responsibility) for the code provided here. If you think that I used your code without any attribution, let me know. I'll be happy post your name/link here.
For the record, I have used bits and pieces of code from samples provided by:
Francis Li - mobile.processing.org / www.francisli.com
Tod E. Kurt - www.todbot.com
Tom Igoe - www.tigoe.net
And, the folks at Arduino Playground - from their tutorials on using LCDs with the arduino board.
So, to these guys, thank you for making your code public so I could copy, learn and share. . .
Comments? email email@example.com