Arduino Audio with the WTV020SD-16P

There are plenty of ways to play sound on an Arduino– at the most basic you might burp out some bleeps and bloops with the tone() command, or perhaps drop some coin at Adafruit and get yourself a multifunction music shield.

Our current passion project at Zheng Labs is an audio-enabling upgrade to Plutarch the Pirate Parrot. For this application neither of the above options will quite fit the bill. We want a board that’s inexpensive, light, and small enough to fit inside a roaster chicken’s body cavity while leaving room for a battery pack, microcontroller, and an ever-increasing number of servos.

Enter The WTV020SD-16P. ‘Tis a picky, tricksy little board, but once you get it up and running it’s scrum-diddly-fun to use.

rex

#RAWR! you can download Rex for 3D printing over at the Forge.

To the tutorial!

GATHER YOUR PARTS

  • a WTV020SD-16P
  • a SanDisk 1GB MicroSD card: apparently the WTV020SD-16P can be a little picky about which brand and capacity of MicroSD card will work.
  • a speaker: This one comes with micro-JST connectors, which you can just snip off and plug into your breadboard. I soldered some jumper wires onto mine to make working with the breadboard easier.
    some jumper wires

And of course an Arduino and a breadboard. I dusted off an ancient Duemilanove for this project, but I’d imagine any Arduino will do.

GET THE SOFTWARE

You can get the sample code and the software library you’ll need at the Arduino forum.

Oh God. Forums.

I can’t be the only one who dreads wading into technical forums seeking assistance. In my experience one can find tiny nuggets of precious content only by softing through the dross, dregs and slag of misinformation, know-it-all-ism, and half-baked do-my-homework-for-me questions IN ALL CAPS from engineering undergrads in Gdansk.

Every now and then a patient, knowledgable member with a willingness to shepherd a n00b through a confusing and contradictory information maelstrom will emerge, but more likely than not a cheeto-crusted basement dweller will snidely inform you that a B+ in Electrical Engineering 101 at Carnegie Mellon is a prerequisite for posing a question to your betters.

Thankfully, the Arduino forum’s friendlier than most, and it’s a decent place to start looking for information about the WTV020SD-16P. There’s still a lot to unpack and sort out before you get your board talking, though.

Once you’ve gotten the sample code from the forum you’ll no doubt come across this image in all its JPEG-compressed glory. It’s the second post on the forum. You can’t miss it.

schematic

I can’t stress this enough: do not use this image as your Virgil to guide you through this particular circle of Arduino Hell. There’s nothing inaccurate about it, but there’s too much information here for those who want to just plug this thing into an Arduino without having to first procure an EE degree, and some of it is misleading.

This schematic will get you a WTV020SD-16P that works in standalone mode with some pushbuttons, to be sure, but if all you want to do is control the board with Arduino code this wiring diagram is overkill. For one, the pins in this schematic don’t match the pins specified in the sample code right above it, which is one of those Things You Don’t Know You Don’t Know if you’re just starting out.

My edited schematic is a little simpler and balls-on accurate, I promise. Behold!

schematic simple

You’ll note that the sample code includes a declaration for a Busy pin. It’s used for asynchronous audio play but we’re keeping things simple and not using it in this tutorial. Also, you’ll see several pins on the WTV020SD-16P labeled as NC: they’re Not Connected to anything and can be safely ignored.

If reading schematics ain’t yo thang, here’s what it looks like IRL:

wiring

To recap:

  • Arduino 3V3 to pin 16 (top right of the board)
  • Arduino pin 2 to pin 1
  • Arduino pin 3 to pin 7
  • Arduino pin 4 to pin 10
  • Speaker + to pin 4 (usually this is the red wire)
  • Speaker – to pin 5 (usually the black wire)
  • Arduino GND to pin 8

ACQUIRE AUDIO:

You can download the commonly used sample .ad4 files here, or use mine which IMHO are better for diagnostics and have the added benefit of not dancing on the knife’s edge of fair use and international copyright law violation.

If you’re visiting the blog from abroad you also can use my files to learn what a nondescript northeastern American accent sounds like. No charge.

