This is a tag page.

Connecting to the Bus Pirate

John Peck
Published , updated

The Bus Pirate is a cheap way to talk to I2C (and a lot of other serial protocol) devices from your laptop. I use it to bring up new boards -- making sure everything works before they get integrated into a bigger platform. Specifically, I've been using the Bus Pirate version 4 (BPv4) shown below.

bpv4

Dangerous Prototypes has built the Bus Pirate's API into the hardware with its binary bitbang firmware mode. This is great, since it means you don't need a separate piece of software running on your laptop to run the API -- you can use whatever scripting language you want.

Connecting to the BPv4 is just like connecting to any other USB CDC (ACM) device. The version 3 Bus Pirate has an FTDI device to handle the communication, while the BPv4 moves the USB stack into a Microchip PIC. You'll have the usual first-time problems: Windows wants an INF file, and Ubuntu wants your user to be in the same group as the device node. I linked the INF file I used below.

Once those basics are in place, the details of communicating over the channel are determined by your choice of scripting language. I use Tcl for things like this, so I need to use commands like chan configure. The debug log shown below shows the script doing a brute-force search of all connected devices.

bpv4<em>connection</em>trace

I'll go into what this potset script is later. For right now, notice that the script identified two potential device nodes: ttyACM0 and ttyACM1. The script will connect with the first device that reponds to a carriage return with HiZ>. The busbridge repository shows how I did things. The BPv4 actually has an eeprom that could be used to "tag" different Bus Pirates if you wanted to work with more than one at once.

Going forward

The next step is to activate the BPv4's API to set up SPI or I2C communication. I'll talk about that later.

References

Busbridge

BPv4 Windows INF file

Create pipe tables from PCB's drill files

John Peck
Published , updated

I use PCB to design PCBs, and I recently needed to embed a list of drills and their uses in a plain text file. PCB's drill file looks like this:

M48
INCH
T72C0.010
T71C0.015
T70C0.067
T69C0.039
T68C0.030
T67C0.046
T66C0.138
%
T72
X010249Y009035
X010249Y005886
X010268Y008256
X010268Y007075
X010268Y005107

...and I wrote drilltable.tcl to generate tables like this:

|------------+----------------------+------------|
| Tool       | Hole size (inch)     | Count      | 
|------------+----------------------+------------|
| T72        | 0.010                | 218        | 
| T71        | 0.015                | 95         | 
| T68        | 0.030                | 3          | 
| T69        | 0.039                | 10         | 
| T67        | 0.046                | 15         | 
| T70        | 0.067                | 1          | 
| T66        | 0.138                | 4          | 
|------------+----------------------+------------|

This borrows from an excellent usage example of Tcl's format command at the Tclers Wiki.

Use teacup to install Tcl's math packages on Ubuntu

John Peck
Published , updated

Download ActiveTcl from ActiveState

ActiveTcl provides teacup, which is a client for the TEApot package server. The Tclers wiki provides much more information about all this.

I unpack the downloaded file in some temporary directory. There's an install.sh file in the root of the unpacked archive.

$ sudo ./install.sh

...will start the graphical installer. I just accept the default /opt/ActiveTcl-8.6 installation directory and accept all the terms.

View the available packages list

With the default installation directory, I need to be root to use teacup. I also need to add it to my path.

$ sudo su
# PATH=/opt/ActiveTcl-8.6/bin:$PATH
# teacup list

See the edit below for more about problems with permissions.

Install your package

I want to install math::statistics, so

# teacup install math::statistics

<snip>

Retrieving package math::statistics 1.0 tcl ...@ http://teapot.activestate.com ... Ok

Installing into /opt/ActiveTcl-8.6/lib/teapot

Installing package math::statistics 1.0 tcl

Check your work

Start tclsh to make sure you can require math::statistics as an ordinary user.

# exit
$ PATH=/opt/ActiveTcl-8.6/bin:$PATH
$ tclsh
% package require math::statistics
1.0

...and that's success! Of course, you can make your life easier by adding the PATH command to your .bashrc or .bash_profile script.

Edit on Saturday, September 24, 2016

I could not install ActiveTcl in a way that allowed an ordinary user to use teacup. I tried installing everything into /home/john/opt instead of /opt, but teacup then created a ~/.teapot directory owned by root. So I guess users of "locked down" systems will need to find another way to get the packages they need.