praxworld.com Electronics, music, electronic music! general geekery

15Oct/101

monome mk: Adding an Accelerometer

I'm having a great time building my monome mk, inhaling solder fumes and feeling pretty confident about my skills. But not too confident! I finished assembling the driver board and it came out great. Then I applied 64 dots of solder to the keypad board, in preparation for 64 SMD diodes. But before unpacking those diodes I decided to install my SparkFun accelerometer (ADXL322 +/-2g) on the logic board. I basically did what thealphanerd suggested in this post:

connect the gnd to gnd, the VDD to 5V and x + Y to two of the analogue pins (such as 0 and 1)

I first attached a header pin to the breakout board VCC and GND. Then I soldered wires to X and Y. Then I connected wire X to analog 0, and wire Y to analog 1. Finally, I flipped it around and soldered the pin headers into the logic board GND and 5V. I stuck a little adhesive foam bumper disc to the gap for a bit of added stability. It came out so pretty I had to show it off:

In this shot you can see the foam disc:

Now I just have to cross my fingers that it will work once I plug everything in!!!

One important note: The accelerometer board would need to be mounted AFTER the pinouts for JP4 (if you are using JP4, like say if you are building a 256). It could probably rest really nicely on top of the pinout header. Since this particular unit is a 64 those pinouts won't be used.

Filed under: Electronics, Monome 1 Comment
4Oct/102

Interfacing MaxMSP and Arduino

Building the Bliptronome got me thinking about microcontrollers in general, and how cool they are. I've been teaching myself to program using an Arduino Duemilanove, and it's a blast. Inevitably I began to wonder how to communicate with Arduino using MaxMSP. The Arduino and the Bliptronome are similar in many respects. Each can use what is known as a serial proxy to communicate with host software. The serial proxy is device-specific, and functions to translate serial messages to and from the USB port to which the devices are connected. The Bliptronome and its cousins Monome and Arduinome can all use a purpose-specific serial proxy that makes it easy to write MaxMSP code for 'nomes. But how do you set things up quickly and easily for a standalone Arduino? You could write your own serial proxy, but who has time for that? Arduino kindly offers one on their site, but it only works to move data between serial port and a network connection, not USB. This is great for Flash users. But what about MaxMSP users, particularly those who want to get straight to I/O with a minimum of fuss?

Thankfully you don't have to reinvent the wheel, as there are a couple of brilliant free solutions that work very well together: Maxuino and Firmata. Firmata is a generic protocol that provides the foundation for MaxMSP (and many others) to communicate directly with Arduino. Maxuino is a collection of Max patches that uses the Max serial object to implement Open Sound Control (OSC). Together, they provide the magic of communicating with your Arduino by using OSC.

Get Started
Get started by visiting Maxuino.org, and following the instructions. I won't duplicate any of that here, since it's fairly straightforward, although I will note that they have their own customized version of Firmata. Once you've got the files all nicely ensconced in your search path, and Firmata Standard is loaded on your Arduino, test it out to make sure it works (hit pin 13 with a digital out or something). Be sure that maxuino.help.maxpat is set to the correct port. If this is your first time, be warned that getting Max to talk to Arduino can be somewhat fiddly. If it doesn't work the first time, you can try hitting the reset button on the Arduino and then resetting to the correct port. If that doesn't work try unplugging and replugging the Arduino, and then resetting to the correct port.

Minimal Max Patch
I don't know about you, but after poking around in those patches I wanted to create my own patch for a fuller understanding of the bare minimum required to get things working. There is a lot going on in there! To be clear, so far all I want to do is send a signal to the Arduino to light up the default status LED on pin 13. Once that all-important task is done, I can be sure that communication is enabled, and attempt to send data back to Max. The first thing to address is setting the correct port number for the Arduino. I lifted the function straight out of maxuino.help.maxpat and plopped it into my patch:

The heart of this patch is the "devices" patcher, which looks like this:

