Rethinking Arduino: A review

I’ll admit it, I was wrong. I’m an engineer by profession, and one for whom designing a microcontroller-based PC board is old hat. I used to look down my nose at Arduino. Its populist appeal and simplified programming language made it a toy in my eyes. I have worked with other boards with similar goals of broad appeal that were poorly designed, with compromises that made the boards unusuable or that overstressed components, making them unreliable. Above all though, “real” engineers design boards for microcontrollers, and they program the microcontrollers using JTAG connections and arcane syntax — or so I thought.

Arduino Uno circuit board

Then a few weeks ago, I was given an Arduino. My perspective has shifted. Arduinos may be populist, they may be the Radio Shack Engineer’s Notebook of the microcontroller world, but they’re also well-designed development boards worthy of any engineer’s attention.

My Arduino came as part of a Sparkfun starter kit, which includes a breadboard, hookup wires, an RGB LED, packs of 1K and 10K resistors, and some fun sensors to play with, including a touch-sensitive resistor and a bend sensor. It amounts to a microcontroller-based building set, and would particularly appeal to anyone who wants to experiment with microcontrollers without having a specific project in mind. Though my son and daughter will be too young for the kit for a few more years, it caught my eye as exactly the sort of thing I might give to one of them to help them learn about what goes on inside a computer.

Sparkfun Starter Kit contents

I set the accessories aside and focused on the Arduino, an Uno model in this kit. Arduino’s current foundation model, the Uno includes a Atmel Atmega328 microcontroller, on-board power supplies (5V and 3.3V), a USB serial interface, a general-purpose LED, and female sockets that break out the microcontroller pins.

The Atmel processor is surprisingly speedy. It has an 8-bit CPU running at 16 MHz, which was plenty of processing power for the things I was trying to do. Perhaps the biggest limitation of the processor is its 2K of RAM. The 32K of flash on-board is great, and conservative programming techniques can fit a surprising amount of functionality into 2K of RAM, but sometimes it’s easier and faster to use a controller with more RAM.

The USB serial interface was a surprise as well. It is implemented by a second, smaller Atmel CPU, programmed to operate as USB-to-serial interface chip akin to the popular FTDI FT232 family. According to Arduino’s creators, the Atmel CPU was less expensive than the FTDI equivalent. Beyond being an interface, the second CPU has a USB bootloader and an ICSP (in-circuit serial programming) header of its own, so it can be reprogrammed just like the Atmega328. The USB CPU is in a tiny QFN package, and most of its I/O lines are not brought out. Still, the ability to reprogram it opens up a lot of interesting possibilities.

Arduino’s native programming environment uses a simplified C-like language. Since I’m comfortable with standard C and prefer test-driven development, I followed Nick Christensen’s detailed instructions on how to set up an Arduino development environment with gcc, Unity, and CMock. The gcc compiler is an industry standard tool these days, and I like Unity and CMock for unit testing.

Then I found out I was a snob. The Arduino wasn’t a toy. As I dug into its schematic and capabilities, I found a well-designed little development board. It was designed with cost-reduction in mind, for sure, but without losing sight of giving access to the entire capabilities of the processor. One processor pin drives an LED, for instance, but that line is also brought out to a header, making it available for other uses. The analog input pins are brought out without analog buffering, so they are available for digital I/O. Even the serial interface pins used to download code over USB can be repurposed.

There are other low-cost development boards, some directly competing with Arduino and others aiming for a slightly different audience. Here Arduino’s advantage is its popularity. Between Radio Shack and Micro Center, I can buy an original or cloned Arduino at retail from at least four stores within three miles of my house. That is surely not true for the entire world, but Arduino and software-compatible clones are also readily available online.

For my last small project, when I needed a microcontroller, I picked an inexpensive MSP430F2011 because TI’s EZ430 USB stick (which was a freebie from TI) could serve as the programmer. Next time, there’s a good chance I will use a genuine Arduino, one of the clones, or maybe just use these development tools with a plain Atmega328.

Yep, Arduino is worth a look, even for those used to the traditional “professional” world of microcontroller design.

Itead Studio’s Open PCB exchange: how it worked out

The boards I ordered last month from Itead Studio arrived with something extra: someone else’s boards! No, it was not a mistake, but a 10-cent option that I could not resist: the Open PCB service. For 10 cents above the cost of a prototype PCB order, Itead fabbed two extra boards of my design. Those boards went into a pool of boards from the other Open PCB participants, then Itead sent each of us two random boards from the pool. All participating boards are supposed to be open source. Sure, there is no guarantee that the boards will be at all useful to the recipient, but who knows, maybe something nifty will arrive!

