otherbirds
  • Home
  • Blog
  • Projects
  • Musics
  • Tutorials
    • 18-16
    • 15-11
    • 10-7
    • 6-1
  • Irrelevant

Arduino + WiFi, Part 2

12/13/2011

2 Comments

 
The Wifi and Arduino odyssey continues.

Having done a bit more research and after a consultation with the good people on the NYC Resistor mailing list, I've come to accept the fact that this is going to be more than a weekend project. All in all I feel as though I'm about to have a very authentically Arduino experience, where after a few initial cries of "What the hell, this is an easy problem, why hasn't someone else solved this for me?" you roll up your sleeves and settle in for a nice, soul-sucking learning experience.  In hindsight I guess there's no reason for anyone to expect for it to be easy to take a difference in voltage, translate it into a digital value, encode those bits into radio waves and beam them across a room, receive that radio signal and turn it back into bits, and finally send those bits to a specific place in a specific application, all without doing any setup or configuring anything. The fact that I'm even trying to solve this problem instead of, you know, eating lice out of my friend's beard is a testament to the advancement of human society. But even though iCloud and iBooks and AirPort and WiFi make seamless wireless communication looks easy, from an objective, physical standpoint it's right up there with gene splicing. Which, I've come to learn isn't actually that hard, but that's another post.

If you're hoping for a clear, concise write-up that takes you all the way from an Arduino and a credit card to a zeroconf WiFi ballet, then you might want to put away the vuvuzela because we're not quite ready to celebrate yet. I haven't even narrowed it down to a specific Arduino shield. I have, however, sifted through the cruft and started to cobble together some of the more promising pieces of wares hard and soft.

Hardware:

Picture

1. RN-XV WiFly Module - Wire Antenna / $34.95 -- http://www.sparkfun.com/products/10822

Aww, look how cute it is! It's like a little red ladybug of nights spent alone rubbing your Arduino and router together in desperation. What's nice about this one is that it assumes you've already got a bunch of Arduinos and Arduino-related crap (which I do). Rather than requiring a whole new shield, this little module simply functions as a drop-in replacement to your XBee antenna. This means it's cheap, low-power and as an added bonus it means you can leave in place most of the hardware and software you'd already been using for XBee serial communication. If I already had some ad-hoc wireless Arduino solution up and running these would be huge plusses; as it is it's some relatively insubstantial but very tasty frosting. As with all the hardware modules it's able to handle 802.11 b/g and has the full TCP/IP stack, giving you DHCP, UDP, DNS, ARP, ICMP, HTTP client, FTP client and TCP. The only downside is that it's limited to 464Kbps, which isn't too slow but then even short people like high ceilings. 

Picture

2. WiFi DiamondBack / $73.00 -- http://linksprite.com/product/showproduct.php?id=74&lang=en

While the other hardware solutions listed here take the form of some shield or module that you plug into your Arduino, the DiamondBack offers an Arduino with WiFi baked directly in. I'm hoping that this makes it akin to a MacBook for Arduino WiFi, in that what you lose in versatility and cost you make up in design and ease of use. This one rakes in big bonus points for having a QuickStart guide, as I believe that anything more complicated than a doorknob (which includes some doorknobs) ought to have a QuickStart guide. It also claims to work with the WiShield code base from LinkSprite, which appears to be the best documented and most complete Arduino ethernet code package out there. But more on that later. Finally it boasts transmission speeds of up to 2 Mbps, significantly faster than the RN-XV. Though you should probably take that claim with a grain of salt, as that's just the theoretical limit based on the hardware, not a reported speed. For a point of comparison on the cost, I think an Arduino retails for $30, so you're actually getting pretty outstanding value-for-money with this board, especially if you don't already have an Arduino.

Picture

3. Hydrogen / $75.00 -- https://diysandbox.com/our-products/arduino-shields/hydrogen

