Showing posts with label diy. Show all posts
Showing posts with label diy. Show all posts

Tuesday, May 19, 2015

Electro-Legos

My oldest son is almost seven years old. Seven is right about when I got my first Atari 800XL and learned to program. Today's kids have much cooler choices for computers. Personally, I think that the ability for programs to interact with the physical world makes a huge difference in motivation.
I recently backed up a Kickstarter campaign for the Espruino Pico. While being "yet another" small microcontroller-based board, this one has quite a neat software stack: it runs a JavaScript interpreter and exposes a very extensive JavaScript API for controlling its I/O. I was thinking this would make a great tool for super-quick hacks that I sometimes need for testing purposes / one-off tooling. But quickly it dawned on me that this would be a perfect way to get my son into programming! The Espruino has an IDE that is a Chrome extension with Blockly support, allowing us to code without having to do much typing and without risking syntax errors (which is often a big source of frustration for beginners). I also found that it was fairly easy to add new blocks, so I quickly made a couple of useful ones (for example, there wasn't a stock block for controlling a servo).
And so we've been playing for a while, controlling the on-board LEDs with the on-board button, and later adding a servo motor. But blinking LEDs and moving a servo for their own sake gets boring after a while. Luckily, the tooth-fairy has kindly provided us with a kit of accessories which greatly extends the possibilities! Since my son loves Legos (who doesn't?), my idea was to allow him to embed the I/O devices in his creations. Not a new concept, but mine was totally DYI, taking only a few hours of work in my garage and costing next to nothing.
The kit I made (shhhhh, don't tell it was me!) contains:

  • A micro servo, fitted with 2x2 Lego bricks on the top and bottom with correct alignment and a 1x4 brick on the arm. I used Gorilla glue for attaching the bricks to the servo, then "cast" the thing in hot glue for extra strength and cleaner shape. For alignment, I built a Lego fixture that held everything in place while the glue dries. For the casting, I found a cool trick you can do with hot glue: I pressed the workpiece with the molten glue against a piece of parchment paper placed on the desk. Once cool, the hot glue easily separates from the parchment paper, resulting in a really clean, flat surface.
  • A selection of LEDs. I found that the "technic" lego pieces have holes that are the perfect size for a 5mm LED. With a bit pressure it goes all the way in and will never come out. I made a set including: a double-LED (red, green) piece, an auto-color-changing LED piece and an RGB LED piece. I soldered the appropriate (for 3.3V) current-limiting resistors to the back of all LEDs to make hook-up simpler for my son.
  • Two push-buttons. It turns out those through-hole push-buttons fit perfectly between the bumps of a 2x2 piece, when placed diagonally. A dab of Gorilla glue, and we're done.
I'm really happy with the result and if it works out well I can easily add more pieces.
Here's what happens when you let dad play with the kids' toys...





Sunday, October 20, 2013

Who Wants a IOIO-OTG for $30?



No, this is picture not a negative: it's the new IOIO-OTG from SeeedStudio!

What's new?


  • It's black.
  • It's selling for $30, including male and female headers and a USB-OTG cable.
Otherwise it's exactly the same.

Why?


Since I set out to develop the IOIO-OTG I had a goal of making the end-user price be $30. For various reasons that didn't quite work out on the first attempt, but I kept pursuing this goal, with the belief that this is the right price for it. I got strong recommendations on SeeedStudio from Shenzhen, China and soon contacted them with an offer. I was not disappointed! They were very enthusiastic to collaborate and very professional. Working together with them, I closely inspected their manufacturing and testing procedures and I'm happy to report that the quality of their boards meets my highest standards, and I feel that they are very serious and committed to quality and user happiness.
We decided to make it black in order to differentiate it from the existing boards and get people's attention. I also personally love the way it came out looking.
So a big shout-out to those guys for all their hard and excellent work, and I encourage you to support them and the healthy competition they are bringing.

What's next for IOIO?

I'm now working full-steam on the next software release. It will include:
  • The motor control library mentioned on my previous post. Took me a while to get it from "working" to "polished" state.
  • The IOIO-OTG can also work as a USB slave with Android devices that support USB-OTG. That means that the IOIO can be powered by the Android without needing an external power source. This is a contribution by my friends Misha and Nadir (thanks!).
  • Some bug fixes and cleanup.
I'm also planning a small hardware revision that will add some improved protection against input voltage surges. My friends from Seeed drew my attention to a subtle problem with the current design which I'm intending to fix with that. Stay tuned!

Tuesday, May 14, 2013

IOIO Plotter and the Motor Control Library


This is the story of how I built my Android/IOIO/OpenCV-based interactive plotter, as well as the soon-to-be-released motor control library for the IOIO. I'll tell the story of the plotter from the bottom up, which is the order in which I've designed and built it. But before diving into the geeky technical details, a few words about the final product.
It started with me looking for a cool example application for the motor control library I was about to develop for the IOIO, and have this application something I can present in Maker Faire. I wanted it to demonstrate the ability to control some multi-axis machine in a simple, reliable and precise way using high-level Java code running on an Android or a PC. I finally decided on the plotter, as it seemed like a fun thing to make as well as an interesting piece to exhibit. The plotter is based on a very elegant design, which unfortunately isn't my idea (just Google for "whiteboard plotter"). Since building yet-another-one is boring, I wanted to make this one with a twist, taking advantage of the fact that I can easily put an Android device in the system. So my plotter is interactive in that you take a picture with it and it would immediately convert it to paths (via edge detection) and plot them.
Now we're ready for the geeky stuff :)

Ultra-Productive Development Environment

My friend and colleague Anton Staaf, has introduced me to a really cool development strategy he's been using on his projects. He developed this nice little "shell" library, which is essentially a simplified, very portable command shell, to which it is very easy to add new commands. I borrowed his code, and ported it to the PIC24, using the USB CDC as the underlying serial link. Shortly after, I had a IOIO board which I could plug into the USB port of my PC, open a "screen" session to and run commands to exercise whichever new features I'm working on. Combined with the device-mode bootloader of the IOIO-OTG, I was able to have super fast cycles of code-compile-flash-test. It was really fun to work like that. I'm hoping to eventually release this shell-app for the IOIO for others to hack with - it's totally awesome!
Another tool which served me really well here is the XProtoLab from Gabotronics. Since this library is all about generating perfectly synchronized, precisely-timed signals, I needed a way to validate the output signals. I don't have a scope or a digital analyzer, but the XProtoLab is a tiny, beautifully designed, tiny oscilloscope, logic analyzer and signal generator. I bought this one second hand for $30 a while back and it is worth its weight in gold. Highly recommended!
Now I was in good position to start playing around with some ideas for how my library will work, which I eventually ported into the proper IOIO app firmware.

H-A-R-D-R-E-A-L-T-I-M-E

OK, so I develop realtime software for a living, but I never before got to this level of realtime...
I initially drafted the following design principles:

  • The IOIO will play the role of a sequencer. It will have a buffer of "cues", which keeps getting filled by the client (Android or PC). Those cues are essentially "over this period of time, I want this channel to do this and that channel to do that". A channel can be for example a stepper motor pulse train, a PWM signal for a DC motor or a servo or a digital output pin.
  • As usual with the IOIO library, I want this to happen with as little as possible CPU intervention, so that it can run in parallel with all the other IOIO functions. So I decided I'll use the output compare modules for generating all the pulse signals and a timer for timing the cues.
  • But stepper signals are slightly tricky, as you want a precise number of steps over the period of the cue. Not one too many, not one too little. Ever. So one might generate those pulses one-by-one, but that would place a lot of burden on the CPU and would be very difficult to time correctly when multiple channels are involved. So I decided I'll just let the pulse trains run freely during a cue, and just be really really precise about stopping them at the right time, before they generate an extra pulse.
So, OK, one might think that setting a timer to interrupt at the highest possible priority should suffice, but it really doesn't, unless you want to be really way too conservative with how close you allow your last step in every cue to get to the cue point. But that would put a very serious limitation on the maximum pulse rate, which I didn't want to do.
It took my some time to convince myself that C can't cut it. You just can't really know how many cycles your code is going to take. And even if you could, this could change the next time you upgrade your compiler. So I reverted to assembly. It was actually a lot more fun than I expected, after not having done this for years. And the end-result is something I'm really really happy with! Cycle-accurate timings for everything. I know exactly when each instruction runs with respect to the output waveforms and everything is super-fast, so it doesn't place any significant overhead on the CPU. You can do up to about 30KHz signals, up to 9 such in parallel, in addition to twenty-something binary outputs (e.g. for controlling the stepper direction, solenoids, or LEDs), without ever missing a step jittering on the timing by as little as one CPU cycle.
Of course, it took me about 10 times to complete than it would have in C...
Here's a little (underground) video I shared a while ago, demonstrating some early stages of the motor control library:

Protocol Glue

From this point, bootstrapping this library to the IOIO protocol was pretty straightforward, and shortly after I had a semi-baked Java API for feeding the sequencer. The current API is pretty bare-metal, and I'm thinking about providing it with some higher level abstraction layer when I release it, or at least a decent set of handy utilities. For the time being, I developed some utilities that are specific to stepper motors, which is what I needed for the plotter.

Plotter Design

Finally came the time to make the plotter. The design is pretty simple: two pulleys driven by stepper motors controlling the length of two strings. The two strings are joined in one point attached to the carriage. A rather simple geometric transformation can tell you how long you want each of the strings to be in order to get the carriage to a given point on the sheet in XY coordinates.

On the carriage is a sharpie. In order to minimize the effect of the carriage swinging on the position of the tip of the sharpie, the hanging point, where the strings connect needs to be as close as possible to the tip. This way, even if the carriage tilts a little, the tip won't deviate by a whole lot.


I found a neat little trick for the carriage design: when drawing, the carriage is supported by two ball casters and the tip of the sharpie. This way the sharpie stays perpendicular to the sheet. In order to raise the sharpie (for moving the carriage without plotting), a third ball caster is mounted on an actuated linear bearing, driven by a small hobby servo. The servo can push this third caster into the sheet, so that it is "deeper" than the tip of the sharpie, thus causing the carriage to be supported on the three casters and the sharpie tip to float.
Oh, and remember that I just used the fancy term "linear bearing", causing you to imagine some precision machined awesomeness? Think more like a piece of a shampoo bottle pump in this case :) What can I say, I just hate waiting for parts to arrive or worry about how to fabricate the perfect bearing, when all I really care about is getting this app up and running...