Unzip the archive and drop the files into the root directory of your FAT16-formatted MicroSD card. Files must be named 0000.ad4, 0001.ad4, 0002.ad4, etc. The WTV020SD-16P supports up to 512 audio files, which should be enough for all but the most loquacious of parrot puppets.

Creating your own .AD4 files from WAV or MP3 of AIFF is brain-dead easy with this OSX tool, but you’ll need to install the JDK first.

Be sure to have your source audio sampling rate set at 32kHz or the software won’t produce any output and (not helpfully) any error messages indicating that there’s a problem.

SOFTWARE:

On OSX, drag the library folder into ~/Documents/Arduino/libraries/

The sample code on the forum shows off everything the library can do, but it’s too much for a proof of concept and has some English errors that introduce ambiguity in the comments. Let’s do some minor surgery.

  1. Cut out everything in between the curly brackets of the loop() function.
  2. Paste the following between the now-empty curly brackets after loop():
int r=random(0,6);
wtv020sd16p.playVoice(r);
delay(1000);

Power up your Arduino, upload the new code and you should be good to go. Good luck, and please post in the comments if I screwed anything up in the tutorial.

Watch this space for news on Plutarch 2.0’s evolution over the next few months. He’s scheduled to debut on Halloween 2017. You might consider watching his progress on Instagram or Twitter: that’s where the microupdates get posted first.

Lao Zheng out.

Plutarch 1.0: finished, still not a robot

After this stability test it’s pretty safe to say that Plutarch is 97% ready to make his debut at J’s Halloween party later this year.

So how did we get here? When last we left our hero he was a naked 3d printed shell enclosing a buggy and unstable collection of wires and electronics.

Rubber cementing the feathers to the body was strikingly straightforward, the only caveat being that one needs to layer the plumage and make sure that none of it gets into the spaces between moving parts.

fledging collar

I ran out of feathers during the fledging process so he’s still got three percent’s worth of bald spots to fix during the 138 days before Halloween.

Epoxying the googly eyes is simple enough. Next time I’ll include 3D printed eye socket markers so I can be sure that Plutarch isn’t walleyed.

googly eyes

Here’s the thing about googly eyes. You can’t buy just two. You have to get a whole mess of them.

Epoxy is enlisted once again to affix the wing feathers to the body, as they’re too heavy to attach with rubber cement alone.

fledging wings

A clever designer would have included tail feather mounting holes in the original 3D printed body, but unfortunately no clever designers showed up to work on body design day. So Plutarch got a few aftermarket holes drilled in his rump.

drill

You may feel some slight pressure, Mr. Plutarch. Please try to relax.

OK! So! Forty-five minutes of fledging and butt-drilling hence, Plutarch’s ready for his big reveal to the family.

too sexy

Possibly too sexy for your cat.

You can see an original Pirate Parrot Accessory in the background of the photo above– one of his duplicates was cannibalized to provide most of Plutarch’s feathers. I bought a bag of blue turkey flats to compensate for the feather shortfall and still didn’t have enough.

The kids (and, of course the Lovely and Talented Mrs. Zheng3) have been watching Plutarch’s progress in bits and bites for the last few months, and they’re assembled in the kitchen for Opening Night. Plutarch is perched, powered up, and ready to go. I hit the button on his remote that makes him shake his head and… BAM.

broken

To everyone’s horror (except the cat, who gives approximately zero f*cks) Plutarch torqued himself off my shoulder, broke a foot, and snapped his battery cables.

Gah. I pinned the broken foot with a couple of epoxy-coated finishing nails and set the patient aside.

Another setback. We were so close.

The epoxy cure delay allows for a few hours of self-reflection. Why am I doing this? Is making an animatronic parrot really best way for me to spend my limited time on earth? How do magnets work, anyway?

Magnets. We need moar magnets. Better-positioned ones, too.

The original perch design put the magnets on the underside of a steel can lid, relying on luck to link up with the magnets embedded in Plutarch’s toes. Fearful of another catastrophic and embarrassing fall, I moved the magnets to the top of the lid and made sure they’re aligned as closely as possible with their mates above.

magnets

The video at the top of the post proves that this time Plutarch stayed put.

But. BUT! Even after all this improvement, Plutarch, while ready for primetime performance, is still not a robot. He’s best described as an animatronic parrot. Roboticization– the addition of sensors and the ability to respond to an environment– shall have to wait until Halloween 2017.