Well it's expensive as expensive balls, so presumably it's got some good features to make it all worthwhile. The first feature that strikes me is being ugly as a broken knee, but then again it is an Arduino shield, not a Japanese flower bouquet. Like the others this board is 802.11b and capable of handling TCP and UDP connections. In a very sneaky ploy to convince us that this is some kind of lightning-fast magic board the product is listed as 11 Mbps certified, with throughput TBD. Of course that limit and certification are actually features of the 802.11b protocol and not the hardware, so who knows how fast this board can actually send and receive data. The hardware for this board links to the WireFree ethernet library, an Arduino connection library specific to this board. The most exceptional and simultaneously mystifying feature of this board is the inclusion of a MicroSD card reader, maybe so it can beam embarrassing photos to everyone in WiFi range without your knowing? The board claims to be able to scan access points for RSSI information, which is actually an extremely cool feature that none of the other boards seem to offer, in addition to storing "two connection profiles for easy reconnection." Presumably it needs the SD card to store these profiles? But even the cheap SD cards are goddamned huge; I'm pretty sure I've got a few 4GB SD cards between my couch cushions. Are the connection profiles really that big? And what is easy reconnection? I guess I'll have to buy the board and see...

Picture

4. CuHead Shield / $55.00 -- http://www.linksprite.com/product/showproduct.php?lang=en&id=73

My gut tells me that this is the WiFi shield for me. It looks just like any other Arduino Shield. It's upfront and clear about which pins it uses. It uses the phrase "plug-and-play." It links to the WiShield library, my favorite so far. It even offers a user manual in PDF form, although the file name "cuhead_wifi_shield_user_manuel.pdf" reeks of French influence. It even brings out all the Arduino headers that it would ordinarily block out, so presumably you can just snap it onto your Arduino and get to work as if it wasn't even there. Awesome. 

Software:


1. WiFly Shield -- https://github.com/jcrouchley/WiFly-Shield 
I saw a very promising and very clear example usage of this code here, http://log.liminastudio.com/programming/getting-started-with-the-rn-xv-wifi-module-node-js, big big thanks to Tedbot at NYC Resistor for the link. This all bodes well, however the code is specific to the RN-XV. I can't find a license, so I'm assuming the hardware specificity means that they didn't bother.

2. Wirefree -- https://github.com/diysandbox/Wirefree
Ugh, GPL. I hate the GPL. At least with commercial code you can pay a license and then the code belongs to you. You can do whatever you want with it without having to feel the icy hand of capital "O"pen software on your shoulder the whole time. Using software with a GPL license is like being a teenager driving your dad's BMW: it's fun but you can never appreciate it because of the constant reminder that you're enjoying something that doesn't belong to you. Worse, every single line of code you write from that point on has to include the original GPL license, so you can't even claim ownership to your own code anymore. What the hell, man? I agree, software should be open and free, but it's Apple-level crazy to claim that I don't own something I wrote myself. What were we talking about again?

3. WiShield -- https://github.com/asynclabs/WiShield
I'm definitely leaning heavily in favor of this source code and any Arduino Shield that can use it. This code claims TCP and UDP sockets and has example code for configuring a web client, a web server and even for posting tweets. That's pretty fantastic; I always wanted to build a wireless sensor attached to a scale under my liquor cabinet that could tweet at me when I was running low. The only downside, and this is a weird one, is that the authors of this fabulous block of code, Async Labs Inc., are closing their doors. This could mean that the code won't be actively maintained anymore. It also says something very interesting about the fact that I can't find a software license attached to the code--maybe there is no software license? Or even if there is, who's going to enforce it?

And now I've bought them. The credit card is maxed out and my Christmas present/punishment to myself is on it's way. You'll be the first to know when I actually get some bits flying through the air. One last thing to mention: eventually it will be important to jump one last hurdle, the hurdle of asynchrony. Writing responsive code that also networks requires a solid grasp of asynchronous programming and some kind of kernel that can handle the threading. How will Arduino stand up to the task? How will I stand up to the task?
2 Comments
 

Concurrency Puzzle

12/01/2011

0 Comments

 
The last thing the world probably needs is more examples of my incompetence, but in case you needed just one more, here's a pretty good example:
As you can probably tell, you're looking at some good old fashioned C. I had some struct with a field counter, and I needed to write a function that would increment that counter and return the incremented value, all atomically. This was my first solution and it's very, very wrong. It avoids some of the worst pitfalls of a multithreaded counter, in that the output does at least increase monotonically and there won't be any nasty memory corruption. At the same time, it's not only possible but likely that two concurrent calls to this function will return the same value. Each will perform the highly optimized, blisteringly fast atomic increment, then dopily retrieve and return the same value from o->counter. In other words, this function is kind of atomic, which as my concurrency professor used to say is a bit like being kind of a virgin.

