Despite what a lot of people say about the Arduino crowd and using C++ on a microcontroller, I like it.  Sometimes it incurs a performance or code-size overhead, but I’m not often approaching the RAM or Flash limits of an Atmega 328, or especially an Atmega 2560.  When appropriate features are used, C++ results in more readable code.  Lately, I’ve branched into using templates with some AVR Code.  Here’s a super useful snippet for creating a quick ringbuffer:

No malloc or new to be seen here.  As long as equality operators and copy constructors are sorted, it should work with arbitrary types (although I’ve only tested it with built-ins and simple structs).

C++11 also allows you to typedef templates, like this: typedef AVRRingBuffer<char, 25> SerialBuffer;

I hate Make.  With a fiery burning passion, I hate Make.  From day one, I found it difficult to understand, difficult to write Makefiles, difficult to modify Makefiles, and difficult to use Makefiles.  Over the years, I have built a collection of boilerplate Makefiles that only sort-of worked for a given project, and any time I wanted to do something creative with the build system, it was a challenge to figure out how to force Make to do what I knew damn well how to do via the command line.

There has to be a better way!

There has to be a better way!

Wasting time on HackerNews, I saw a post about a build system called Tup.  It was designed as a pet project for a pet project, but I was able to understand the syntax in just a couple hours of reading and experimenting.  Seriously, in just a couple hours, I was writing Tupfiles from scratch, something I would never think of doing with Make.

Tup has some seriously huge benefits if you’re building projects with thousands of files, and lots of nested directories.  Tup uses inotify and some other tricks to automatically figure out what needs to be rebuilt, and when it needs to be rebuilt.  I’ve been told that you can do a lot of this using Make, but I have never been able to write a Makefile that didn’t try to rebuild everything all the time, so even though I shouldn’t be saving build time using Tup on small embedded projects, I am, by a huge margin.

In fact, “tup monitor -a” is probably the most magical command I’ve encountered in any build system ever.  Because tup uses inotify, the monitor daemon can receive notifications that files in the build chain have changed, and automatically determine what parts of the project need to be rebuilt.  As a result of this, my project is often rebuilt by the time I’ve alt-tabbed to the terminal to check the results of the build and upload to the board.  Serious, magic.

Most of my projects lately have been built on AVR8 processors, so I’ve created two Tup skeletons on github, if you’d like to try it out:

https://github.com/Zuph/TupArduinoSkeleton

https://github.com/Zuph/TupLufaSkeleton

The first is an Arduino skeleton project that allows you to easily write Arduino code using whatever text editor and programmer you damn well please.  Simply #include “Arduino.h” at the top of every file, and you’re in Arduino-land.  Works out-of-the-box with any AVR processor used on an Arduino, including the AtMega328, and AtMega2560.  Other processors will require a pin definition file in order to work with Arduino functions.  To use, clone it, run “tup init” then “tup upd”.

The second is a skeleton project for LUFA, the AVR USB library.  I’ve been using LUFA with the Teensy++ 2.0, but there are plenty of other boards and processors that can make use of the library.

If you want to improve the skeletons, or submit your own, I welcome all pull requests.  I’m also happy to help folks get started with tup.  The more folks using it, the more well-supported it will be in the future!

3D Printing WorkshopThis past weekend, we had a 3D printing workshop at LVL1.  I built a Mendel Prusa i2, along with 9 other folks in the LVL1 community. Sonny Mounicou came up from Memphis, TN, while Jon Oly of SeeMeCNC came down from Goshen, IN to help us build 3D printers.  One guy had his printer up and running in a mere 14 hours!  I had to get some sleep, so I was a little bit behind that.

Needless to say, everyone had a great time, and walked out with some working 3D printers.  I’ve since gotten my Prusa home and had some time to play with it.