Another little trick I found is for mounting the main assembly (with the motors and pulleys) on the easel: I used some square pieces of plastic, originally intended for hot cups, and bent them with the hot air gun I used for soldering. It ended up pretty cool, and I can easily unmount the thing for transportation.
And of course, the IOIO is mounted on the front, and a pair of DRV8825 stepper drivers behind it to help with the heavy-lifting. I dialed them to about 1A per motor, which seems to work well.


Now, Plot!

There's this part in a project when the hardware is pretty much done and now it's all "just a simple matter of software", as my friend Ed likes to joke. But at this point, having all these million layers of infrastructure at my disposal, I just couldn't wait to draw something with it and see if it's any good. For all I know, I might have a million problems hidden. I coded like crazy for a couple of days, until finally plotting a first circle! Well, let's call it circle-ish, since it did uncover some small mechanical issues that needed addressing. But pretty much, the entire stack of electronics and software worked flawlessly! I wrote some basic utilities to do the coordinate transformations and to expose a high-level Plotter API, which gets an arbitrary list of paths, each represented by x(t), y(t) and plots them.

Pimp Your Plotter



Since this piece is to be presented, some aesthetics can't hurt. I coincidentally noticed that the pulleys look a lot like yo-yo's and decided to have fun with this concept. My friend Ali took me for an awesome tour in his workshop and let me cut some pieces of MDF on his laser cutter. It's funny that the only precision part in this entire system is the decoration :D