Now I'm primed to add the rest of the Maxuino code, which consists of two parts: maxuino-gui.maxpat which handles OSC routing and UI interaction, and maxuino.maxpat (shown here as "maxuino a"), which contains JavaScript that interprets output from maxuino-gui.maxpat and sends it to the Arduino to be interpreted by Firmata. I also copied maxuino-gui.maxpat and maxuino a from maxuino.help.maxpat. Note that I first had to rename "maxuino-gui" to "maxuino-gui.maxpat" in maxuino.help.maxpat. I patched them together as shown here:

That's a good start, but I still need to flash that LED. The example patchers in maxuino.help.maxpat demonstrate how to set pin modes and use the various outputs. I took the code on the far right side and added it to my patch. I connected the output of the prepend object to the first input of maxuino-gui.maxpat. Now it looks like this:

Now I should be able to click "update", set to the correct patch (in this example it's COM4), set the pin number for pin 13, and click the toggle to turn my LED on, and then turn it off! Again if this doesn't work the first time try resetting your Arduino and setting the port again. The message box at the bottom shows what the OSC message looks like. This will only work on a digital pin, as we're sending a digital out message.

Get Some Input

Although flicking an LED on and off can be hours of fun, it's only half the fun we could be having. What if we were to interpret a signal sent from a digital pin on the Arduino? That would be so awesome. The part of maxuino.help.maxpat that shows how to handle input is the Analog-Digital-Inputs patcher. In order for it to work though, the pin of choice on the Arduino must first be set to mode 0 for digital input. This is demonstrated in the Pin-Modes patcher. I went ahead and copied both of those, pasted them into my patch, and connected them as shown here:

NOW we're really ready for some hot Arduino on Max action! Connect one lead of a button to digital pin 7, and the other to ground. Now open the Analog-Digital-Inputs patcher, and watch what happens when you press the button. More hours of fun!!! At least three hours and 27  minutes by my last estimate.

Watching Messages

The maxuino a subpatcher has a couple of gswitches that you can use to print out messages and see what they look like. Open the subpatcher, toggle the switches, and watch what happens when you press buttons in the maxuino-gui.maxpat interface. Set a digital pin to PWM and move the slider around. A handy way to monitor what's going on when you use the Maxuino patches. Of course you can also attach your own print objects wherever you like.

Analog Input

What's the most popular kind of input? Analog input! Well okay, I'm not sure if that's 100% true, but wouldn't it be fun to get a potentiometer wired up and watch it moving a slider around? I think so! First, wire up a potentiometer according to these instructions. Next, open the Pin-Modes subpatcher and set your analog pin of choice to mode 2 for Analog In (I selected pin 0). Finally, open the maxuino-gui subpatcher and turn on the pin of choice in the list of Analog pins. Now twist the pot, and you should see your slider moving around. For extra fun you can add a print object and watch the values come out. I connected mine to the output of the maxuino a subpatcher along with a gswitch.

Now What?

As promised, Maxuino and Firmata together enable you to completely program the functionality of your Arduino from within MaxMSP. At this point you can add any type of functionality you want, from something as simple as connecting the button to the LED, to reading input from a sensor and adjusting a parameter on a synthesizer, to detecting input and dynamically generating user interface elements to match. You could write a patch to control a dancing monkey with LEDs for eyes. And all you need to do is use OSC to make calls to Maxuino from within MaxMSP. Pretty sweet!!

Obviously the excellent Maxuino patches serve well for instructional purposes, and I found it really helpful to break them down and simplify them to have a closer look at how (most of) it works. When I write an actual Max patch, I foresee a somewhat different design pattern. First of all, my code is going to be directed at an Arduino-based device that is hard-wired for a specific purpose. I think it would be easy to come up with a subpatcher to initialize the Arduino with the correct configuration at startup (loadbang), so that all of the pins are set to the right values, activated, etc. I'm still not sure if enabling/disabling pins has any effect on the performance of the unit. Obviously UI design is a consideration, and the Maxuino patches are a wonderful starting point for that. I think my design would probably still include judiciously placed Print objects, since I like to see values when I'm programming (who doesn't).

There are other issues as well, such as whether it is possible to have multiple instances of a Maxuino patch running at the same time. I did run into some behavior while writing this posting that suggested you can only have one instance open at a time. I'm not sure which steps to take to bypass this seeming limitation. Another issue is "how would this work in Max for Live?" and you will find that there is a Maxuino.amxd patch included. I intentionally did my experimentation in Max proper to avoid having to deal with any Live-specific issues, although I did run the .amxd and it worked fine.

Source Code

Here is the source code for my humble little patch: maxuino-simplified. Copy it to your clipboard, and then use File/New From Clipboard to open it in Max. Note that none of this will work unless you have properly set up Maxuino on your system.

More Information
Read these interesting articles on the creators of Maxuino and Firmata:
An Interview with Chris Coleman
An Interview with Ali Momeni


29Sep/100

Building a Bliptronome, part 2

In the first posting, I walked through the steps I took to build a Bliptronome, up to the point of plugging it in and testing it using MaxMSP. The remaining steps now consist of:

  • Cutting a little slot in the case to expose the header pins.
  • Mounting and connecting the potentiometers.
  • Stuffing everything back into the enclosure and screwing it back together.
  • Re-sticking the little rubber feet.
  • Downloading some Monome apps and stuff.

Marking the Slot
My goal here is to mark the spot on the top shell where I will cut a slot so that the USB-BUB can plug in to the header pins. Since my circuit board seems to be angled up a bit, I first put a screw into the mounting hole nearest the pinout to get a more accurate idea of how it will fit with the top. I then set the top of the case on the bottom half, taking care not to offset the placement of anything.On my unit the header pins protrude exactly to where the edge of the case will be. You can see the spot where I used a marking pen to draw the shape of the slot.

Cutting the Slot
[WARNING: The next section features using an X-acto blade. These blades are very, very sharp. Please use caution when working with them!]

I busted out my X-acto #11 blade, thinking that it will be the best tool for the job. Well, the plastic on the case is mighty thick. I don't have a micrometer, but my eyeball tells me it's in the vicinity of 3/32". So I keep cautiously cutting along the outline of where I think the slot should go, trying to get deeper without slipping and scratching the edge. Well crap, at least I tried. It's difficult to get a good hold on the piece, and also avoid slicing into my own tender flesh. As I cut, I can see that the top line is a bit crooked, so the suggestion to finish with a flat file seems like a good call. Hopefully I have a file that'll fit because man, that is one sloppy looking slot.

Finishing the Slot, Painting
In fitting the top half to the bottom again, it's pretty clear I didn't make my slot deep enough. I was going to see if I could deepen it with a file, but I couldn't find a file! I could have sworn I had at least 3. I found some sandpaper and tried that, and ended up making some very noticeable scratches. So add spray painting the sides to my list. In the meantime I need to go out and get a file! A quick rummage through my bin of potentially useful miscellaneous items turned up a quite handsome set of small hobby files. Perfect! The slot is a bit deeper than I wanted but it's about as square as it's going to get. I'm gonna find some spray paint to hide those scratches and beautify the finish a bit. I sure wish I'd have looked in that box before using the damn sandpaper. Ah yes, and I also dabbed a bit of model glue on the edge of the play button to keep it from rattling around.

[Fsst! Fsst! I'm spray painting in my driveway at 11:45 p.m. Dry, dry, dry.]

The next morning...
The paint is dry and it looks good! I used a silver metallic, let it dry for about half an hour, then laid on some irridescent overcoat. I masked off the knob area so I could paint over the default markings since they're no longer applicable. The messed up slot looks a lot better, too. Overall a success! One minor tip, try not to fudge with the case too much like I did, you can see in the photo that the metal outer layer is offset a little, the result of my efforts to carve the slot.

Installing the Potentiometers
The potentiometers that came with the kit are pretty typical. They are nice and compact with three contacts, to be connected in series (the instructions detail this). Before installing them, I am going to mark where the flange points line up with the case, and then drill some teeny little holes in there with my electric drill. As mentioned in the instructions, a 1/8" bit looks the way to go here. First I set one of the pots into its spot, then use an X-acto knife to mark approximately where the flange will sit. If you plan to do any kind of case mods for projects (circuit bending, anyone?) this is a great technique to use. In this case, we can even avoid poking our flange holes through to the other side.

Drilling the Flange Holes
I use my drill to put the holes in. Some of them overlap the edges of the holes that are already there, but that doesn't matter. Plus the metal part acts as a shield for people like me who wait until they feel the bit hit the metal. It's like they saw me coming!! I used a 10mm socket to hand tighten the nuts down. As the instructions say, do not overtighten or you will squoosh the innards of the potentiometers.

Soldering the Pots
The pots are in, so as Buck Owens once said on Hee-Haw, it's time to start Strippin and Tinnin. At least I think that's what he said. I've got some 26awg hookup wire that should do just nicely, since those holes are pretty small. The pots are to be daisy chained, so I'll strip and tin each set of connections. I made my wire segments about two inches long. First I'll chain the GND solder pins (left-hand side), and then the 5V solder pins (right-hand side). The middle pins are a bit more complicated, so I want to double-check against their positions on the board as I make those connections. And here are the completed potentiometers, or ADC controllers as they should now be known.

Putting it Back Together
This part took me a couple of tries, as the black insert sheet got knocked out of position and subsequently de-clicked one of the middle buttons. A second attempt was 100% successful. monome_test reveals that all buttons and ADCs are fully functional. In the ArduinomeSerial settings, I have left the Cable Orientation set to "left". One more note, plug the unit in BEFORE turning on ArduinomeSerial, or else your device might not be recognized. Also there is a setting called Address Pattern Prefix that seems to be specific for each type of MaxMSP app you run. You need to set that field in ArduinomeSerial to match the app you choose.

Aaaand, here is the final finished product:

I ended up going with the Boss-style stompbox knobs because I really like the way they fit these pots.

And here are some excellent resources for the Bliptronome Kit, Monome, electronics and that.

Resources:

Now to spend some time with my new creation. I'd like to write a bit more about the software aspects of Bliptronomics, but first I'd like to play!

27Sep/100

Building a Bliptronome, part 1


The Bliptronome is a low-cost open source alternative to the coveted Monome hardware controller, that is the result of modifying the Bliptronic instrument in a radical electronic transformation.

Will Lindsay at Stray Technologies has figured out how to hack a Bliptronic, and has created a marvelous kit that contains all of the components you need to change this bleeping box of buttons into a fully functional Monome one-off. The primary advantage here of course is that it costs somewhat less than building one of the official Monome, or Arduinome kits. If you know how to operate wire cutters and a soldering iron, you're in business. Well I guess that makes me barely qualified.

I acquired a Bliptronome and a Bliptronic kit a few months ago, and haven't assembled it yet. Today is the day! So first I shall get into a suitably blippy mood with the help of some coffee, and some delicous tunes from the Subvariant record label. They have some awesome free compilations available to download so it's well worth your time to check out if you are into the electronica. Which I decidedly am.

Let us begin the operation. I am using the provided instructions, which are so good it makes me wonder why am I even writing about this? I don't know. At the very least someone might find this useful, and if it sends a little business back Will's way so much the better!

1. Lay parts and tools out.
Before I started I was a good boy and laid out all of the stuff on my little work table. Yes, I am crazy for using such a small work table.

2. Open Bliptronic case.
First I removed the knobs, using my Swiss Army knife to pry them loose a bit first. This only took a gentle effort. Next, I removed the screws which are under the rubber feet. I saved the rubber feet by sticking them to the plastic bag that the included USB cable came in. I plan to re-stick them later.

Now it's time to pry the thing open. My unit seemed to be easier to open from the side opposite the jacks. This took a bit of wiggling, but I managed not to break anything. I carefully separated the halves, trimmed the speaker wire, and set the top of the case aside. The button pad stays attached to the top of the case. I trimmed the battery wires, which I won't need again, and also the ribbon cable which will be used for the potentiometers later.

Now to heat up the soldering iron. I got to try out my new Hakko tip cleaner, too. Nice. I am very concerned about getting the best quality soldering, and NOT messing up anything. The soldering was relatively uneventful.

Soldering is done, connections are shiny and decent. I think it's okay, although I can almost hear the voice of my 11th-grade electronics teacher, Mr. Post, who may as well have been looking over my shoulder just now because I just discovered that I soldered the 6-pin FTDI header to the wrong 6 holes. Crap. That means I'm done for today. If you are doing this be absolutely sure that you are connecting the components in the proper orientation. Check EVERYTHING before you commit it to solder. There is a photo on page 4 of the instructions that clearly shows which side of the board it attaches to. Also be sure to heed the following: "The 6 pins should bend at a 90 degree angle from the bottom of the board". That means the angled part is actually the side that connects to the board. Take a look at the photos in the instructions for an idea of how all of the parts are oriented together.

I quickly discovered that there is no way I am going to be able to desolder the headers with my soldering iron. I don't have a hot air gun or even a toaster oven. Instead I go online to order another right-angle 6-pin header to put into the right holes. I ordered the parts from Modern Device an online store with everything you might need if you start tinkering with the world of open source hardware.

Five days later...
YAY! My bag-o-headers just arrived in the mail, and now I can continue. Such a tiny thing, yet so vital. Stock up on stuff like this, because you sure the heck aren't going to find it at Radio Shack (not that I would be lame enough to...oh nevermind). A nice benefit is that since I ordered the pack of male + female headers, I was able to use one of the nice right-angle female headers to attach the USB-BUB board. It came with straight connectors which I could have bent, but hey, these came already bent. Time savings: 0:34 seconds.

I made the remaining solder connections, and then assembled the boards for testing. Then I plugged it in and crossed my fingers. And I was indeed greeted with a Shangri-La of scrolling red LEDs. A successful powerup!! Not only that, but Windows 7 automatically installed the drivers. Cool. However there is one other critical software program that needs to be installed: ArduinomeSerial. This is the software that translates native serial protocol to OSC, enabling the device to communicate with your OSC-compatible software. When you go to the download site, note that this isn't the firmware source. Find your way to the "Files" area and get the ArduinomeSerial and you're good to go. I installed ArduinomeSerial, launched it, fired up MaxMSP, and opened monome_test. It works! I am so happy! And judging from the photo, my Blip is happy, too. As it should be. Happy birthday, Blippy. Note that the grids in monome_test are set up for a 256. Alas, Blippy is a 64, so only the upper left quadrant of the grid in monome_test affects it. Also, the proper orientation is with the USB-BUB connection facing away from you (I got a bit disoriented for a moment). You can adjust the orientation of the unit through ArduinomeSerial. More on that in my next post.

This is what the test software looks like. Monome provides a whole raft of great Max patches along with the test software so you can start coding your brains out immediately. However I am going to wait until the rest of it is finished.

Now that it's all tested, time for me to take a little break. Stay tuned for the breathtaking conclusion, in which I will:

  • Cut a little slot in the case to expose the header pins.
  • Mount and connect the potentiometers.
  • Stuff everything back into the enclosure and screw it back together.
  • Re-stick those little rubber feet.
  • Download some Monome apps and stuff.

Until next time, cheers!