Prusa at HomeI’ve already got plans to make it better.  Tonight, I’m going to redo all the wiring to make it nicer, more reliable, and better looking.  Next, I intend to scrounge a server power supply out of the basement of LVL1.  Currently, it’s attached to a 200W Dell Power supply, which can only push out 200W.  This is fine for most things, but it just can’t put our the juice needed for heating the build platform to ABS temperatures.  I was able to get some calibration cubes of ABS to stick to the build platform, but nothing bigger. After that, sky’s the limit.  I’m also going to use this printer to print parts for another 3D printer, a Rostock.

Unfortunately, I’ll be missing the Midwest RepRap Fest this weekend, but I’ll be there in spirit!

 

 

Recently, Matseng at the Dangerous Prototypes forums posted another source for cheap printed circuit boards and test equipment direct from China:

http://www.smart-prototyping.com

The site is apparently run by German ex-pats in Shenzhen.  Although the site is pretty sparse at the moment, they’ve got a PCB prototyping service and a selection of very cheap test equipment for sale.  I placed an order for some PCBs and a Bench Supply on the day the Chinese New Year ended.  They arrived Thursday.

PS-303DM Power Supply

The bench supply looks great.  I tested it with a crappy RadioShack meter and some resistors, and the readout is at least as accurate as the meter.  This is every bit as nice as power supplies 3 times as expensive.  When I received it, the switch on the back was set to 220v, and contrary to the description, it did not come with a power cord, but for the cost, I’m very, very happy.

Smart Prototyping Circuit Board

The PCBs also came out very nicely.  These are nothing particularly taxing (these board are for a possible through-hole kit to sell on Tindie), but the drill hits are every bit as accurate (if not better) than Seeed Studio or iTead studio.

Overall, I’m very happy.  The service was really quick (less than 2 weeks!), and the price was good.  Shipping was on the high side, but considering the price of the power supply, nothing to complain about.

 

Jim William's Workbench

Jim Williams Workbench, courtesy of the Computer History Museum.

There has never been a better time to get into hobby electronics. Unfortunately, the tools required can be daunting for a newbie, and can quickly make the hobby look expensive and unappealing. I’m getting ready to move into a house where I’ll have my own electronics workbench, so I’ve been devoting a lot of attention to budget tools. I’ve got the basics, but since I joined the LVL1 Hackerspace, I’ve really let my tool collection atrophy. In the spirit of sharing, here’s a list of tools needed to get into electronics hobby. These tools are roughly listed in the order of priority, and all of them are list at new prices. You’ll definitely be able to get away with cheaper tools if you’re willing to do a little digging.

A disclaimer: You might not need all of these tools, and this list is not comprehensive! These tools are highly useful for analog and digital circuit design and construction, but if you’re into different areas of the hobby, you’ll need different tools. For example, radio geeks will find antenna analyzers and SWR meters extremely useful! For more inspiration, browse the Electronics Workbench Flickr Group: http://www.flickr.com/groups/elwb

If you know of a better/cheaper source for any of these tools, or you’d like to suggest an addition to the list, please leave a comment! This is as much a learning experience for me as anyone, and we all love learning about new sources for these toys.

Unless mentioned otherwise, I have experience with all the hardware mentioned below (although not necessarily with the suppliers). Super Budget items are things that I would tolerate using if I didn’t have a better alternative, Medium Budget items are probably items that I have bought or would buy, and Standard budget items are tools that I would prefer to use. You can definitely spend more than the standard budget on every item in this list, but this is supposed to be a post about the shoestring workshop, and if you’re spending more than the “Standard” budget, you’re no longer in shoestring territory!

» Read more…

4 months ago, I read about Johan’s Nanino on Hack-A-Day, and thought it would be a great way to teach some folks how to etch their own circuit boards.  Although I’m increasingly shipping PCBs off to China, being able to etch your own boards is a valuable skill to have.  I’ve taught workshops on it in the past, and I’ve described the process on this blog.  Today, I set out to make a copy of Johan’s Nanino, but was almost immediately frustrated by the inability to manipulate and print the board file in a way that worked well for my process.  In the end, I redrew the thing using DipTrace.