So here’s what I’ve got planned for Plutarch’s next year:

  • improved internal accessibility
  • 2-axis head movement
  • articulated beak
  • audio
  • some kind of sensor ability, for crissakes

#staytuned.

Tales of Plutarch’s earlier incarnations can be enjoyed here and here.

Lao Zheng out.

Plutarch: 148 Days until Halloween

Longtime readers of the blog will recall the first mention of Plutarch the parrot some time ago. To recap: I’m building an animatronic parrot as part of my recurrent pirate costume. I’ve had some success this weekend getting Plutarch’s proof-of-concept to the next level.

Plutarch 1.0 is not yet a robot: he currently lacks any way to percieve the world around him and relies entirely on a user with a remote control to direct his movements. Eventually he’ll get some sensors and some programming that will let him interact with the world, but for now he’s not much more than a remote control servo, an Arduino, and 4 AA batteries crammed inside a 3D printed body. One shudders to think of the wacky magnetic fields created by the rat’s nest of wiring inside his shell.

parts

I wrapped his RF reciever in a Ziploc bag and secured it with a rubber band. It works, but hoo doggies is it ugly.

rf

(The remote control is this nifty little guy from Adafruit.)

TODO: Stability and order! The purpose of this test was to ensure that Plutarch’s magnetic feet would be strong enough to keep him perched on my shoulder even with the torque created by whipping his head back and forth. He passes the test (barely) but it’d be nice to have a more reliable connection between man and parrot.

He’s got to stay on my shoulder for a couple of hours at a crowded Halloween party, which gets to be more and more precarious a proposition as the grog starts a-flowin’ and people are maybe not paying quite so much attention to where they’re going.

inside

Changing his batteries requires removing his head and digging out the Arduino and the battery case, which puts some physical strain on the electrical connections. One of them broke.

stress

Boooooooo.

The on/off switch on Plutarch’s back is also frustratingly flaky, a discovery which I of course made after epoxying it into place. I’ll have to get a new one in there before showtime.

Also it’d be really funny if he had a functional USB port in his cloaca.

While I’m waiting for some parts to arrive (I found a dozen replacement switches for the price of a latte) I can catch up on some much-neglected cosmetic additions to our hero. Plutarch’s body will mostly be covered in feathers someday, so there’s no need to worry about the layer lines created by 3d printing for most of his surface.

His beak is another matter entirely. Painting it directly will leave the print layers intact, which is going to look fugly. Instead, I masked out the beak with some painters’ tape and spread a thin layer of silicone caulk– the stuff you use to seal your bathtub– on the surfaces that will be exposed to outside observation.

silicone beak

Pro Tip: gently wipe down the caulk with a wet finger to get it really smooth.

I had some flourescent pink spray paint left over from painting Brenda the Tardigrade, so into the garage went Plutarch’s head for a couple of coats.

masked

Removing the tape reveals that our currently featherless friend is going to need a little touch-up before he’s fledged. Note the difference in texture between the coated beak and the raw plastic. Nice.

final beak

Once he’s stable, functional and unlikely to short himself out, I’ll start attaching feathers, and then Plutarch 1.0 will be done and I can move on to planning Plutarch 1.5 for Halloween 2017.

Schrödinger’s Shipping

TL;DR: Some backer rewards are shipping. Others are not. Be sure to set a minimum layer time for spherical prints.

Kickstarter update: The first wave of physical backer rewards has been shipped and is happily trundling towards Strongholds backers. This batch is mostly Dice Plinths and a couple of mini-citadels. Eyries and full-sized citadels are (slightly) delayed, for reasons soon to become clear.

But first! We’ve got some photos of backer prints to share, yes we do. Here’s a FlashForge Creator print of the modified Citadel straight outta Pinshape. Some backers had expressed disappointment that their printers couldn’t handle the citadel’s height, so I used Maya’s Multi-Cut tool to split the mesh at a mortar line.

flashforge

Thanks to backer Nagromic Strongbow for this one.

In other, less enthusiastic gnus: we’ve hit our first official backer reward fulfillment snag.

Booooooo.