Finally: The App Layer

So many layers on layers on layers, I finally had a working plotter and it was time for the application. It's been a long time since I wanted to get my hands dirty with OpenCV for Android. It is 100% pure awesome! Makes image manipulation and standard computer vision algorithms really simple to implement. I developed a simple GUI that allows you to pick a picture from your Android gallery (local  storage, Web albums or capture an image from the camera), and then interactively tweak the parameters of a Canny edge detector. The detected edges are displayed in red against a grayscale image, so you can easily see what result you are going to get and keep moving the sliders until you're happy.thinning the resulting edges, or otherwise a single edge may actually be two-pixel thick at times, which makes it really annoying to convert into paths. I used the algorithm proposed here (thanks, guys!) and implemented it pretty easily with OpenCV. Last, I needed to trace the edges into paths. I did this step pretty dumbly, because I started to run out of time and juice. In the future, it could be pretty nice to:

Then, I found that an essential step I needed to take is

  • Smooth the edges rather than just connect pixels coordinates with straight lines. A nice algorithm to borrow ideas from is here.
  • Be clever about the ordering of paths within an image, so that to attempt minimize the total length of travel of the carriage. In the current implementation, the ordering is pretty stupid, causing the carriage to move from side to side way more than is necessary, significantly slowing down the process.

Aftermath

This weekend I'm going to present this project, along with some other IOIO projects in the Maker Faire Bay Area 2013. If you happen to be around, drop by to say hi. Special thanks to my good friend Al Linke, who made the video shown at the top. Al has made some awesome IOIO-based projects himself, and is going to share the booth with me in Maker Faire.