Nanino ImprovedThe only change made to the original is the addition of a .1 uF capacitor on the DTR line of the FTDI header.  Some of the traces are a little closer together, but they’re still spaced out enough that etching this board is a cinch.

Here are the files:

Diptrace Schematic for Nanino

Diptrace PCB for Nanino

PDF of Nanino from the Back

You can use this PDF to etch directly.  No mirroring is needed.

Can be printed.  1200 DPI.

Can be printed. 1200 DPI.

Can be printed. 1200 DPI.  No mirror needed for etching.

Can be printed. 1200 DPI. No mirror needed for etching.

DXF of Nanino

And, because the original Nanino is licensed CC-BY-NC-SA, this one is also:
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

 

It works!

It works!

Good toner transfer

Good toner transfer

The etch was drama-free

The etch was drama-free

We live in a golden era of the electronics hobby.  PCBs are easier to make and cheaper to manufacture than ever before.  In some cases, it can even be easier to have  PCB made than breadboard a circuit.  With the growing proliferation of surface mount components, and ever greater levels of integration, PCBs are more and more appealing for hobbyists.  Like most folks in the maker community, I get my PCBs made at one of three places: Seeed Studio, OSH Park, or Batch PCB. (Itead Studio, also, but their prices and quality are basically the same as Seeed Studio.)

I’ve been ordering from whatever place strikes my fancy at the moment (increasingly from OSH Park, so I’m not left waiting as long for the boards), but I’ve never seen a decent comparison.  A few minutes in Octave fixed that right up.  Without further adieu, the price of 10 PCBs from OSH Park, Seeed Studio, and Batch PCB.  In order to compare apples to oranges, I assumed expedited shipping for the Seeed Studio orders.  In practice, this means about 10 day turnaround time for all three options.  All board dimensions are in CM.

 

Pricing for Expedited PCBs from Seeed Studio. X and Y are board dimensions in CM, Z is cost in US Dollars.

Pricing for PCBs from OSH Park. X and Y are board dimensions in CM, Z is cost in US Dollars.

Pricing for PCBs from Batch PCB. X and Y are board dimensions in CM, Z is cost in US Dollars.

This view gets even more interesting when you plot all three on the same graph:

The Mountain Range View of PCB Costs.

The stair-step pattern is Seeed Studio, the middle-surface is OSH Park, and the top surface is BatchPCB.  So, for 10 PCBs in about 10 days, OSH Park is the cheapest up to about 20 cm^2, then Seeed Studio is cheaper.  Here’s a heat-map of that price-breakdown.

Best Cost for 10 PCBs in 10 days. Yellow is OSH Park, Green is Seeed Studio. X and Y are board dimensions in CM.

 

Of course, sometimes you don’t need 10 boards.  In this case, OSH Park is the winner in a lot more cases.  In that case, here is the cost breakdown:

Best cost for minimum number of PCBs. Yellow is OSH Park, Green is Seeed Studio. X and Y are board dimensions in CM.

And, of course, sometimes you don’t care when the boards arrive.  If you don’t mind waiting for 3-4 weeks, here’s where you’ll find a better deal:

Best Price for PCBs, no rush. For Seeed, this means 4 weeks or so. For OSH Park, this means 10 days. Yellow is OSH Park, Green is Seeed Studio, X and Y are board dimensions in CM.

So, here’s the verdict:  Never order from BatchPCB! (Sorry Sparkfun.)  Otherwise, figure out whether you need a lot of boards, board fast, or boards slow.  Depending on those answers, look at the heat maps above, and find your best deals!

I’m not dead.  I switched jobs back in September, and it’s seemed like an impossible task to catch up to everything until now.  But I’m working on some cool stuff!

For example, I’m building a 3D printer:

This is the start to my Rostock 3D printer.  I started printing the parts for this way back in October, and I’ve just now gotten to the point where it’s starting to come together. Unfortunately, a much better version has come out in the mean time.  A couple of people have already come through LVL1 building the improved, extruded aluminum delta bot.  It was almost enough to make me start over and try again, but not this time!  I’ve tried to build three other printers in the past, but they never got further than printing some plastic parts.  This time, I’ve spent real money on the project, so I’m going to forge ahead!