I ordered the Open PCB option with my AK5388 ADC board. Along with my 8 copies of the board, I received two boards from strangers. Both are 5 cm x 5 cm, which is likely a popular size for Itead because it’s the maximum size for their cheapest PCB fab deals.

Boston University Rocket Team thermocouple digitizer PCB, top side Rocket team's thermocouple digitizer PCB, bottom side

The first board is a thermocouple digitizer from the Boston University Rocket Team. The team has posted the schematics, layout, and Gerbers online on GitHub. The board was clearly labelled, making it easy to find the documentation in Google. It even had a QR code. though the pixels were blurred by the silkscreen and my phone was unable to read it. It’s a great idea for open source hardware, though, and would probably work if it were a little bigger.

The design uses a single MAX31855 as a thermocouple-to-digital converter. This is a neat chip that contains a thermocouple amplifier, cold-junction compensation, and a 14-bit ADC all in an 8-pin SOIC. That’s a ton of analog circuitry condensed into a single chip! It can cover temperatures from near absolute zero to molten metal, with quite respectable accuracy and resolution.  The board runs the chip’s Serial Peripheral Interface (SPI) to a USB 3 connector, wired in a non-standard way that carries power (12V, 5V, and 3.3V) and an SPI bus.

The Rocket Team has chosen an interesting mission. They don’t fly rockets, but rather research the design and performance of hybrid rocket motors, including firing them on a static test stand. They build their own instrumentation, all open source hardware, and this board is part of that package. I can see why they would be interested in accurately measuing the temperature of very cold and very hot things!

The board actually has some potential to be useful to me. I don’t need a thermocouple interface right now, but I can imagine using for one down the road to monitor a reflow oven or to manage the heatsink temperature in a linear amp.

Ville K's board, top side  Ville K's flash power control board, bottom side

The second board is a bit of a mystery.

On first inspection, I was puzzled by the single-row header right across the middle and the smaller row of holes at the upper-left side. Eventually I noticed that there are no traces running to either, so it’s likely that they are perforations to simplify cutting the board into three pieces.

The bottom portion is the least obscure. It bears the labels “Flash power control” and “X-SYNC”, so it must have something to do with photo flash. Beyond that, I’m stumped. A two-pin header for an IGBT (a three-terminal device) particularly leaves me scratching my head. The designer did a nice job of bonding his top-side ground pour to the bottom-side ground plane with plenty of vias, including all around the edge of the board.

On the upper right, there are two copies of a circuit, separated by a row of holes to aid breaking them apart. The circuit has a transistor in SOT-23, a diode, a few capacitors, a resistor, and what is likely an IC in a small 5-pin package. Looking at the topology, I think the circuit is a boost converter, at least if the unlabeled two-pad component on the center left is an inductor.

The patterns in the upper right corner are even harder to understand. They look like series chains of something, maybe resistors or LEDs. The vias in the pads and the wide traces indicate that the designer was concerned about resistance, inductance, or heat dissipation. Since the three-device chain (upper center of the board) has the triple vias to back-side copper, but does not use the copper to interconnect, I would guess heat sinking is the concern. It could be a challenge to reflow the board with the open vias in the pads, but it’s probably meant to be hand-soldered. When hand-soldering, one can keep feeding solder until the holes have wicked up their fill.

I sent some e-mail to the address in the silkscreen but got no reply. Google searches on other likely terms turned up nothing. I’m left with a board and guesses.

The Open PCB  exchange is a great idea, and I’ll happily participate again in the future. The thermocouple board is an example of how it can go right. I got a well-documented board that led me to find out about the Rocket Team’s interesting work. In contrast, the Flash Power Control board is an example of what can go wrong. There is nothing to stop someone from entering an undocumented PCB in the exchange, getting documented and interesting boards but failing to repay the favor. Still, I like seeing what other people are doing and hopefully two other people enjoyed seeing what I’m up to. For 10 cents, less than a 1% increment on the cost of a PCB order, it’s worth it.

Have you tried Open PCB, and how did it work out? Are you able to shed any light on the mystery board?  As always, comments are welcome!

Bus Pirate review