I intend to release the motor control library within a few weeks for everybody to enjoy. I hope it will pave the way for driving 3D printers and other CNC machines with a IOIO/Android combo, which seems to me like an elegant way for giving these machines a great user interface, standalone computing and connectivity on the cheap.

Some more fun pictures for those who persisted this far.

Sunday, June 5, 2011

IOIO over OpenAccessory (ADK) Available

About two months ago, I've announced IOIO on this blog. About a month later, in Google I/O, Google announced the OpenAccessory and the Accessory Developer's Kit (ADK), which enables connecting your Android device (version 2.3.4 and higher) to external peripherals. Today, I'm announcing IOIO's support of the OpenAccessory protocol!

This new feature is currently released in Beta mode. Technical information available on the IOIO wiki. The way this works is that IOIO will attempt to communicate with the Android device with the OpenAccessory protocol. When this is not supported, it will seamlessly fall back to ADB. This enables you to connect the same IOIO board to both new and old devices. Your applications can be very easily be ported to the new mode, requiring only a few non-intrusive modifications to your application's metadata.

What is this all about? What is the relation between this new technology, IOIO and the other boards out there? I will try to provide some answers and clear some of the confusion that was caused as result of the proximity of all these announcements.

What is OpenAccessory?

OpenAccessory is a new Android feature, which enables connecting external peripherals to an Android device over a USB connection. This feature exposes a standardized interface on the USB bus, as well as a Java API that enables an Android application to communicate with the accessory on the other end. This feature is supported on Android 2.3.4 and higher. The OpenAccessory protocol allows the Android device to act as either a host or a device on the USB bus (the host mode is only supported on Android 3.x and higher and only on certain devices).
OpenAccessory is a low-level protocol: it features a single full-duplex communication channel between the Android device and the accessory, over which arbitrary bytes can be sent back and forth - much like a UART connection. It leaves to the accessory designer to design the higher-level protocol, i.e. what messages to send and what their meaning is to the Android application and to the accessory.
Read more about OpenAccessory here.

What is ADK?

The Accessory Developer's Kit (ADK) is a reference implementation of an OpenAccessory-enabled board, developed by Google and announced together with OpenAccessory. This board is essentially an Arduino Mega with an on-board USB host shield. It comes with an Arduino-side C++ library, which implements the protocol. Following Google, several vendors have released compatible boards.
The term "ADK" is often used synonymously with "OpenAccessory", i.e. one might say "this new board supports ADK" when they actually mean it supports the OpenAccessory protocol.
In my personal opinion, the ADK has been released mostly for promoting the OpenAccessory protocol and providing a quick-start and demo board, rather than intended to be a consumer product.

How Does OpenAccessory Compare to ADB?

The Android Debug Bridge (ADB) is a debug protocol which existed on every Android device since the early days of Android. Technically, this protocol allows a host connected over USB to open various kinds of communication channels to the Android device. On the Android-side of these communication channels are different services, such as debug, file-system access, Linux shell access. Another note-worthy service (on which IOIO has been based) allows forwarding of the data sent over the channel to a TCP socket. This allows an Android application to listen on a certain port and accept connections coming from the outside world, and do so without the need to modify the OS.
ADB's main advantages over OpenAccessory are:
  • Available on any Android device.
  • Provides useful features, such as file-system access (IOIO uses this for firmware upgrades).
  • More mature, does not suffer from some problems currently existing in OpenAccessory.
  • Simpler to work with on the Android application side - just listen on a TCP socket.
OpenAccessory's main advantages over ADB are:
  • Better throughput and latency.
  • Does not require the user to enable USB debugging.
  • More secure (IOIO takes its own measures to guarantee that the power of ADB cannot be exploited by a malicious firmware).
  • Allows applications to be notified upon connection of the accessory. The user can choose which application to launch when the accessory connects. This might be doable with ADB too, but IOIO doesn't do that.
See Inopia's excellent in-depth comparison here.

