Posts with «node.js» label

Using the Raspi as an Ethernet shield

[Alexandre] wanted to set up a web-based temperature logger with his Arduino, but found the Arduino Ethernet shield a little finicky. Since his Raspberry pi was just delivered, he figured he could use the Raspi as an Ethernet shield with just a little bit of coding.

After [Alexandre] set up his Arduino to send a thermocouple through the USB, the only thing left to do was to add node.js to the Raspi’s Debian installation. Every five minutes, the Arduino wakes up, takes a temperature reading, and sends it over to the Raspberry pi. From there, it’s easy parse the Arduino’s JSON output and serve it up on the web.

In the end, [Alexandre] successfully set up his Raspberry pi as an Ethernet shield to serve a web page displaying the current temperature (don’t F5 that link, btw). One interesting thing we have to point out is the cost of setting up this online temperature logger: the Arduino Ethernet shield sells for $45 USD, while the Raspberry pi is available for $35. Yes, it’s actually less expensive to use a Raspberry pi as an Ethernet shield than the current Arduino offerings. There you have it, just in case you were still on the fence about this whole Raspi thing.


Filed under: arduino hacks, Rasberry pi

Publishing data on the web with Node.JS

Many solutions exist for publishing data coming from Arduino boards on the web. Bangon Kali, in his detailed tutorial, proposes his novel approach, which makes use of several widespread and open-source technologies, such as Node.JS, jQuery and Apache:

Using the USB, the Arduino Board is connected to the PC serially to a certain COM port which the OS allocates. Node.JS, the asynchronous server side JavaScript engine then listens for the port using a Node.JS module called SerialPort2. When a signal is received, using the Node.JS Socket.IO module, data is then served also asynchronously to the web providing a real time feed of the Arduino signal.

The tutorial (which can be applied on Linux, Mac OS and Windows) can be found here.

[Via: DangerousPrototypes and The Code Project]

Arduino Blog 05 Jun 15:31

WineShade: Hipster Stack-Powered Voting Gizmo for O’Reilly’s Strata Conference

I was asked to make something for the O’Reilly Strata Conference, which was held in Santa Clara at the end of February 2012. We needed some devices to capture vote from attendees who participated in Coco Krumme‘s Data Crush: Where Wine and Data Meet:

This new event at Strata will host wine tastings for participants, whose feedback data will be compiled and analyzed to extrapolate behavioral trends and factors influencing their responses.

I decided the best way to accomplish this was to shovel a bunch of new technologies into the project: MakerBot, XBee, Arduino, Node.js. I believe it was Alasdair Allan who dubbed this the hipster stack. I believe it was Alex Howard who dubbed it the WineShade. But between the wine and solder fumes, my memory is suspect!

MakerBot
If I’m going to make something physical, I knew my MakerBot Thing-O-Matic could make my life easier. At first, I thought I’d use the MakerBot to print out something to hold buttons and indicators in place, but I decided to go with some foam core for this. I had decided to use lampshades as the chassis for each station, and I needed something to cap it off. So I made a little tower to go on top of each one. I eventually went with something smaller than what you see here.

Arduino Mega
I knew I’d need a lot of I/O, since each station would have three bargraphs and three buttons (though we ended up using only two each). I didn’t want to put too many components into this since I’d need to build them, so I decided to drive the bargraphs directly from the Arduino pins. To minimize the number of transistors, I decided to take advantage of persistence of vision, and multiplex the bargraph. I wrote a small library for the Adafruit LED bar graphs to do this, and posted it to GitHub. I’m just using one color, but the library could easily be extended to handle both of the bar graph’s colors.

Digi’s XBee
These voting stations would be spread out all over the place, and needed a way to talk to a central server. I’ve had a lot of experience with Digi’s XBee modules, and I’ve always wanted to use the XBee Internet Gateway (XIG) in a project. XIG lives on a Digi ConnectPort X, and acts as a gateway between the XBee network and web servers (XIG can also talk to the IDigi cloud). I reached out to Rob Faludi, author of Building Wireless Sensor Networks, and he arranged to loan me a ConnectPort X2 Industrial and four XBee Pro modules. Thanks, Rob (and Digi)! I liked XIG so much that I bought a ConnectPort X2 Commercial (less RAM than the Industrial, but it works well for me).

Node.js
If I’m going to have the XBees talking to the network, they better have a server to talk to. I usually reach for PHP or Perl for this sort of thing, but I decided I’d heard enough about Node.js (Beagle Bone‘s adoption of it got me really interested in it) that I better look into it. It worked great. It would have taken me longer to write this in PHP (or any of my usual languages) than it did for me to learn Node.js and implement it. Once I got my head around the asynchronous insanity, I could add whatever feature struck my fancy in a matter of minutes (OK, so some features needed more minutes than others).

The trickiest part of building each unit was connecting the Arduino Mega to all the pins on the buttons and LED displays. I decided to take an Adafruit perma-proto breadboard, solder some long male pins to it, and shape them so they’d plug into the double row of headers on the Arduino Mega. It was a kind of makeshift Arduino Mega tail shield, but it works. I threaded each strand of ribbon cable into a breadboard hole and up before soldering it down, which gave me quite a bit of strain relief.

I’ve got some documentation in process in the form of a GitHub repository that includes the Arduino code. It’s a pretty simple system: when the Arduino boots up, it sends a URL over the serial port that the XBee’s connected to (you’ll want to modify the server string in the Arduino source), and XIG relays this to the server, and sends the response back to the Arduino over the XBee network. The server is a Node.js server that handles the requests from the Arduino: press a button, and a vote is registered. At each bootup (and after each button press), the Arduino gets the current vote tally from the Node server. That way, the Arduino doesn’t have to store any state at all! There’s also a primitive UI (/dash on the server) that lets you view the votes and manipulate them or reset them if needed. The index.js file lists all the handlers, and the corresponding handler code is in requestHandlers.js.

Flick set: WineShade for Strata
GitHub repo: bjepson/WineShade


MAKE » Arduino 10 Apr 23:30