Downtown Doug Brown

Found a neat blog will all kinds of topics on basic Microcontroller programming (as well as Linux and Mac hacking): http://www.downtowndougbrown.com/. The microcontroller-specific topics are here: http://www.downtowndougbrown.com/category/microcontroller-programming/. The author writes long-winded posts just like me! I can tell we’d be friends.

One of the things that caught my eye was the collection of posts on SPI and also the fact that a lot of the programming examples and techniques target AVR (which I’m trying to get into).

Hack a Guitar Hero drumset to use it with any computer over USB, Part 5

 

BitBucket repository is live: https://bitbucket.org/MostThingsWeb/usbdrumming/src
In the final post in this five part series, I’ll develop a client side application in Python to communicate with our drumset which was modified in part 4.

The final result will be a simple command line interface (for now) that looks like this:
 

 

Requirements

Before even choosing the language I wanted to use, I decided to list a few requirements for the client-side software.

  1. The software will automatically detect the drumset; the user will not have to manually choose a serial port.
  2. The software will support playing multiple drumpad sounds at once (like a real drumset). This will require audio mixing.
  3. The software must be cross-platform and easy to install.

 

My development process

I ended up developing this application three times: twice in C# and once in Python. There was also almost a C++ version. In this section, I’ll explain the initial prototype versions and why I decided upon Python in the end. To do this, I’ll go down the list of the requirements.

Requirement 1 is easy: if you remember, back in part 3 we added a feature to the embedded software that supports responding to “pings”:

// The client might want to know what we are, so let
// them ping us
if (Serial.available()){
  while (Serial.available()){
    Serial.read();
  }

  Serial.println("{ "msgType": "ping" }");
}

I didn’t want users to have to figure out which serial port to use. It should Just Work™. This is a very simple feature to implement, and because of this, requirement 1 didn’t actually steer me towards any one language.
 
Continue reading “Hack a Guitar Hero drumset to use it with any computer over USB, Part 5”

Hack a Guitar Hero drumset to use it with any computer over USB, Part 4

 

BitBucket repository is live: https://bitbucket.org/MostThingsWeb/usbdrumming/src
In part 3, we finished fleshing out the details of the hardware and embedded software. In this part, we’re going to build it!
 

Ready? Let’s begin…

…by reading this first

Let me preface this post by saying that I am not responsible if you destroy your drumset, burn down your house, spoil your appetite, etc. These instructions are accurate to the best of my knowledge, but I assume no responsibility for anything that may come from you following them (unless you win the lottery – in that case, I take checks or PayPal).

One more thing. This project involves soldering really tiny surface mount parts to a tiny board on both sides (and uphill, both ways). So I wouldn’t recommend this as a beginner soldering project.
 

The plan

You will be assembling a PCB that I designed. This PCB implements all the features of the schematic we finalized in part 3. Here is a picture of a completed board, soldered onto the Pro Micro:

Let me explain what you are seeing:

  • The purple board is the board I designed.
  • The red board (bottom) is the Pro Micro 3.3V, which is soldered to the purple board.
  • The white Molex connector is for the RGB LED.
  • The two surface mount chips are the tri-stating buffers.
  • Finally, and most importantly, the two right-angle female headers are connectors for the control box and drumpad controller.

Disclaimer: This board was autorouted out of laziness. If you’re better at using Eagle than I am (or just more motivated) please by all means grab the Eagle files and manually route it. If you do this, don’t forget to send a pull request my way on BitBucket! Should the average person care about it being autorouted? Probably not. Some vias might obstruct the silkscreen in some places, but you should have the reference PCB layout in front of you anyway.
 

Resources

All components of this project (software, hardware, and misc. development tools) are available at BitBucket here. For this part, you should only care about the hardware folder.
 
Continue reading “Hack a Guitar Hero drumset to use it with any computer over USB, Part 4”

Hack a Guitar Hero drumset to use it with any computer over USB, Part 3

 

BitBucket repository is live: https://bitbucket.org/MostThingsWeb/usbdrumming/src
In part 2, we finished up the initial drafts of the hardware and embedded software for the drumset. Now, we’ll make a few modifications to our circuit and software to add some additional features.
 

Improving the circuit

Let’s add three more things to your circuit:

  1. Some kind of indicator, so we know it’s working.
  2. Decoupling capacitors
  3. Circuity to detect when the control box and Arduino are on at the same time (a conflict)

 

Indication