Hundreds of hours of nonstop printing with abrasive Glow in the Dark filament have worn out our print nozzle. Worn nozzles lead inevitably to failed and/or low-quality prints, up with which the quality control minotaur at Zheng Labs simply will not put.

failed cap

Enjoy the schadenfreude of failed prints? See more at http://3dprinting.fail

The above print failure is hilariously catastrophic, but these holes and blisters in the Eyrie caps are by far more pernicious:

caps

Here one can see the importance of paying attention to your slicing software; a good slice can make the difference between a mediocre and a solid print. What’s happening here is that the hot plastic doesn’t have a chance to cool before the extruder starts laying down the next layer. There’s some inter-layer fricton going on, and the newly extruded layer is dragging the still-gooey previous layer around with it.

Sometimes this process creates a tiny hole in the top of the cap. Smetimes one can’t tell there’s an issue at all. Must have something to do with ambient air temperature and viscosity thresholds or sunspots or something.

Naturally, I didn’t stumble upon the solution until I’d printed a dozen or so faulty caps. All you’ve got to do to fix an error like this is give each layer a chance to cool. In Cura, the setting’s under the Advanced tab– change your Minimal Layer Time to some value other than 0.

I’d rather delay shipping than send out prints of anything less than the highest quality that I can manage, so production’s been suspended until a replacement part arrives. Once it gets here I’ve got maybe 20 caps to reprint at 3 hours a pop.

While this situation is terribly frustrating, Strongholds is still mostly on schedule and, more importantly, shows no signs of devolving into one of those I-took-backers’-money-and-built-myself-a-house-in-rural-Saskatoon Kickstarter fiascoes.

On the subject of fiascoes, I’ll leave you with this deceptively attractive Ultimaker print from backer Michael Zions:

ultimaker

Looks good, right? A thousand quatloos to the Ultimaker team for designing a 3D printer that can do double duty as a diffuse lightbox.

Unfortunately this print crumbled to the touch as soon as Michael removed it from the bed. If you’re having this kind of trouble with your prints, use the citadel_alt STL file instead of the original.

hero

Faire Play III

Witness Faire Play III: a fully articulated, 3d printed, Barbie-compatible battle tardigrade.

The tardigrade, hereafter to be referred to as Brenda, is roughly the size of a domestic cat when printed at 100% scale, and comprises 61 separate pieces. Brenda has five body segments, eight articulated legs, and is fully poseable.

This time around Barbie eschews the full plate from the original Faire Play in exchange for a fantasy barbarian furkini. The furkini and boots are printed in NinjaFlex TPE, and are designed to fit a Barbie Made to Move doll. They’ll probably fit other dolls of similar size, but I haven’t tested them yet.

kneeling

Brenda’s saddle includes a mounting bracket for Barbie’s yoga mat because it’s always wise to warm up with some sun salutations before sack and pillage day.

saddle cu

Also included in but not pictured are a Mongol-style recurve bow and a three-headed flail.

I’ve set this playset up as a pay-what-you-like download with a $1 minimum. Yep, you can get the tardigrade, the furkini, a full compliment of Barbie-compatible weapons and armor, a saddle, and— AND! a 3D printable yoga mat for a BUCK, people.

Feel free to donate more than $1 if you like the project and would like to see more stuff like this exist in the future. Even if you don’t have a 3D printer it never hurts to throw an indie designer a bone. I’m just sayin.

Better yet: it’s Creative Commons licensed! You’re free to remix and redistribute this work as long as you credit Jim “Zheng3” Rodda as the original designer. Credits for the giants upon whose shoulders I’ve stood to create Faire Play III are listed in the .ZIP file.

Designing and executing Faire Play III was a yuuuge endeavor and a full description of it is beyond the scope of a single blog post. Watch this space for more photos and behind-the-scenes stories of how the latest and greatest in Barbie-compatible wargear came to pass.

UPDATE: Hello, SciFri Twitter followers! Here’s an extra couple of photos just for you guys! While you’re here you might want to check out SciFri Bingo in advance of tomorrow’s show.

feeding

Tardigrades LURVE themselves some garbanzo beans. It is known.

tree pose

And as always, #staytuned, my friends. I’ve got the Next Thing bubbling in the hopper already. See pics of embryonic Plutarch on Ye Olde Instagramme.

