Physical Computing with Ruby and Arduino

Posted: October 16th, 2008 | Author: | Filed under: coding, culture, ideas, science | Tags: , , , | 9 Comments »

Just got back from this month’s ORUG, where Matthew Williams gave a presentation on using Ruby to control an Arduino. Matt is a very natural speaker, and the presentation was great. He even demoed a bartending robot he built, which should be featured on Make very soon.

I took notes during the presentation, and they are as follows, with links where possible.


Matthew Williams
Physical Computing with Ruby and Arduino

Arduino is an open-source board

There’s Bluetooth Arduino boards

There’s an Arduino board that was developed in a circular shape. People have combined this with conductive thread and sewn it into clothing. Someone even integrated this with some LEDs into their clothing and made a shirt with turn signals for biking.

Matt showed a video of a Wii nunchuck integrated with an Arduino, hooked up to some servos, and made a robotic puppet that works just by moving the nunchuck (not the control stick, just the accelerometer motion).

There’s also a YouTube video with someone who built a 1-wheel Segway-esque skateboard. Matt claims there are only about 50 lines of code controlling this device.

So, onto the Ruby Arduino Framework.
http://rad.rubyforge.org/ << outdated
http://github.com/atduskgreg/rad/ << more up to date

Matt says that the Arduino Google Group is fantastic.

[Tim: The Arduino IDE looks a *lot* like the Processing IDE (the Java-based graphics language).]

RubyToC – Ruby To C project; converts your Ruby code into C++, then compile it into Arduino bytecode. Then, there are Rake tasks which will load it onto the board for you. Most — but not all — of the Arduino API has been ported to Ruby.

RAD Methods
input_pin(s)
output_pin(s)
digitalWrite | digitalRead
analogWrite | analogRead
serial_print | serial_read

He mentions a slick trick for controlling the 7-segment LED displays. Since there’s 7 segments, you need to set 7 values separately, OR just create an array of those, and set them all with a single assignment.

Coming soon to RAD framework:

  • Testing
  • Arduino Simulator (for testing)
  • Better RubyToC support (there’s a few hacks required because ToC isn’t perfect)
  • More “out of the box” support
    • LCDs
    • OLED displays

Arduino “shields”
Shields are boards that can be plugged directly on top of the Arduino that add major new functionality.

Where to buy? Only $34.95 at
http://www.sparkfun.com
http://www.makezine.com (Matt strongly recommends subscribing to Make, says the dead trees copy is excellent)

Cheaper versions are available, but they either have components removed, or you must assemble it yourself

Make published a “get started with Arduino” kit, about $80, includes project info, the Arduino, extra parts. Most of the parts required for the project are included in the kit.

Barduino – DRINK MIXING ROBOT (created by Matt, who is clearly demonstrating his aptitude as a proper geek)
He used windshield washer pumps, $9/each

Matt created a DSL for describing drinks

drink ‘Screwdriver’ do
serve_in ‘Highball Glass’
ingredients do
2.ounces :vodka
5.ounces :o range_juice
end
end

Matt mentioned a hack, some functions that accept only one param will get converted (by RubyToC) to functions that accept none, so, the following line fixes it

def dispense(pump)
foo = pump + 0 /* This is the fix */

end

For more Ruby Arduino…

RubyConf 2008, Friday, 10:25 – 11:05, Room 3
Greg Borenstein — author of the Ruby Arduino framework — is presenting

Questions:

Can you “brick” an Arduino?
Not via code, but you could put too much power into it and fry it. Matt thinks there’s a little surge protection on it.

Can you sync Arduinos?
He’s seen something like it, and thinks that the serial comm lines would make it fairly easy to do.


Twitter Autocomplete (Tw-autocomplete Firefox Extension)

Posted: September 23rd, 2008 | Author: | Filed under: coding, firefox extensions, hustle, javascript, science | Tags: , , , | 2 Comments »