I wanted a visual indicator that would quickly indicate the status of drumset, so I chose to install a big RGB LED right in the back of the drumset. Specifically, I chose this 10mm RGB LED. If you look at the back of your drumset, you can see a little plastic panel where the pedal and MIDI “in” ports are installed. That panel is taken, but if you look opposite the control box (still on the back of the drumset), there’s some open space. That’s where we will eventually install a hole for the USB cable to come out of, as well as the LED.

The LED – image property of SparkFun

Side note: This indicator LED is optional, though highly recommended. It will involve you drilling a hole in your drumset, which is a very delicate operation because of the weak plastic (sawing the hole for the USB cable is far easier). If you choose not to install the LED, you will probably save yourself half an hour, but you will lose an important feature. Plus the LED is really big and shiny. I’d recommend you install it. If you want, you could go for the smaller 5mm version instead of the huge 10mm LED. Just be sure that you get a common cathode LED.
 

Decoupling capacitors

We just need two decoupling capacitors: one on each of the buffer chip power supplies. I tried adding decoupling capacitors on the control box and drumpad controller, but the added capacitance caused a bunch of problems, so don’t do that. Also, you don’t need one on the Arduino’s power supply because it already has decoupling capacitors on the board.
 
Continue reading “Hack a Guitar Hero drumset to use it with any computer over USB, Part 3”

VirtualScroller 1.1.1 released

I’ve updated VirtualScroller (grab the latest download here). Here is the change log for the new version:

  • Breaking change: The return value of the factory method now returns an object, not a View. To access the VirtualScroller view (to add it to your view or window), you need the view property of the return value. See the Wiki for more information.
  • Dispose method: Call the dispose method to clean up event listeners and views used by the VirtualScroller instance. Not required but highly suggested.
  • Improved anti-jitter: With this new update I can almost guarantee that your VirtualScroller instance will never end up in an invalid state. In the past, this has happened when someone scrolls the VirtualScroller too fast.
  • Improved options handling: Internally, I’ve added deep option defaulting, which gives you the ability to override properties in sub-options (like top in containerDef, for example) without overriding the entire object. This functionality is similar to jQuery’s $.extend.
  • Accessibility: Set touchSupported to false (the default is true) to enable support for trackball navigation of the VirtualScroller. This is useful if you plan to publish your app on Amazon Appstore, or another app store that doesn’t require devices to have touchscreens.
  • Auto-focus: Set autoFocus to true and the first child of each view will be focused automatically upon viewing.

Access the updated documentation here.

Hack a Guitar Hero drumset to use it with any computer over USB, Part 2

BitBucket repository is live: https://bitbucket.org/MostThingsWeb/usbdrumming/src
Continuing where we left off from part 1, let’s plan out some of the hardware that will interface with the drumset. A little bit later, we’ll prototype the embedded software.
 

Planning the hardware

We already know that the control box and drumpad controller communicate with SPI. Below is a simple (highly abstracted) schematic showing the existing drumset circuit. Note that the drumset uses 3.3V logic. This will be important when choosing a microcontroller.

SPI is a simple protocol to work with, so let’s plan on somehow having our hardware take control of that SPI bus.
 

Choosing a microcontroller

I decided early on that I wanted to use some kind of Arduino, instead of just a bare microcontroller, for a few reasons:

  • USB connectivity: Many Arduino-compatible development boards have a USB connection built-in, so it would be easy to connect the finished product to my computer. Of the three, this was the most important factor to me.
  • Simplicity: My hope is that other people will follow the (impending) tutorial. I didn’t want to require that people not only solder together the drumset interface circuit, but also a microcontroller circuit.
  • Ease of prototype: After I’m done prototyping on a breadboard, it will be easier to transfer my circuit to protoboard since I’ll have less parts to route.

Continue reading “Hack a Guitar Hero drumset to use it with any computer over USB, Part 2”

Detecting a touch screen in Titanium

I looked through the Titanium documentation and user boards, but I couldn’t find a simple way to detect whether a device has a touch screen (as opposed to a trackball). Obviously, all iDevices will have touch screens, so this code is really meant for Android and web deployments.

Here is my very primitive (but functional) solution. Place this code where the first window that your user interacts with is created.

    Titanium.App.Properties.setBool("touch", false);

    function touchStart(){
        Titanium.App.Properties.setBool("touch", true);
        self.removeEventListener("touchstart", touchStart);
    }

    self.addEventListener("touchstart", touchStart);

The first time the user touches the screen (indicating that a touch screen is present), an application-wide setting is written indicating touch support.

In the rest of your application, check for touch support with:

var hasTouchSupport = Titanium.App.Properties.setBool("touch", false);