Lao Zheng out.

You’ve Got Fail!

TLDR; I released suspect geometry into the wild. Also 3dprinting.fail is now a thing.

failed citadel

Despite rumors to the contrary, it’s not all mimosas and backrubs here at Zheng Labs. There are times, thankfully few and far between of late, when we fail to make the proper sacrifices to the 3D printing gods and models go kablooie on the print bed.

To wit: these Eyrie caps that bought the farm before they could reach their full potential.

eyrie cap

The bottom surface of the Eyrie cap is a thin circle and occasionally won’t adhere to the build platform. Double woe if one gets ambitious and prints multiple models at a time; one failed print can catch on the extruder nozzle and get dragged into its doppleganger, causing a calamitous cascade of failure.

The printer, being blind, deaf, and completely lacking in agency besides, has no idea that this failure is happening and if left to its own devices will merrily continue extruding hot plastic into thin air.

Fail.

A quick primer on 3D printing for those of us who don’t live and breathe this stuff. One can break the process down into three basic steps, about which one could proceed to write volumes of details.

Step 1: Creation! By some mystic means, a 3D model is created. My weapon of choice in this arena is Autodesk Maya because I use it in my day job, but there are scores if not hundreds of software packages that will export a 3D printable model. Amazingly, even Minecraft can do it with the right mods. Tell your nine-year-old niece.

Step 2: Slicing! Before it can be printed a model must be divided up into a vertical series of horizontal layers. If you’ve accidentally introduced wonky geometry in Step 1 the slicing process will create toolpaths that kinda work, but might result in a less-than-optimal print in the real world. More on this and a mea culpa in a bit.

Step 3: Printing! A tireless bot with a melted plastic-filled hot glue gun draws successive layers on top of each other. The plastic cools and before you can say Bob’s your uncle you’ve got a brand new Dice Citadel. Usually it works, and sometimes this happens:

The reasons for print failure are legion, but I’m guilty of letting an avoidable one slip through my quality-control network with the Classic Citadel. Back to slicing and the aforementioned mea culpa:

Here at the lab our preferred slicing software is Cura. Cura has been churning out perfectly usable G-code for months and I’ve printed dozens of citadels with nary a problem. But here’s the rub, mein grübenses: not everyone out there uses Cura.

Printing problems started cropping up once the Citadel was released into the wild. Users of slicers Simplify3D and slic3r were shocked to find that their printed citadels, walls too thin to withstand an assault even by Marshmallow Mangonels, were crumbling to the touch– see the photo at the top of the post.

Mea maxima culpa, I really should have run the models through several slicers before releasing them. Parallels may easily be drawn between the current state of 3D slicing and the early Web when different browsers would render the same HTML in completely different ways. 1996 was a great year for flannel, but damned if I enjoy the return to crossing one’s fingers and hoping that WYS is truly WYG.

Wizzywig. Now there’s a term I’ve not heard in a long, long time.

But! Thanks to the heroic and dogged troubleshooting efforts of Strongholds backers Chris Yohe and Nate Johnson, the problem’s been fixed as far as I can tell. I’ve uploaded a new Citadel to Pinshape and alles gut. Print, my friends. Print LIKE THE WIND!

Other backers have been busy printing Eyries and plinths a-plenty. If you’ve got a print you’d like to show off to our little tribe of medievalists, send it my way.

backer prints

Unexpected creative output: There’s plenty of downtime to be filled while the printer is producing Citadels and Eyries for physical rewards backers, we’ve been thinking about failure a lot lately, and here at Zheng Labs we’re certainly not ones to let a good domain name go unclaimed.

So I went and registered 3dprinting.fail, polished up my JavaScript-stealing chops, and made a nice slideshow of some of the spectacular messes my printers have created over the years. Tell your friends. Tell your mom. Tell your mom’s friends at the next euchre tournament.

beast fails

(That model’s a Beast Token and you can grab your own at The Forge.)

So! That about covers it for this week. Back to printing backer rewards and obsessing over the Next Thing. Here’s another wee teaser for that project, which I’m hoping to release within a month or so:

wee

Who loves ya, baby?

Lao Zheng out.