I'm finally back from OSCON, and what a trip it was. Friend of the show wxl came with me to assist and experience the awesomeness that is OSCON. Over the next few days I'll be posting about the three sessions we taught and many, many sessions we attended. A splendid time is guaranteed for all. To kick things off, here is the code from my Amino talk.

Amino is my JavaScript graphics library I've been working on for a few years. Last year I started a big refactor to make it work nicely on the Raspberry Pi. Once we get X windows out of the way we can talk to the Pi's GPU using OpenGL ES. This makes things which were previously impossible, like 3d spinning globes, trivial on the Raspberry Pi.

For the talk I started by explaining how Node and Amino work on the Raspberry Pi, then shows some simple code to make a photo slideshow. (in this case, Beatles album covers).

beatles

Next we showed a 3D rotating text RSS headline viewer.

rss viewer

And finally, using the same GeoJSON code from the D3/Canvas workshop, a proper rotating 3D globe.

globe

Hmm... Did you ever notice that the earth with just countries and no water looks a lot like the half constructed Death Start in Return of the Jedi?

Of course, my dream has always been to create those cool crazy computer interfaces you see in sci-fi movies. You know, the ones with translucent graphs full of nonsense data and spinning globes. And even better, we made one run on the Raspberry Pi. Now you can always know the critical Awesomonium levels of your mining colony.

awesomonium

Source for the demos on DropBox.

I’m happy to announce Electron 0.2. We’ve done a lot of work to improve the compiler and library tools. The biggest news is Windows and Linux support. Also, you don’t need to pre-install the regular Arduino IDE anymore. Electron will auto-download it’s own copy of the required toolchain. Here’s the details:

  • Initial Windows and Linux support!
  • You don’t need to modify settings.js anymore. Electron will auto detect your Arduino/Sketchbook dir.
  • You don’t need the regular Arduino IDE installed anymore. The appropriate toolchain will be auto-downloaded for you the first time you compile something.
  • User installed libs work now. Note that user installed libs take a priority over libs installed by the IDE.
  • the serial port will be automatically closed and reopened when you upload a sketch. If this crashes your computer please let me know. I might need to increase the timeouts.
  • Preliminary support for auto-detecting which board you are using by the USB VID/PID. Special thanks to PixnBits for that.
  • Set the serial port speed
  • Sketch rename works now
  • download progress is shown in the browser (partially)
  • tons of under the hood fixes
  • auto scroll the console

The arduino-data project was also updated with new boards an libraries:

  • New boards: TinyLily and Gamebuino
  • More networking libs: CmdMessenger, OneWire, PS2Keyboard, SerialControl, SSoftware2Mobile, Webduino
  • More specs on various boards
  • The rest of the built in libraries: Ethernet, Firmata, GSM, LiquidCrystal, SD, SoftwareSerial, TFT, WiFi
  • Support library sub-dependencies

Thanks to contributors:

  • Dan O’Donovan / Dan-Emutex
  • Nick Oliver / PixnBits
  • Sean McCarthy / seandmcarthy
  • trosper

You can get the latest code on the github project.Please test this with every board and OS you have. File bugs in the issue tracker.

I’ve registered a domain for Electron, electron.pw, though don’t bother going there yet. I haven’t built the website. If anyone is a talented webdev who’d like to help with that job, please contact me.

I’ve you’d a sneak peek of the next version of Electron, check out the mockup here. It’s got a new library picker, a proper tree based file picker, and resizable panes. It still needs a lot of work before it can go live, but this will give you an idea of where we are going.

Thank you, and keep on testing.

I love the Arduino platform. I have official boards and lots of derivatives. I love how it makes hardware hacking so accessible. But there’s one thing I hate: the IDE. It’s ugly. It’s ancient. It has to go.

Sure, I know why the IDE is so old and ugly. It’s a hacked up derivative of an older IDE, written in a now-deprecated UI toolkit. Fundamentally, the Arduino guys know hardware and micro-controllers. They aren’t desktop app developers. I suppose we should be happy with what we have. But I’m not.