Note: I found that it was necessary to first clear the setting, for some reason, at least during debugging on an emulator. You could probably get rid of that first line.

Using Appcelerator Titanium with Android on 64-bit Windows 7

If anyone else is having trouble with the combo of Titanium, the Android SDK, and Windows 7 64-bit, then maybe this post if for you. It took me a few hours to get right.

Upon clicking “Android Emulator” under the Run button, I was receiving errors about jarsigner and java missing. Here’s what you have to do:

  1. Titanium requires the 32-bit version of the Java SDK, even if you are running on 64-bit Windows. Furthermore, it requires Java 6; Java 7 is the default.
  2. Uninstall all other versions of Java, and download Java 6 (which appears to be version 1.6, as opposed to Java 7 which appears as 1.7) for 32-bit from here: http://www.oracle.com/technetwork/java/javase/downloads/index.html
  3. Install that.
  4. Set your JAVA_HOME path by following these steps: Go to your Start Menu, right click on Computer, click Properties. Click Advanced System Settings on the left, go to the Advanced tab, and click the Environment Variables… button at the bottom. Under System Variables, and click New… Name is JAVA_HOME, and value is something like C:Program Files (x86)Javajdk1.6.0_33, with the path possibly varying depending on the exact version of Java you installed.
  5. Now, add the bin directory to your PATH variable. Still in Environment Variables, under the System Variables section, find Path. Click Edit…, and in the Value box, append a semicolon if one isn’t already there. Then, append C:Program Files (x86)Javajdk1.6.0_33bin, taking note that your exact path might be a little different.
  6. Click Ok twice to get out of both dialogs.
  7. Restart your computer – yes, really. It simply won’t work if you don’t.

Side-rant: Why can’t Java configure the damn path variables for me? It couldn’t possibly be that hard to have the installer perform these two simple steps. I propose a new slogan. Java™ : Complexity for the sake of tradition.

Further troubleshooting

If you still get errors, then make sure you got all the paths to your JDK right. Actually navigate to the exact directory and copy the path from the address bar, instead of relying on the exact paths that I posted above.

If you still get errors, then make sure you have the right version of the JDK installed. Remember: 32-bit, Java 6 (1.6).

VirtualScroller: A Titanium module supporting memory-efficient finite and infinite scrolling

Time to release something new. I’ve been working on a little project to develop an Android app. I’ve chosen Titanium because the app is simple (no network connectivity, sensor interaction, maps, etc.) and the learning curve for Titanium is low.

I had been working with the Android SDK for about a week (very frustrating), and one feature I found to be missing from Titanium is a decent way to scroll through large datasets horizontally. In my case, I had a few dozen pages that needed to be scrolled. I didn’t want to plop all of them into a ScrollableView, since that would put a strain on Android. So, I created this little module.

It is based off of this GitHub gist, though it doesn’t bear much resemblance anymore. Scroll down for links to my project.

VirtualScroller

The module I created is called VirtualScroller, and you use it like this:

// Replace the path as necessary
var VirtualScroller = require('ui/common/VirtualScroller');

var virtualScroller = VirtualScroller({
    itemCount: 10,
    getView: function(i) {
        return Titanium.UI.createLabel({
            width: Titanium.UI.FILL,
            height: Titanium.UI.FILL,
            text: "This is item " + (i + 1)
        });
    },
    infinite: false
});

window.add(virtualScroller);

I’ll steal the description from my BitBucket page, since I don’t feel like writing a new one:

VirtualScroller is an easy to use Titanium module that wraps around a ScrollableView and provides finite and infinite scrolling. All items (which are actually Views) are created on-demand, and only remain in memory when needed. The ScrollableView instance has three Views, which act as containers for the actual items.

This method permits memory-efficient scrolling of large sets of views.

So, if you have a large amount of views to scroll through, but don’t want to load them into memory until they’re needed, check out my module. It supports finite and infinite scrolling, and uses a callback to generate each view only when needed.

On BitBucket:
Wiki (instructions and information)
Downloads

Hack a Guitar Hero drumset to use it with any computer over USB, Part 1


BitBucket repository is live: https://bitbucket.org/MostThingsWeb/usbdrumming/src

So, you’ve got one of those Guitar Hero (World Tour) drumsets, and want to use it with your computer? Are you also looking for a fun DIY project involving soldering, electronics, and possibly voiding a few warranties on consumer hardware? Great! Read on.

My humble drumset

Continue reading “Hack a Guitar Hero drumset to use it with any computer over USB, Part 1”