After lots of code, tests, and fun, I’ve produced a Firefox extension to add a useful, new feature to Twitter, as opposed to writing Twitter extensions as a joke :D

Simply put, the extension provides autocomplete for Twitter usernames from your own list of friends while you’re using the web interface at twitter.com. It’s totally secure — no separate login required. Just install it, and use Twitter naturally.

When you start typing messages to people — using “@user” or “d user” — a list of matching contacts (along with icons) will drop in. You can click the person’s name to fill their username into the text box, or use the arrow keys along with tab/enter to select. As an added bonus, if you can’t remember their username at all, just type their first name, and the extension will figure it out.

There is another autocomplete script for Twitter, but it requires installing extra libraries, and I think this is simpler. Clearly it’s a feature in-demand.

The extension is hosted at addons.mozilla.org, a highly reputable site. They also provide lots of great management features that are handy to developers. I hope you enjoy using Tw-autocomplete.


Adam Savage of Mythbusters

Posted: August 19th, 2008 | Author: | Filed under: ideas, science | Tags: , | 3 Comments »

I watched a video of Adam Savage at a hacker con in NYC. You should watch it too. He talks about Mythbusters, and also has a lot of other good stuff. Strongly recommended.

Bonus: Look for his pirated copy of The Dark Knight.


Vinegar beer

Posted: July 31st, 2008 | Author: | Filed under: food, ideas, science | Tags: , , , | 1 Comment »

I’ve got a post at Websites and Beer talking about adding vinegar to beer. Blasphemy? Maybe not…read on.

I’m reposting this here, because it’s sort of a follow up to my post about cheap versus expensive wines. Hooray for food. Hooray for science. And hooray for food & science together!


I love Science.

Posted: July 30th, 2008 | Author: | Filed under: ideas, science | Tags: , , , , , | 1,158 Comments »

I love Science. I don’t just love Science, I *fucking* love it. Maybe I’ll do a post on the Science sticks someday.

There’s a webcomic I particularly like, called XKCD.  It’s Science-y, Math-y, geek humor. Perfect for me.

One of the best is the following comic, good old #397. I love it because Feynman (one of the most significant scientific figures of the 20th century) shows up *as a zombie*, to defend the Mythbusters (who are awesome). On top of it, he makes a great point about Science, and Science in culture.

Zombie Feynman defends the Mythbusters

That, and I love the phrase “drag humanity out of the unscientific darkness”. Science!


Do judge a book by its blank pages

Posted: July 22nd, 2008 | Author: | Filed under: ideas, science | Tags: , , , | 529 Comments »

Zombie Feynman got me reading about Feynman, and I came across a great page discussing Feynman’s involvement with the textbook industry. Although it’s funny at times, it’s fairly sad that this is actually the back end of our education system.


What makes a great wine?

Posted: July 17th, 2008 | Author: | Filed under: food, ideas, science | Tags: , , , | 1,497 Comments »

Saw a post on the Freakonomics blog about wines, and people’s abilities to tell the difference between good and bad wines. I love Levitt for his willingness to piss people off in the pursuit of truth (read the part about the scholar who stormed out of the room!) Anyways, there was a large study done, and the conclusion is that people generally can’t taste the difference between “great” wines, and ordinary wines (link goes to original paper).

Don’t get me wrong, I’ve had some reasonably pricey bottles of wine. And I’ve enjoyed some of them. I appreciate that there’s people who really take care of their vines; who pick the best grapes; who use classic equipment and methods. But, I’ve also had bottles that cost under $20 and tasted quite nice.

Generally (and with no expertise to back this up) I think the knowledge of how to produce a decent wine has spread very far, and snobbery is mostly a hangover from the past few hundred years when lots of wines were actually quite bad.

Of course, I know the true secret behind great wine. It’s that any average wine becomes great when you drink it with great people. Salud!


Little digits