Sparkfun Bus Pirate, top viewThe Bus Pirate: It sounds kind of shady, and maybe it is, but it is also a handy little tool. A few weeks ago, I received a Sparkfun Bus Pirate as a birthday present. This little board is a USB-to-nearly-anything serial adapter that can speak SPI, I2C, async serial (UART), JTAG, and several other protocols. It’s designed as a quick tool for easy exploration of new hardware and, yes, as a hacking tool useful for reverse engineering undocumented boards and communications protocols. It has a few limitations that hold it back from being everything it could be, but the low price makes it a worthy addition to a professional’s or hobbyist’s engineering toolbox.

The Bus Pirate was designed by Ian Lesnet at Dangerous Prototypes, and he sells his original version via his partnership with Seeed Studio. Since it is an open source hardware design, others are free to make their own versions, which is what Sparkfun opted to do. It appears that Sparkfun did their own layout, but the major components are in roughly the same locations. Both versions are electrically equivalent and run the same firmware, and both versions cost about $30 (at this writing).

Bus Pirate Hardware and Accessories

On unpacking the box, my first surprise was the Bus Pirate’s small size. That’s not a drawback in practice, but it looks more delicate than I expected. The board has a row of LEDs along the top edge for status information, a USB mini-B connector on the left side, and a header for the serial interfaces on the right side. The header is shrouded, which is a nice touch, because it makes sure polarized cables only go in one way.

Polarization is great for cables, except that different versions of the Bus Pirate orient the header in opposite directions! The Sparkfun version has the polarization notch on the outside, while the Bus Pirate documentation says that some Seeed Studio versions have the polarization notch on the inside. Although this inversion means that pin “1” moves from one end to the other, the layout of the PC board has not changed, so the pin in the lower left corner remains chip select (CS), regardless of which way the header is installed.

Bottom view of Sparkfun Bus PirateI am a little concerned about the durability of the board. One aspect is having small surface-mount components exposed, where they could get knocked off, taking their PCB pads with them. Another aspect is the choice of a USB mini-B connector. The mini-B has durability issues that has caused the USB Forum to deprecate it in favor of their other connector styles. A standard B connector would have been a better choice.
Another disappointment was the lack of PCB mounting holes, which are handy for screwing in standoffs to use as feet. holes would also make it easier to protect the board in an enclosure, such as a mint tin.  It appears that the latest Seeed Studio Bus Pirate boards (v3.5) have mounting holes.

Sparkfun and Seeed both sell breakout cables for the board. These cables aren’t strictly necessary, and in fact you might find a fistful of single-pin jumpers more useful for many purposes. The header has a few pins that can be jumpered for special purposes, such as configuring a pullup voltage in open-drain/open-collector mode. The the breakout cable may make that more awkward in some circumstances. I found the breakout cable handy, though, and I would recommend it as an accessory. The Sparkfun cable has single-pin sockets on its loose leads.  Seeed sells a version with single-pin sockets and one with mini-grabbers.

SPI Sniffing

Although I wanted a Bus Pirate for my basement hacking, the day after I received it, I took it to work. I was debugging a tough problem for which it would be useful to be able to eavesdrop on SPI traffic between a microcontroller and a peripheral. The Bus Pirate’s SPI sniffer mode seemed perfect. (I did have the option of using an Agilent mixed-signal oscilloscope, but who wants to read hundreds of bytes, in binary, from a ‘scope screen when an easier option exists?)

In principle, SPI sniffing can be done from a terminal, but in practice, an SPIsniffer utility that uses the Bus Pirate in binary mode is recommended. I downloaded the SPIsniffer and had a tough time interpreting the output. It appears that the latest version was released with debugging code that causes duplicated bytes in the output. I removed the debugging code, recompiled, and had somewhat better success.
The SPI sniffer formats its output as “[0xba(0x00) 0x5e(0x00) 0x00(0x1e)]”. The square brackets show when chip select is active, and the bytes are shown as the MOSI value followed by the MISO value in parentheses. This format is basic, but easy to read. Getting the chip select brackets in the right place is critical to interpreting SPI traffic. Many chips use the first byte after chip select as a command or an address, and the following bytes as data. Without having chip select in the right place, it can be impossible to decipher the data stream.

