Code and Life

Programming, electronics and other cool tech stuff

Supported by

Supported by Picotech

V-USB: Outputting Data with usbFunctionRead()

I promised to commenter Marek to post an example of using usbFunctionRead() to return larger amounts of data. So building upon the ATtiny85 version we made in last part, let’s add one more command to usbtest.exe:


// [...] Change the buffer size in main():
    char buffer[2048];

// [...] Add the following in the if-else structure in main():

    } else if(strcmp(argv[1], "longout") == 0) {
        nBytes = usb_control_msg(handle, 
            USB_DATA_LONGOUT, 0, 0, (char *)buffer, sizeof(buffer), 5000);
        printf("Received %d bytes: %s\n", nBytes, buffer);

Now let’s tell V-USB that we’re implementing usbFunctionRead() and doing transfers of more than 254 bytes in usbconfig.h:

Read post

7 Segment Multiplexing With ULN2003 & PNP Transistors

The reason a started my electronics hobby was that I wanted to build a chess clock. Lacking a proper LCD display, I chose to multiplex several 7-segment displays. Most sources in the net did not specify hardware at all, and those that did were driving the segments with a 74HC595 shift register and using NPN transistors to enable one common cathode display at a time. However, if you look at 74HC595 specs you’ll notice that it’s not designed to source the amount of current that is required to drive several multiplexed 7-segment displays. It might work, but no one can say for how long!

It took me a while to find a good, inexpensive and readily available alternative. I finally found it in ULN2003, which is inexpensive darlington array that can drive 500 mA from each of its pins. So I decided to write a little tutorial on 7 segment multiplexing that walks through all the needed hardware and software in detail. Here’s what we’ll build (click for a larger image):

For this tutorial I assume you know how to connect ATtiny2313 to a programmer and flash it with custom software. You’ll learn as much in’s AVR tutorial. You’ll also need the following components:

Read post

Default feed not disabled with Suffusion

I switched to a new WordPress theme, Suffusion! Hooray! However, the %#&/?! default feed link is added to HTML even if disable it in Suffusion settings. Not hooray.

Digging into Suffusion code, I found suffusion_include_default_feed() from functions/actions.php, but it seems that it correctly does not output anything when I disable the default feed. Furthermore, the alternate feed URL actually does output my FeedBurner feed URL. So it seems Suffusion is not generating these links by itself.

Grepping around the WordPress source code (a look through the dozens of templating PHP files really makes me want to code a barebones blog myself) I finally located the culprit: feed_links() method in wp-includes/general-template.php. Why is this called? Where should it not be called?

It seems at least wp-includes/default-filters.php is adding this feed_links action to wp_head. I commented it out, and what do you know, the nerve-wrecking automatic feed URLs are gone!

Just thought to share it if someone else is having the same problem. It looks like Suffusion should have the following somewhere if default feeds are disabled:

remove_action( 'wp_head', 'feed_links', 2 );

It seems Suffusion is adding a ton of actions and filters in its functions.php, namely in function suffusion_setup_custom_actions_and_filters(). So here’s a patch which gets rid of that default feed URL if you have chosen to disable it in Suffusion setup:

function suffusion_setup_custom_actions_and_filters() {
    // Theme supports automatic feed links, which makes WordPress output default 
    // RSS feed links via feed_links action. Disable this if the user has explicitly
    // chosen in Suffusion setup to disable those very feeds.
    global $suf_custom_default_rss_enabled;
    if ($suf_custom_default_rss_enabled != 'enabled') {
        remove_action( 'wp_head', 'feed_links', 2 );
    ///// ACTIONS

Read post

V-USB with ATtiny45 / ATtiny85 without a crystal

One guy at Hack a Day remarked on the long wire runs in my V-USB tutorial breadboard setup. So I thought I’d build upon the part 4 of the tutorial but modify the setup a bit to run the AVR at 5 volts and use zener diodes to drop D+/D- voltage, thus eliminating the need for a regulator. And why not stop there. ATtiny45 and ATtiny85 are smaller than ATtiny2313 and have an internal oscillator that can be calibrated to provide 16.5 MHz clock, accurate enough for V-USB to do its magic. I challenge anyone to drastically shorten these wire runs!

In the photo, I used a 4-pin header to show the place of the USB cable so the zener diodes would not get obstructed. Note that due to the angle it can seem like the 0.1 uF tantalum cap (light brown one) is wired to PB4 when it really is going to GND pin! Here’s the schematic, heavily borrowed from V-USB’s EasyLogger reference implementation:

Read post

Dissecting the Excalibur Game Time Chess Clock

A go-playing friend of mine had a broken “Excalibur” chess clock that we here in Europe use extensively in go tournaments. The LCD was shattered and I don’t think they ship replacement parts:

Because the clock is not of much use without a display, I got to rip it apart to see what it contains. This particular clock is used quite a lot, so I thought I’d share the images. Note that you can click on pictures to view larger version of the image.

Read post

PicoScope 2204 USB Oscilloscope Review

PicoScope 2204 USB scope

One of the nicest things when starting a new hobby is that there’s just so many things you don’t yet have, and can thus look forward to researching and then maybe buying if the price is right. In electronics, you can pretty much get started with a $10 soldering iron, $25 multimeter, maybe a $30 programmer if you want to use microcontrollers, and then just buy cheap components to tinker with. But sooner or later, you start thinking about how nice it would be if you had an oscilloscope.

For me it took about nine months. I saw an article on using AVR as an RFID tag and noticed I could build a simple RFID reader with a few components. However, to really learn something, it would be nice to actually see the 125 kHz RFID carrier wave instead of fumbling blindly with the schematics. Additionally, I could use the scope to verify DIY D/A circuits, maybe debug serial protocols and much more. So I started researching.

Getting a used analog or digital scope from eBay was of course one option. However, old scopes are big, clunky and I don’t really have much table space. And if the scope fell out of use, it would be wasting space in a closet. New Chinese-made digital scopes from Owon and Rigol looked good and were relatively small and light. However, they had 640×480 or 800×600 displays and I had 2560×1600 30″ monitor sitting on my workspace, and being more of a software person, I eventually decided against them and chose to get a PC scope instead.

Options in USB scopes

Going through the options for digital scopes, there seemed to be a few price brackets:

Read post