Posted: June 12th, 2008 | Author: | Filed under: ideas, science | Tags: , , , , , , , , | 1 Comment »

There’s this idea I’ve had rolling around my head for a while now. I call it the Law of Small Numbers, but it’s not really a law, and it’s apparently not called that either, at least according to Wikipedia.

Basically, it’s that small numbers increase easier than big numbers. It’s an idea that’s become popular with investors — small businesses can double your money easier than big ones. A tiny store can easily double it’s business, WalMart can’t.

Simply put, if you’ve got 2 units, and you increase that by 1, you’ve increased by 50%. If you’ve got 20 units, and you increase by 1, it’s only 5%. That’s the Law of Small Numbers. Maybe I should call it the Law of Increases of Small Numbers.

It’s something that’s popped into my head lately, thinking about gas prices. I’ve been trying to collect some gas mileages in my car, so that I can have hard data to look at. The way I see it, your gas mileage is a function of your gear, and your RPMs. Assuming constant gear (let’s say 4th — you’re cruising). If you are going from 2000 RPM to 4000 RPM when accelerating, you are literally cutting your gas mileage in half. If you can travel 55 MPH at 2000, but 60 MPH at 2500, is it worth decreasing your mileage by 25%? What if the corresponding speed increase only gets you there 90 seconds faster?

On a side note, one of the pages linked from that Wikipedia page discusses the Strong Law of Small Numbers

“There aren’t enough small numbers to meet the many demands made of them.”

I see this as the reason that things always seem to happen in twos and threes, but that doesn’t mean that they’re related.


Bayes, and the Mythical Viagra Spam

Posted: June 4th, 2008 | Author: | Filed under: science | Tags: , , , | 1 Comment »

OK. I’ve been running a test where I’ve been attempting to gather Viagra spam into a Gmail mailbox, viagraspamtest@gmail.com

I started the test in mid-May, posting the email address to questionable and shady mailing lists, as well as linking the address in plain text on my blog.

And 6 weeks in, how is it going? Well…it’s not. There’s not even a hint of Viagra spam. Nothing in the spam folder, nothing in the Inbox. Just all legitimate mailings from newsletters.

Possibly, it takes time to get onto shady mailing lists. I imagine lists of emails get hacked and resold to spammers, but that it takes a while for a given email list to work its way down to the spammers.

Also possible — there’s no more Viagra spam. As in, spam mentioning Viagra by name. They are either advertising whole pharmacies, a class of drugs (blood pressure, E.D.), or the ad is in an image that gets embedded into the email.

Maybe I should retry this project with the word “pharmacy”. Viagra spam is *sooo* 2002, anyways.


Training Gmail: Sit. Stay. Good Gmail.

Posted: April 14th, 2008 | Author: | Filed under: science | Tags: , , , , , | 2 Comments »

At the end of my presentation on Bayes’ Theorem at BarCampOrlando, there was some Q&A time.

I was asked a question about automatically training a spam filter, and I got into explaining how Bayesian filtering isn’t a “spam test” per-se. The simplest way to think about Bayesian filtering is that you sort email you’ve already received into two piles: email you don’t consider spam, and email you do consider spam. Then, through the magic of Bayes, new emails automatically get put in one of the two piles, based on which pile the new email most resembles.

Then I mentioned — as a bit of an oddity — that you could theoretically train Gmail to deliver nothing but Viagra spam to your Inbox. “Heh,” I thought, “that would be a neat trick.”

Hence: viagraspamtest@gmail.com

I’m trying to sign up for as many shady email newsletters and web forms as possible. I’m posting the email address here, as a fully-qualified mailto: link. Anything I can to start getting spam as fast as possible.  I’m planning on marking everything that mentions Viagra as “not spam”, even “1337-speak” emails like “V1agra”. Depending on how it goes, I hope to post results here.

(On a side note: I wonder how the IT dept at Pfizer handle spam. They must get a ton of false negatives for Viagra spam.)