Control your R/C vehicle from your iPhone
Posts tagged sockets
And just like that… the jitter’s gone!
Mar 9th
I’ve made a few modifications to my Arduino sketch to keep it small… and I’m happy with it! I’ve learnt that the smaller the footprint on a device with limited memory the faster it can process things. So I’ve gone from an Arduino Sketch of roughly 100 lines of code… to something so slim and simple that it almost feels wrong to use it! Below is the graph from the output of the serial socket…
I’m releasing this code… now… I’m feeling a little nervous about releasing it… If you’re going to copy and paste this code, could you please at least leave the credit at the top? I’ve worked hard on this, and I didn’t do it so some twat can steak his claim on my work!
That’s right, no advanced algorithms, no crazy conversions, I’m just taking the first 3 bytes of the buffer from the socket and assigning it to the acceleration, and the last 3 bytes and assigning it to the steering… There are no heavy HTTP protocols to handle the requests, just one socket stream connection from the iPhone to the Arduino/BlackWidow! I can’t believe that the last 4 months of R&D has led to 8 lines of code!
Just to show you what I mean, the sketch started out like this…
Which works fine if you’re not trying to push through 60 requests per second to a device with 2 KB of SRAM and 1 KB of EEPROM. Just to put it into perspective the iPhone 3GS has 256mb’s of RAM…
Update… sorry guys, I’ve taken the code down… for now! I’ll put it back up once I’ve made my mind up about how to distribute it!
New Board, New Ideas
Mar 4th
I know I’ve been away for a while but this is why…
On the left you can see the old Arduino and on the right you can see the new streamlined Black Widow from Async Labs, which is just a modified Arduino with WiFi built into it. I’ve also decided to go down the sockets route to communicate between the Arduino and the iPhone, all is going well! I’ve started creating the iPhone app, which is looking pretty nifty, when you turn the phone the steering wheel turns too! And it sends commands to the Arduino. I’ve had a few problems where the servo’s jitter from the commands from the iPhone but have found that connecting directly to the Arduino over WiFi in ad-hoc mode seems to have mitigated this.
Using the serial out on the Arduino I was able to see what values were being received from the iPhone, obviously trying to analyse a load of numbers (several thousand of them) is pretty boring, and I have better things to do with my life. So I downloaded  Plot for the mac, which will turn a load of data into a graph (before you ask, Numbers and Excel can’t process stupid amounts of data quickly to display them in a graph, even on my dual 2.26ghz quad core mac pro). So below are the fruits of my labour, there are still a few anomalies as you can see, but it’s getting there, once the jitter’s all gone I’ll feel a bit more confident and hook up the speed controller!
Just imagine that those curves are from me tilting the phone.