My previous attempt

About two years ago I created a new IDE built in the same UI toolkit as the original (Java/Swing for those who are interested). It worked roughly the same but looked better. It had a proper text editor (syntax highlighting, line numbers), better serial port and board management, and a few inline docs, but basically worked the same; just some UI improvements.

I posted my new IDE on the Arduino forums and got almost no response. Pondering this for the past two years I realize this forum was the wrong place to launch a new IDE. The people there are experts. They are happy enough with their current tools that they don’t want to switch. They are experts. They don’t need all of the improvements that a better IDE could provide, like inline documentation and auto-library-installs. They are also more likely to simply use a general purpose IDE. I’ve done this myself and it works okay, but I’m still not satisfied. Arduino is special. It deserves better.

As the Arduino platform grows it needs a better out of the box experience. We have more and more novices hacking for the first time. We need an IDE that is truly top notch. Something that is custom built for Arduino, and the tasks that you do with it.

Some have asked me, “What do you want to do that the existing IDE doesn’t already?”. That’s a good question. If we are going to seriously invest in something new then we need some good reasons. Let’s start with the basics: installing libraries and boards.

Library management

Right now you find a library somewhere on the web, download the zip file, and unzip it into your ‘libraries’ directory. You do all of this outside the IDE even though you will be using it inside the IDE. Next you need some docs. There is no standard for the docs, but there’s probably something to read on the website you got the lib from. At least there are some examples. Oh, but they are buried deep inside a menu.

Now suppose it’s a month later and you are working on a new sketch. Do you remember all of the libraries you have installed? How do you search for them? Do you have the right versions? Do they work with all of your Arduino boards or just some of them.

It’s the year 2014. Why can’t the IDE just already know about the libraries out there. It should let you search for them by name or keyword. It should let you search through the example code. Once you find the library you need it should install it for you automatically. Where does it go on disk? Who cares?! That’s the IDEs problem. Finding and installing a library should be a single button click (or maybe two clicks if we are picky).

Board management

The many Arduino boards are listed in a nested menu, derived from the boards.txt file. This text file is only updated when the IDE itself updates, which isn’t very often, and the list isn’t comprehensive anyway. If the board you need isn’t listed then you have to add it manually, outside the IDE, duplicating the effort of other developers everywhere. Why can’t the IDE just fetch a list of all boards from the internet somewhere; a list updated by the actual vendors of those boards, so it’s always up to date.

This list of boards actually contains quite a bit of useful information, like how much RAM is in that board. However, this information isn’t actually shown anywhere. It’s only shown to the compiler. The IDE should give you full specs on your chosen board right on screen so you can refer to it whenever you want. Furthermore, the IDE should have extra board info like the number of pins, the input and output voltages, and if we are being generous an actual pinout diagram! All of this information is available on the web, just not in your IDE.

The IDE should just do all of this for you. Choose your board from a gigantic list downloaded from the internet. This list includes detailed specs on every known board, updated as new boards are made. You can refer to the board specs in a side pane, and even correlate the pins in your sketch with the pins on the board reference. This isn’t rocket science folks!

So you can see, there’s good reasons for a new IDE. This is before I’ve gotten to forward looking features like a built in Firmata client or data analysis tools. It’s time. Let’s build this.

Now for something completely different

Two years ago I tried by recreating the IDE in the same form. Now I want to do something different. I’ve started a new IDE completely from scratch, written in NodeJS and HTML. While it does use web rendering it won’t be a cloud based IDE. It will still run locally as an app, but using newer GUI technology than Java Swing. Don’t worry, you’ll have a proper app icon and everything. You won’t know it’s NodeJS underneath. It’ll just be a nice looking GUI.

Since it’s a back to basics effort I’m calling this new tool Electron, the fundamental particle of electronics.

So far I have basic editing, compiling, and uploading working for an Uno. I’ve also built a system for getting installing libraries and board definitions from the Internet using a git repo. This separate repo will contain a JSON file for every known library and board. Currently it has the basics from boards.txt and a few libs that I use, but more will come online soon. If you want to help, adding to this data repo is the easiest way to start. Pull requests welcome.