The puzzle is how to fix it. With locks or multiple concurrency operations the answer is trivial, but with only one hardware-level concurrent operation it's at least not immediately obvious to me how to do it. The basic problem is that you need to do two atomic things at once: increment the value of o->counter and write that atomically-incremented value to the return register. Almost sure that it is a laughably naive answer, I propose this solution:
Not something I would necessarily bring to a Google interview, but it gets the job done. If you've got a better solution I'd love to hear about it.
Add Comment
 

Arduino + WiFi

11/29/2011

10 Comments

 
Get ready to be sad.

All I want is a WiFi shield for my Arduino. I want to snap a little board on top of my Arduino, throw in some code to specify a WiFi network to connect to, and then I want to be able to do socket programming on my Arduino like I can on my desktop. That's all I want.

Infrequently I'll take flak for owning a MacBook Pro or an iPhone. Someone will come along and they'll tell me that I shouldn't support Apple's closed and evil software philosophy, or that I've paid way too much for my computer, or that MacPorts blows goats on a jetski (this last one is totally valid. Choosing between MacPorts, Fink and HomeBrew is like picking whether you want your arm, leg or face pulled off). I take all that criticism, ignore it, and then set it on fire. Why? Because I am a firm believer in what I like to call the "and then move on with your life" philosophy. Here's why I got a MacBook: I asked a friend what kind of laptop I should get. He said I could get a Dell or an HP if I hated myself, I could get something even cheaper and throw a lightweight Linux distro on it, or I could get a MacBook "and then move on with my life." Sold. My friend saw through my question and accurately inferred that what I was really asking was "What's the fastest way to get from where I am now to a place where I can be enjoying laptop-ownership?" And by far the fastest way was in the driver's seat of a MacBook Pro.

That takes us back to the Arduino. What I really want is to be able to connect my Arduino to something else, be it my phone or my laptop or something. I want to get the two communicating and I want it to be easy and lightweight. In other words, I want to get a WiFi shield "and then move on with my life." Unfortunately it doesn't look like the Arduino community understands this philosophy. A quick google search for Arduino WiFi shield yields these results:

http://www.bizoner.com/arduino-wifi-ieee80211bg-serial-shield-internal-antenna-p-232.html
http://www.robotshop.com/anaconda-wifi-shield-arduino.html?utm_source=google&utm_medium=base&utm_campaign=jos
http://www.robotshop.com/cupperhead-wifi-shield-arduino.html?utm_source=google&utm_medium=base&utm_campaign=jos
http://www.linkspritedirect.com/product_info.php?products_id=63&cPath=6#googlebase
http://www.linkspritedirect.com/product_info.php?products_id=25&cPath=7#googlebase
http://www.linksprite.com/product/showproduct.php?lang=en&id=73
http://www.sparkfun.com/products/9954
http://www.cutedigi.com/product_info.php?products_id=4361
https://diysandbox.com/our-products/arduino-shields/hydrogen

All these options with no end--or reviews--in sight. This tells me a number of things: 1. Simple WiFi connectivity might not be that hard, which is good. I mean, the market for Arduino WiFi shields isn't exactly huge. If this many parallel solutions exist then the cost to actually develop something like this must be pretty small. 2. There is no standard solution for WiFi on Arduino, which sucks. This means that each of these boards probably has its own code to go with it, and that the mileage I'll get out of each board will depend not only on the design of the hardware but also on the quality of the documentation. It also means that I'm going to spend a lot of time combing through Arduino forums filled with incomplete or outdated information. Yay. 3. Any solution I develop for working with one shield and software combo will be totally ad-hoc and will not work with another shield and software pairing. For me personally it means that if down the road I decide I don't like a particular board that I'll have to re-write all my network code from scratch. On a level that affects other people it means that it will be really hard to develop a cross-platform library for WiFi on Arduino, something that could be agnostic to which WiFi shield you're using.

What I really want is to slap on a WiFi shield and move on with my life. Instead, I'm going to buy a few of these boards, try them out, and write up a nice comparison, just in time for non-denominational Jesus day. Hopefully the picture isn't as bleak as I've painted it, and getting all this stuff to play together isn't as bad as I suspect it will be. But I'm not holding my breath.
10 Comments
 

    Sam Tarakajian

    Breakfast is a faith-based initiative

    Archives

    January 2012
    December 2011
    November 2011
    October 2011

    Categories

    All
    Codes
    Life Fiction
    Stuff

    RSS Feed