Unfortunately, in my application, the chip select indications were all over. When watching an initialization sequence, which should have shown chip select low for each of a series of two-byte packets, and high in-between, the Bus Pirate showed many one-byte packets and a few with up to 10 bytes. I looked for ground loop problems and other issues that might throw it off, without success. An oscilloscope showed the two-byte packets, as expected. As best I can figure, the Bus Pirate was simply unable to keep up with the data stream and got its chip select reads out of sync with its serial data reads. The Bus Pirate did not drop any data bytes, but without accurate chip select information, it was as useless as if it had.

Would The Correct Logic Level Please Stand Up?

My SPI sniffing also brought to my attention the Bus Pirate’s less than ideal logic level selection. The Bus Pirate is billed as working with logic levels “at any voltage“, and “above and below the Bus Pirate’s 3.3V supply“. I thought this meant it incorporated a level shifter that could input and output all of the major logic levels used today, from 1.5V on up. Unfortunately, the truth is that the Bus Pirate runs at 3.3V with 5V-tolerant inputs. It does have the ability to use open-drain outputs with a strappable pull-up voltage, which could be anything from 0 V to 5V, but that does not change the input thresholds, which remain at standard 3.3V CMOS levels. Unfortunately, that means that logic running at 2.5V and below is not guaranteed to be read correctly by the Bus Pirate. Logic with a 1.5V supply simply won’t work.  (In fairness, there are other pages on the Dangerous Prototypes web site that correctly describe the Bus Pirate as supporting 3.3V and 5V I/O.)

This problem could be solved by incorporating a proper level shifter into the board or, with some constraints, by replacing the 3.3V regulator with a lower voltage version. The hobbyist market for which the device was designed rarely uses I/O voltages below 3.3V, so many typical users will not notice this limitation, at least for the next few years. However, the problem makes it harder to use the Bus Pirate as a reverse-engineering tool and for developing low-voltage designs.

A USB UART

The Bus Pirate includes a UART mode that lets it communicate with asynchronous serial, just like RS-232, but at logic levels. Conveniently, I’m currently working on a project that uses asynchronous serial at logic levels, but at an unusual baud rate. This was a great chance to try out the Bus Pirate.

In addition to all of the standard baud rates, UART mode accepts direct programming of the PIC’s baud rate generator. It was a simple matter to compute the right value for my project.

Unfortunately, though I was able to generate serial at the right baud rate and verify it on a ‘scope, I wasn’t able to get the Bus Pirate to work on receive. I had some noise problems with the system, and that coupled with the I/O voltage mismatch meant the receiver picked up garbage characters. I was in the midst of bringing up a custom USB-to-async converter to fill the same role, so I didn’t have much incentive to spend more time getting the Bus Pirate to work. I have since taken the time to eliminate the noise, so maybe the Bus Pirate would work now despite the logic-level mismatch. In any event, the problems on receive were my fault, not the Pirate’s.

Documentation

The Bus Pirate “manual” is a wiki. The strong point of using a wiki is that it is easy for the developers to update. It has some drawbacks, too. Like much hypertext documentation, there is no obvious way to read it linearly like a textbook, and it can be hard to be sure you have found all of the material relevant to a particular topic. Maybe I’m showing my age, but I would have liked to be able to download and archive a PDF, or perhaps even print and bind a manual with complete instructions for the Bus Pirate.

The documentation is concise to the point of terseness at times, but I was able to find all of the information I needed. The diagrams, in particular, are well done and clearly show exactly what needs to be conveyed.

Terminal Software

For some reason, the Bus Pirate did not work well with Windows’ Hyperterminal. From the wiki and forums, it seems this is not unusual. Following the manual’s recommendation, I switched to Tera Term and did not have any further problems.

More Cool Features

So far, I have only sampled the Bus Pirate’s capabilities. Among its cool features are a bitbang I/O mode that let the PC command each pin individually. Even in the SPI and other modes, it has an auxilary output pin that might be useful for a reset, address, or secondary chip select.

The Bus Pirate has two power supply outputs, one each at 5 V and 3.3 V, on its connector. Commands from the PC switch the supplies on and off, and there is enough current available to power small circuits. Some applications require little more than a Bus Pirate, a breadboard, and the target chip.

Analog signals can be read with the Bus Pirate’s ADC input pin. Together with the power supplies, this means that the Bus Pirate can directly connect to some analog sensors as well as the more obvious one-wire, I2C, and SPI devices.

It can even speak JTAG for debugging or programming, albeit slowly. It was not designed for JTAG and has to emulate the protocol in software.