Electron IDE repo

Arduino Data repo

Here’s a rough screenshot. The GUI will greatly change between now and the 1.0 release, so just think of this as a guideline of the final look.

If you are a Node/HTML hacker please get in touch. There’s tons of work to do. Even if you are just an Arduino user you can help by providing feature requests and testing, testing, testing.

Thank you. Let’s bring Arduino development into the 21st century.

I’ve been using Node JS off and on for the past few years, ever since we used it in webOS, but I’ve really gotten to go deep recently. As part of my learning I’ve finally started digging into Streams, perhaps one of the coolest unknown features of Node.

If you don’t already know, Node JS is a server side framework built on JavaScript running in the V8 engine, the JS engine from Chrome, combined with libuv, a fast IO framework in C++. Node JS is single threaded, but this doesn’t cause a problem must most server side tasks are IO bound, or at least the ones people use Node for (you can bind to C++ code if you really need to).

Node does it’s magic by making almost all IO function calls asynchronous. When you call an IO function like readFile() you must also give it a callback function, or else attach some event handlers. The native side then performs the IO work, calling your code back when it’s done.

This callback system works reasonably well, but for complex IO operations you may end up with hard to under stand deeply nested code; known in the Node world as ‘callback hell’. There are some 3rd party utilities that can help, such as the ‘async’ module, but for pure IO another option is streams.

A stream is just what it sounds like from any other language. An array of data that you operate on as data arrives or is requested. Here’s a quick example. To copy a file you could do this:

var fs = require('fs');
fs.readFile('a.txt',function(err, data) {
     fs.writeFile('b.txt',data);
});

That will work okay, but all of the data has to be loaded into memory. For a large file you’ll be wasting massive amounts of memory and increase latency if you were trying to send that file on to a client. Instead you could do it with events:

var fs = require('fs');
var infile = fs.createReadStream('a.jpg');
var outfile = fs.createWriteStream('b.jpg');
infile.on('data',function(data) {
     outfile.write(data);
});
infile.on('close', function() {
     outfile.close();
});

Now we are processing the data in chunks, but that’s still a lot of boilerplate code to write. Streams can do this for you with the pipe function:

fs.createReadStream('a.jpg').pipe(fs.createWriteStream('b.jpg'));

All of the work will be done asynchronously and we have no extra variables floating around. Even better, the pipe function is smart enough to buffer properly. If the read or write stream is slow (network latency perhaps), then it will only read as much as needed at the time. You can pretty much just set it and forget it.

There’s one really cool thing about streams. Well, actually two. First, more and more Node APIs are starting to support streams. You can stream to or from a socket, or from an HTTP GET request to a POST on another server. You can add transform streams for compression or encryption. There’s even utility libraries which can perform regex transformations to your streams of data. It’s really quite handy.

The second cool thing, is that you can still use events with piped streams. Let’s get into some more useful examples:

I want to download a file from a web server. I can do it like this.

var fs = require('fs');
var http = require('http');

var req = http.get('http://foo.com/bigfile.tar.gz');
req.on('connect', function(res) {
     res.pipe(fs.createWriteStream('bigfile.tar.gz'));
});

That will stream the get request right into a file on disk.

Now suppose we want to uncompress the file as well. Easy peasy:

var req = http.get('http://foo.com/bigfile.tar.gz');
req.on('response', function(res) {
    res
        .pipe(zlib.createGunzip())
        .pipe(tar.Extract({path:'/tmp', strip: 1}))
});

Note that zlib is a built-in nodejs module, but tar is an open source one you’ll need to get with npm.

Now suppose you want to print the progress while it happens. We can get the file size from the http header, then add a listener for data events.

var req = http.get('http://foo.com/bigfile.tar.gz');
req.on('response', function(res) {
    var total = res.headers['content-length']; //total byte length
    var count = 0;
    res.on('data', function(data) {
        count += data.length;
        console.log(count/total*100);
        })
        .pipe(zlib.createGunzip())
        .pipe(tar.Extract({path:'/tmp', strip: 1}))
        .on('close',function() {
            console.log('finished downloading');
        });
});

