Pirates and SPIs

"Pirates and SPIs" sounds like a cheesy adventure story, but I'm afraid it's more likely to be a serial than an exciting drama.

A few days ago I had a delivery of some components I had ordered, including a MCP3002 analogue to digital converter. The data sheet for this device claims that it can do 200k samples per second (when powered at 5V) and it has a high-speed SPI interface so it should be fairly strauightforward (probably with the use of some level converters) to wire it straight to the Raspberry Pi SPI pins.

I have never done something like this from scratch before, so I thought I'd err on the side of cautious experiment, so I also ordered a "Bus Pirate". This interesting device claims

"The Bus Pirate is an open source hacker multi-tool that talks to electronic stuff. It's got a bunch of features an intrepid hacker might need to prototype their next project"

I had seen several mentions in my travels around the web of people who had made good use of this device, which positions itself as a kind of "swiss army knife" of serial communications.

My initial got at using the Bus Pirate consisted mostly of connecting it to my development PC, setting up the USB serial port driver, and running its self test. The self test is pretty clever, link together two pairs of pins on the interface socket and run a menu command over the serial command console. Everything checked out OK, and I removed the self-test links.

Bus Pirate

After that, though, Things slowed down a lot. The device is obviously very powerful, and has a very concise but very extensive command syntax. Most commands are just a single character (see the SPI page for some examples), but can be combined in endless ways. The web site is also a bit rambling, and I bumped into several broken links. The main problem I had, though was trying to "connect the dots" between the various documents. The Bus Pirate docs are written from the point of sending and receiving values, while the MCP3002 datasheet is all in terns of signals and clocks. Somewhere in between there must be an example of using the Bus Pirate to talk to this kind of device. I just haven't found it yet.

Never mind. I'll keep trying.

No related content found.


  1. Just an “educated guess” as I don’t have an MCP3002 nor a BusPirate (been meaning to order a BusPirate for ages though, just never quite got round to it), but from reading the datasheet (Chapter 5) and the insructions you linked to, it looks like the BusPirate command string you want is:
    And then you’ll have to do some bit-manipulation (and arithmetic) to convert the two read bytes back into the analogue voltage on CH0… to read CH1 instead you’d change the command string to [0b1111r:2]

    At least, that’s what my limited understanding says ;-)

Leave a Reply

Your email address will not be published. Required fields are marked *