So far, I’ve run into two major setbacks.  The first: the printed arms an u-joints are really, really terrible. Threading an M3 bolt into the U-joint as instructed is painfully difficult, and the result isn’t particularly smooth motion.  I’m going to have to buy a set of real rods before I can continue.  Second, the specced GT2 belting and pulleys were completely unavailable in the lengths I needed, so I had to switch to HTD 3M belting and pulleys.  It was expensive!  The company I bought the stuff through charged me $15 for shipping, on top of $35 for the belt.  Then I cut the belting wrong, so I have to buy even more!

I’ll be using a Printrboard Rev. D to drive the whole thing, unless it blows up in my face.  Then I’ll probably just buy a nice reliable RAMPs setup, or a fully assembled printrboard.  And then, I’ll be off to the races!

This is the wrong way to cut the belting. Instead, leave a long tail, loop it back on itself, and zip tie it together.

 

 

 

 

 

 

 

 

.

I’ve been excited about the LPC1114FN28 for a while now (at least, as excited as one could be about a microcontroller).  The LPC1114FN28 is a microcontroller from NXP with an ARM Cortex-M0 core in a 28 pin DIP package. With 32k of flash and 4k of RAM, this chip isn’t the biggest or baddest on the block, but at $1.50 in small quantities, it has just about every other uC beat in the performance-per-dollar arena.  It’s got the basic peripherals, SPI, Serial, ADC, and I2C.  It’s programmable via SWD or serial bootloader. Though I don’t use a breadboard too often any more, it’s great to have an easy-to-prototype ARM chip in my box.  Unfortunately, these chips are notoriously difficult to work with, especially with open source tools.

A few posts ago, I talked about getting an open-source ARM toolchain up and running.  With the correct linker scripts, this toolchain will work very well for this chip.  NXP has also seen fit to include an internal RC oscillator on-board, so the breadboard setup for this chip is surprisingly simple.  Here’s what I used:

I’ve got an LED for power, an LED hooked up to PIO1_8 (pin 17), a reset switch, and a pin header configured to work with an FTDI cable or an FTDI friend hooked up to the serial lines.  Most important is the resistor between ground and PIO0_1 (pin 24).  The value of this pin is sampled at reset, and if it is tied to ground, the chip enters the serial bootloader. Otherwise, it executes the loaded program.  This process can’t be done in software, so you have to connect this resistor when you want to load code, and disconnect the resistor when you want to run your program.  You could also use a pin on the FTDI friend for this, but you’d have to modify the ISP software.

As I said, I’m using the toolchain I configured earlier.  I found some blinky test code for another chip in the LPC1114 family, and modified it to work with the LPC1114FN28.  The modified code can be found here: https://github.com/Zuph/lpc1114-blink

In order to get the code to work, I altered the linker script to reflect the amount of RAM on this particular chip, and changed the pin configuration for the LED pin.  I also had to change the clock source: this was the most difficult piece to chase down.  Unlike AVR chips, where the clock configuration is set by fuses, this ARM chip (and many others) force the user to configure clock sources manually. Originally, line 154 of main.c read:

LPC_SYSCON->SYSPLLCLKSEL = SYSPLLCLKSEL_SEL_SYSOSC;

This configured the chip to use an external oscillator.  Changing this to:

LPC_SYSCON->SYSPLLCLKSEL = SYSPLLCLKSEL_SEL_IRC;

resolved the problems.  Output code is now being generated properly, but getting it on the chip is a different problem entirely!  Reading the manual for the series makes the bootloader look like a fairly simple piece of work!  Auto-baud synchronization makes interfacing simple, and the commands are reasonably easy to understand.  There are a few programs which purport compatibility with the the LPC111x family, including VSProg (from the Versaloon folks), and a likely-abandoned projected called lpc21isp.  Neither of these programs, however, support the LPC1114FN28/102 variant.  VSProg looked to be the most promising (given its general purpose nature), but modifying the config files proved fruitless in adding support for the FN28 (if you can get it working, please let me know!).  lps21isp, however, worked well once the parameters for the chip were programmed in.  I’ve uploaded the code for my variant here: https://github.com/Zuph/lpc21isp