Streams and pipes are really awesome. For more details and other libraries that can do cool things with Streams, check out this Streams Handbook.

It's the fashionable thing to speculate on future Apple products. One idea that continues to get traction is the Apple TV, a complete TV set with integrated Apple-ly features. Supposedly to be announced this fall, after failing to appear at any event for the past three years, it will revolutionize up the TV market, cure global warming, and cause puppies and kittens to slide down rainbows in joy.

I don't buy it. I don't think Apple will make a TV. Televisions are low margin devices with high capital costs. Most of the current manufacturers barely break even.

Furthermore, the market is saturated. Pretty much anyone in the rich world who wants a TV has one. Apple needs growth opportunities. The last thing they need is a new product with an upgrade cycle at least twice as long as desktop computers. It doesn't make sense.

All that said, speculating about products is a useful mental exercise. It sharpens the mind and helps you focus when working on real products. So here we go:

If Apple Made a TV, How Would They Do It?

First let's take care of the exterior. In Apple fashion it would be pretty and slender. Either a nice brushed aluminum frame like the current iMac or a nearly invisible bezel. I suspect they will encourage wall mounting so the TV appears to just float. The current Apple set top box will be integrated, as will network connections, usb, etc. Nothing to plug in except the power cord.

Next, we can assume the current Apple TV will become the interface for the whole device. A single remote with on screen controls for everything. While I love my Roku, I hate having to use one remote for the interface and a second for power and volume.

Third, they will probably add a TV app store. I don't think it will feature much in the way of games and traditional apps. Rather, much like the Roku, there will be apps for each channel or service. The current Apple TV essentially has this now with the NetFlix and HBO apps. The only difference would be opening the store up to more 3rd party devs.

I think we can assume this will another client of your digital hub. Apple already wants us to put all of our music, videos, and photos into

So far everything I've described can be done with the current Apple TV set-top box. So why build a TV. Again, I don't think they will; but if they would need to add something to the experience beyond simply integrating

First, a camera for FaceTime. Better yet, four of them, one in each corner of the screen. Four cameras would give you a wide field of view (with 3D capture as a bonus) that can track fast moving toddler as they move around the living room. This is perfect for video chatting with the grandparents.

Furthermore, there are modern (read: CPU intensive) vision algorithms that can synthesize a single image from multiple cameras. Right now the camera is always off to the side of the screen, so your eyes never meet when you look at the person on the other end. With these algorithms the Apple TV could create a synthetic image of you as if the camera was right in the middle of the TV. Combined with the wide field of view and a few software tricks we could finally have video phones done right. It would feel like the other person is right on the other side of your living room. It could even create parallax effects if you move around the room.

Video calls are a clear differentiator between the Apple TV and regular TVs, and something that a set top box alone couldn't do. I'm not sure it's enough to make the sale, though. What else?

How about the WWDC announcement of HomeKit? An AppleTV sure sounds like a good home hub for smart automation accessories. If you outfit your house with smart locks, door cameras, security systems, and air conditioners, I can see the TV being a nice place to see the overview. Imagine someone comes to the door while you are watching a show. The show scales down to corner while a security camera view appears on the other screen. You can choose to respond or pretend you aren't home. If it's a UPS guy you can ask them to leave it on the front door.

I imagine the integration could go further. Apple also announced HealthKit. The Apple TV becomes a big screen interface into your cloud of Apple stuff, including your health data. What happens if you combine wearable sensors with an Apple TV. See a live map of people in the house, ala HP's Marauders Map. An exercise app can take you through a morning routine using both the cameras and a FitBit to measure your vitals.

A TV really could become another useful screen in your home, something more than just a video portal. I think the idea has a lot of potential. However, other than a camera and microphones almost everything I've detailed above could be done with a beefed up standalone Apple TV set top box. I still don't think a full TV makes sense.