How Does IOIO Compare to Other OpenAccessory-Enabled Boards?


  • Supports All Android Versions - since IOIO works with both OpenAccessory and ADB it can communicate with a very large variety of existing Android devices, leveraging OpenAccessory when it exists and leveraging the additional features of ADB when they exist. Other boards, which do not support ADB, are limited to all but the newest Android devices out there.
  • Functionality - IOIO is almost exactly identical to the Arduino Mega in terms of pin counts and functions. The only difference I could spot is in the number of PWM channels (IOIO-9, Mega-16) and TWI channels (IOIO-3, Mega-1).
  • Cost - at $50, IOIO currently seems to be the cheapest available commercial board out there. A close alternative is a DIY version offered here, costing $55 and requires some work.
  • High-Level Software - the other boards out there expect you to write both an Android application and embedded-C code for the board, designing your own communication protocol. IOIO does all that for you, leaving you to write only the Android-side code, while using a high-level Java API for controlling the board's functions.
  • Support Forum and Wiki - IOIO has an active discussion group and an extensive documentation wiki, which continues to grow quickly. The IOIO project is committed to the hobbyist community, and to the hobbyist community only!
  • Size - IOIO is probably the smallest board out there - almost as small as you could get with 48 I/O pins, numerous supply pins and a USB connector. It is much smaller than the ADK board.
  • Bootloader - IOIO's firmware includes a secure bootloader, which enables firmware upgrades to be performed through the Android device.
  • Power Supply - IOIO has an on-board 5V switch-mode regulator capable of delivering up to 1.5A. This allows for simultaneous charging of the Android and powering two standard servos without problem. Some of the other boards will require an external 5V supply to support this use-case. In addition, IOIO has an on-board trimmer which allows limiting the Android's charging current. This is very useful for battery-operated setups, when you don't want the Android device to drain your battery.
  • Open-Source - Unlike some of the other alternatives - the IOIO's hardware, firmware and software are completely open-source with a FreeBSD license (very permissive). This approach has been chosen because I believe this is what works best for the hobbyist community, and allows people to customize the product for their needs, contribute to it, understand it best, compete on its pricing.
In conclusion, despite my obvious bias, I believe IOIO is very competitive with other OpenAccessory-enabled platforms. To be fair, here is another view.

Tuesday, April 13, 2010

PICMAN

For a long time now I've been wanting to make my own microcontroller-based prototyping board. My original motivation was the unjustified high costs for even the simplest boards (a basic Arduino for $30 - why???) and the challenge of designing something that anyone can make at home within a few hours, with parts that can be cheaply obtained on eBay.

Eventually, I came up with the PICMAN. It is:

  • Based on Microchip's PIC18LF4553 - a 12MIPS microcontroller with 12-bit A/D, plenty of I/O, built in USB transceiver and tons of other coolness.
  • A single-layer PCB design - ideal for DIY toner-transfer etching fabrication.
  • Small form-factor that nicely fits on a solderless breadboard.
  • Can be powered by USB/external 5V/external 8V-35V using on-board 1.5A regulator.
  • Has a reset button, a user button a power LED (blue) and 3 user LEDs (red, yellow, green).
  • Needs zero external components to work.
  • Programmed with a bootloader, making it possible to download a program via USB.
  • Can implement any USB device using Microchip's USB stack.
  • Less than $7 total with easily obtainable parts (not including shipping costs, which are usually low if not free, and assuming that some of the small parts are bought in quantities).
I made two pieces so far, each took a couple of hours' work, requiring some SMD soldering experience. I did the initial programming (bootloader image) with a PICKit2 programmer, after having to struggle a little with the Microchip provided bootloader firmware code. It really works nicely - I like it much better than most Arduinos that cost 5+ times as much and it was really fun to build.
Some ideas that I used in the design:
  • Mount the PIC at the bottom of the board, between the header pins.
  • Use the copper layer for text to make it easier to locate individual pins.
  • Use a mini-B USB connector for smaller form factor (than B) and availability of cables.
Some assorted design/fabrication tips:
  • Edit the final PostScript file generated by Eagle with a text editor, replacing the last number in every line ending with "h" with 2000. This effectively resizes all holes to 0.2mm making them perfect for centering the drill bit.
  • Add a cool logo on the final PDF with Illustrator.
  • Print in 1200DPI on a transparency with a laser printer.
  • Cut board with a large paper Guillotine.
  • Use lamination machine for toner transfer. Let fully cool in air before gently removing transparency. Verify before etching, or otherwise scrape off toner and retry.
  • 1 part HCl, 2 parts 3% H2O2 for etching.
  • Final cutting of the board to shape with tin snips.
  • 0.6mm holes for PIC and ceramic capacitor, 1mm holes for L7805 and all mounting holes (switch and USB jack), 0.8mm holes for the rest.
  • 1k resistor for the green LED makes it just as bright as the other ones with 330 resistors.
  • Solder USB jack first. Have a lot of patience ready.

Here is the schematic, the layout and the final artwork (mirrored). The Eagle files, firmware images and programming software can be downloaded from here. I'll happily share eBay links, where all these components can be bought cheaply, just ask if you can't find any of them.
If anyone has any constructive comments, or has built one and wants to share it, feel free to comment below.