I had to change lpcprog.c, adding the following on line 116:

{ 0x1A40902B, "1114FN.../102", 32, 4, 8, 1024, SectorTable_17xx, CHIP_VARIANT_LPC11XX },

This adds the FN28 chip-id, along with the amount of RAM, flash, number of flash pages, and the maximum amount of data to transfer at once (the bootloader uses a two step process, writing code to RAM, then moving it to flash in order to reprogram the ship).  Once this is added, I was able to easily flash code to the chip, although I wasn’t able to do so at 9600 baud.  115200 baud works well.

In summary, wire up a breadboard as seen in the picture above, compile the blink code, flash it on to the chip using the lpc21isp program, remove the resistor on pin 24, reset the chip, and watch it blink!

Here are the exact commands I used:

Possible caveats: The chip will only attempt to enter the bootloader once.  If autobaud has been attempted and failed, you’ll need to reset your chip to attempt it again.  Also, in the programming command, we give it the speed (in kHz) of the RC oscillator, since that’s the oscillator that the bootloader will be using.

Let me know if you have any questions.

This year, I had the good fortune to visit GenCon after a 2 year hiatus. Not much has changed, although I was surprised at the number of KickStarted projects on the show floor.  There were a lot of really interesting independently funded games, including a few print-and-play games.  Print-and-play has been around forever, but with the advent of the MakerBot, and the rising popularity of 3D printing, both at home and for contract, I am surprised at the lack of 3D-print-and-play games.

Pocket Tactics

Maybe I’m biased, since I have nearly unfettered access to a 3D printer through the LVL1 hackerspace, but I strongly believe that this technology is our future.  In ten years, I truly think that everyone reading this article will have trivially easy access to a 3D printer, if they do not already have this access.  It astounds me that gamers haven’t adopted this technology in droves.  The maker crowd and the gamer crowd have a huge amount of overlap, so what gives?  Why aren’t there more 3D printable games?

Sure, there are a few examples of printable games on thingiverse, but most of these are clones of other games.  Not only is this a legal and moral gray area (at best), but it’s boring and unimaginative.  Pocket Tactics is the best example of a printable game that I can find, and it’s a game in its infancy, at best (but serious props to these guys!).  There just aren’t a lot of 3D printable games.  Why?  The technology seems like a perfect match for the gaming community!  Everybody loves to invent and modify and tweak rules systems, and printable games make it simple to create your own game universe without relying on game pieces stolen from other games, or figuring out how to do injection molding in your garage.  The world of indy game publishing should be eating this up, since a small team can rapidly iterate on a game design, complete with unique tokens and artwork.  Wargamers especially should rejoice!  The huge barrier to entry for games like 40k is the cost of outfitting an army, and 3D printed parts are pennies on the dollar compared to ordinary wargaming miniatures.  A 3D printed wargame should be a no-brainer.

An Easy 3d Print

There are event successful business models that a prospective game maker could take advantage of.  There are already indy tabletop games releasing game guides and modules as for-profit eBooks.  3D printed games could use the same model, selling the rules and models in digitally distributed packages.  A game designer could give away the rules, and sell the models, or sell the rules and give away the models.  This sort of distribution makes it possible to give away a starter set of models, along with the rules in order to get people hooked.  Game designers could even adopt a “value-added” model, bootstrapping with 3D printed game parts, and selling nicer injection-molded parts later.

So, why aren’t there many 3D-print-and-play games?  Any ideas? I, for one, would very quickly purchase any compelling 3D printable game that came across my desk, as long as it wasn’t a clone of something else.  In fact, I’m printing out pocket tactics right now.