Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.

Channels ▼

Al Williams

Dr. Dobb's Bloggers

Rocking with sigrok

January 29, 2013

A coworker asked me about buying a telescope the other day. I gave him advice I'd received earlier: The best telescope is one that you will use. If you have a $100 telescope that takes 5 minutes to set up, you might use it more than an $800 telescope that takes two people an hour to set up. So even though the $100 telescope isn't really all that great, it is a better value because you will use it more. Last time, I was talking about my inconvenient logic analyzers; this time, I'll tell you more about my quest for convenience.

A little eBay shopping let me pick up an "ArmFly" logic analyzer for about 10 bucks. No kidding. It is a Cypress CPU that receives a firmware load from the host computer. In reality, it is a clone of the USBee hardware, although as far as I can tell they all originate from a Cypress reference design. From what I have read online, there is a constant battle to keep the USBee software from running on these clones, but since I wanted Linux software anyway, that didn't concern me (there is no USBee software for Linux).

The open source software sigrok supports the ArmFly (and the USBee, and a host of other logic analyzers and similar instruments) and my plan was to use that. In the end, I did wind up using it, but not in the way I expected.

There are a few things that sigrok suffers from and the main one is out of date or lack of documentation. Another item is that some of the ancillary pieces are not quite ready for prime time. For example, the serial UART decoder has a comment in the code that there needs to be a way to invert the incoming signal, but it fails to provide a way to do that (short of writing your own code, of course). The GUI front ends are not really polished nor do they offer all available features.

None of these problems are insurmountable, but they do detract from the overall package. Of course, the strong parts of sigrok are its wide array of input and output options. Last time I showed you the LogicSniffer software and — not surprisingly — the sigrok tool can output in that file format.

Once again, I hooked up an Arduino with a simple SoftwareSerial test program:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup()  
  // set the data rate for the SoftwareSerial port

void loop() // run over and over
  mySerial.println("Hello, Dr. Dobb's.");

With a probe on pin 11, sigrok can dump a "graphic" right to the terminal:

Cute, but hard to read. Note the command line:

sigrok-cli --driver fx2lafw --samples 1024 -O ascii -p 1

Despite the current documentation, this is the correct way to use the tool. The --driver options tells the software what device to look for. In my case, all of the Cypress-based cheap analyzers use the same driver, fx2lafw. The rest of the options are self-explanatory. Collect 1024 samples from probe 1 and emit them as ASCII. You can read up to 8 channels at once with this hardware.

It takes some detective work to figure things out. If you use the --show option you can learn more about the driver's support for your hardware:

[email protected]:/tmp/sigrok$ sigrok-cli --driver fx2lafw --show
CWAV USBee AX with 8 probes: 0 1 2 3 4 5 6 7
Supported triggers: 0 1 
Supported device options:
    samplerate - supported samplerates:
      20 kHz
      25 kHz
      50 kHz
      100 kHz
      200 kHz
      250 kHz
      500 kHz
      1 MHz
      2 MHz
      3 MHz
      4 MHz
      6 MHz
      8 MHz
      12 MHz
      16 MHz
      24 MHz

That tells us that there's an option for the driver called samplerate. The values are fairly tolerant. For example, 25 kHz can appear as '25 kHz', 25khz, or even 25000. Let's go to 100kHz sampling:

sigrok-cli --driver fx2lafw -d samplerate=100khz --samples 1024 -O ascii -p 1

The same trick works for learning about protocol decoders:

[email protected]:/tmp/sigrok$ sigrok-cli -a uart --show
ID: uart
Name: UART
Long name: Universal Asynchronous Receiver/Transmitter
Description: Asynchronous, serial bus.
License: gplv2+
  Data bytes as ASCII characters
- Decimal
  Databytes as decimal, integer values
- Hex
  Data bytes in hex format
- Octal
  Data bytes as octal numbers
- Bits
  Data bytes in bit notation (sequence of 0/1 digits)
. . .

The output goes on, including wording about inverting data. However, in the actual code there is simply a comment that inverted input is "to do."

I can change the -O ascii option to -O vcd and get a dump that is just what I would get from a typical Verilog simulator. A tool like gtkWave can easily read that:

Note that I'm only looking at one signal by choice. You could easily add any or all of the 8 signals into any of these displays.

Of course, gtkWave doesn't do sophisticated signal decoding (that I know of, at least). But with the OLS format (-O ols) it is possible to read the data into LogicSniffer and use the UART analyzer tool just like I did last time.

You can combine the sigrok software with the idea of using named pipes I talked about last time:

mknod /tmp/sigrok.pipe p
sigrok-cli –driver fx2lafw –d samplerate=100000 –continuous -O binary –p 1 >/tmp/sigrok.pipe

Now you can ask LogicSniffer to do a "generic" acquire on /tmp/sigrok.pipe and you can capture the data directly into the tool without an intermediate file.

You can trigger in a very limited way, and perhaps I'll talk about that next time. However, if you expect this little box — about the size of a small box of mints and about the price of a hamburger — to match an expensive professional instrument, you'll be disappointed. However, its cost/benefit ratio is very good. It is also handy, like a small cheap telescope. It might not give the best views, but you are more likely to look.

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.