Pine Car Derby

I run a small youth group at my church, and one of our annual events is a pine car derby race. Group leaders also get to participate, and this year I entered what I called the “CompuCar”.

Cars have to come in at under 5 oz. so putting wireless on board, components, and a battery, would have presented a major challenge if not for the Imp. Most of the wood was cut off the default brick to start, then various components were weighed until a good combination of visual fun was achieved. In the end, the configuration included a red and blue LED, and a BlinkM RGB LED. By default the lights behave like a police car - alternating red and blue (even the BlinkM).

Of course what fun would having an Imp on board be if there was no reason for the Internet connectivity? The lights on the car can be turned on/off remotely from a web page. Additionally the same web page controls the BlinkM state (on/off) and color. The web page is designed to reflect the iOS interface which most of the kids are familiar with using. Actions on the web page invoke XHR requests to Parse.com Cloud Code, which in turn POSTs the information to the Imp via HTTP In. This is done to (a) avoid running a server and (b) overcome browser cross-domain restrictions.

It’s not particularly impressive from an Imp standpoint, and even less impressive from an electronics standpoint (blink is the new hello world). The key was ultralight, power conscious, wireless, which would have been really hard to pull off with Arduino. And in the end, none of the kids believed that I built it myself.

@mjkuwp94

Re: Education

Thanks! I gave a workshop to teach electronics to kids in New York City about a month ago. It was amazing to see their minds kick into high gear with the possibilities. I’m not a teacher, or engineering type, but having kick-started the some of next generation into the sciences makes me see why teachers do what they do.

Re: Parse.com

The web page for the user interface is hosted on Amazon S3, so effectively that is my hosting server. You can get a URL for anything you put into your buckets. But, there’s no server-side technology there like PHP or what have you. S3 just delivers static assets. You can even point a domain at an S3 bucket.

I can run JavaScript in that static page to make things look dynamic, but I can’t reach across domains to POST my data to the Imp. Normally, that data would get passed through PHP, but again, I don’t have that. The back door here is that you CAN send data to servers from which you have loaded other assets in the page.

In the case of Parse.com, they give you a JavaScript library to access their data storage services. Loading that library into my page, gives me access to call back to their servers (via the library in this case). Parse.com allows you to run JavaScript code in their “Cloud Code” system (effectively server-side JavaScript, but not Node.js), and that API offers an HTTP class.

That HTTP class gives me access to the Imp via HTTP In.

It probably seems like a strange hack, but it is really pretty elegant for my needs. The static assets serve off of Amazon S3 lightening fast. And of course those bits cost next to nothing to store and serve. Parse.com gives me a “database” and some “server side” functionality - enough for most of my needs. That service is free to 1 million requests a month.

That leaves me with high-speed, redundant storage and data pass-through without having to worry about managing Apache, PHP, MySQL, some variety of operating system, or anything else. And it costs next to nothing until I’m ready to scale. And when I want to scale, costs scales with me.

Re: Getting Information Back

I assumed the transaction was successful across the board if I got an OK response from the HTTP POST operation in this case. Sloppy, I know. But with other projects I have used an OutputPort (see Imp documentation) to pass data along to the HTTP Request agent in the Planner.

So it certainly seems possible to handle the request with HTTP In, flip some bits on the board, check things, and then set values on an OutputPort to send along to HTTP Request, and back into your system. Not quite the same as getting immediate feedback from the HTTP response, but pretty close.

Depending on what you’re doing, this asynchronous approach might even be better. You wouldn’t want to hold open the HTTP response while you were waiting for a servo to move, or something like that. The Imp would respond with “OK” and you could ignore that for the time being. Then later when the Imp POSTs that the servo has reached its destination, you could update the user interface.

Hope this helps!

This is super cool. I especially like how you linked to education.

Regarding the web stuff. I am really new to this and it may show in my question. I do not understand why you went through parse.com. Wouldn’t you need a server in order to host the web page?

Can you get information back from the imp to the web page? So that a newly loaded page would understand that the lights were already on?

again, excellent job!

The web page looks like a real iPhone app. Did you use jQuery mobile? Would you mind posting the HTML code? Great job!

@osherl

Thanks!

No, no jQuery or frameworks here, this was a simple enough user interface to just code it outright. There’s no screen transitions, no need for a highly architected component library, or anything like that, so a framework would be overkill.

I’ve stripped out the Parse.com hooks from the code and posted it at the following URL. Feel free to play around and have yourself a “View Source”. By default, the police lights are on, and they take priority, so nothing else will work until you turn that off. And it will turn everything else off with it. From there you can toggle on the individual switches and/or select colors for the RGB LED.

http://hoytdemos.s3.amazonaws.com/compucar/index.html

Since iOS uses WebKit, there may be some WebKit specific hooks in the CSS. Note that I’m not trying to fragment the web here with a “best viewed in” WebKit-only experience, it is just that I knew that was my target device and browser, and it was only for me and the kids. The kids all know the iOS user experience, so I didn’t bother trying to get it to work in anything but WebKit. I did a quick check though, and it seems to work fine in Firefox, and on an Android phone I have.

Now let’s just hope that Jonathan Ive doesn’t change the UX too much in the next version of iOS (doh!).

Hope this helps!

The education part in my opinion knocks this project out of the park. You may never know how many kids that project might inspire. I especially like that they can actually see the hardware, circuit board, components and wonder about it. It’s that “wonder” that seems to be elusive with the youngest generation.

Thanks again!