The Bus Pirate also has a logic analyzer mode. SUMP and other software compatible with the Open Bench Logic Sniffer can interface to the Bus Pirate to read a few logic channels, slowly. It’s really just a toy in this mode, but I would have loved something like it when I was a kid experimenting with 4000-series CMOS.

Conclusions

I’m happy with my Bus Pirate. It is described as being a hacker’s multitool, and I have to agree. I love my Leatherman, too! I’m going to need longer to fully understand the Bus Pirate than to grok a Leatherman, but I’m looking forward to finding new ways to use it. Especially considering the low price, the Bus Pirate is a worthy addition to any basement tinkerer’s toolkit.

Is the Bus Pirate ready for professional use? The answer is “maybe”. If you work on 3.3V or 5V systems, buy one. It’s worth having in your toolbox, and the $30 price is practically free compared to engineering hours. I’m not quite ready to order some for my bench at work, though, because everything I do is at lower voltages. The low cost may yet pull me in, though. Particularly when evaluating new parts, the Bus Pirate would be a faster and easier solution than either a microcontroller or a National Instruments DAQ.

Links:

A Trip to Electronic Surplus in Cleveland

Yesterday my son and I took a trip to Electronic Surplus, Cleveland Ohio’s candy store for electronics hobbyists and professionals. From a warehouse building in Mentor, ESI operates both a brick-and-mortar store and the website electronicsurplus.com. This is my home-town surplus dealer, which has been a good source for parts for me. Read on to have a look around.

The welcoming sign tells me I’m in the right place. Their location is near a busy intersection, but out of sight of the main roads. An earlier incarnation of the business was known as “Electronic Surplus Inc.”, hence “ESI”. Today the “I” is vestigial — the company is an LLC — but the abbreviation stuck.

The retail store fills about a quarter of the warehouse-style space, with the rest used for storage and web order fulfillment. The store has an odd C-shaped floorplan. This is the view from just inside the front door. The grey drawers contain a variety of parts. The shelves behind them have some of the test equipment that is for sale.

Not far from the counter is a selection of odd circuit boards and modules. This one is a sound and light board from a toy, and next to it is a high voltage supply board. Out of sight to the right was an LM317 power supply board. I was tempted by that, but decided it would be a better idea to use up the ones I already have in my parts collection. Continue reading “A Trip to Electronic Surplus in Cleveland”

Teaching Electronics to a Preschooler

I was stuck. How do I explain decoupling capacitors to someone who doesn’t know yet what electricity is? I said something garbled about getting rid of the part of the electricity we don’t want. He accepted my explanation, but it bothered me. He wanted to know about electronics, but I didn’t know where to start.

After several wrong turns while searching online, I found Oscar and the Bird, by Geoff Waring. The book was perfect for us.

Oscar, an inquisitive kitten, is surprised one day when he accidentally turns on the windshield wipers in a tractor he is exploring.

Oscar and the Bird: A Book About Electricity
Geoff Waring
Candlewick Press, 2008

“Will you show me something, Daddy?” asked my three year old son as he padded down the basement stairs and scampered to my workbench.  Forever wanting to know how things work, he likes to sit on my lap and look through my magnifier lamp at whatever is on hand.

On hand that day was my NorCal 40A.  I popped open the clasps on the lid and opened it up, and the questions began.

“What’s that, Daddy?”  He pointed to an LM393 op amp.

“It’s an amplifier. It makes things louder.”

Then we got into dangerous territory.

“What are those, Daddy?”

“What are what?”

“The blue things.”

“Oh! Those are capacitors.”

“What do they do?”

I was stuck.  How do I explain decoupling capacitors to someone who doesn’t know yet what electricity is?  I said something garbled about getting rid of the part of the electricity we don’t want.  He accepted my explanation, but it bothered me.  He wanted to know about electronics, but I didn’t know where to start. Continue reading “Teaching Electronics to a Preschooler”

Exploring ABC Electronics in Minneapolis

Exciting stuff is going on at work, but as often happens, excitement involves a bit of overtime. I spent last week in the Twin Cities, working with two test engineers to evaluate an ASIC during the day, and working on patent paperwork at night. I did manage to get away long enough to visit ABC Electronics, a surplus dealer in Minneapolis. (The Twin Cities are also served by the Ax-Man Surplus Stores, about which I will write another time.) I left ABC assuring myself that I am not jealous of the Twin Cities’ surplus options, but I’m not sure I believe myself.

Continue reading “Exploring ABC Electronics in Minneapolis”