Simple FAT and SD Tutorial Part 1

Are you limited by 128 bytes of EEPROM on your MCU or even the few kilobytes of flash in your project? Instead of just downloading a library like Petit FAT File System Module and following blindly a tutorial on how to customize it to your microcontroller and SD card, would you like to really understand what you are doing, and maybe learn a bit about filesystems and SPI in the process?

In this first part of my FAT and SD tutorial, we’ll take a SD card image, and create a simple C program to interpret its contents. For this part, you don’t need any hardware at all, just a computer with gcc (GNU C Compiler) or any other ANSI C compatible compiler installed.

Getting ready: Hex editor and disk image

To make the coding easier, I recommend a good hex editor. The one I’m using is the free and excellent HxD by Maël Hörz. You can also use it to create a 1:1 disk image from a physical SD card. To have a filesystem to read, I purchased a 1 GB micro-SD card with SD adapter for 5€, plugged it into my computer and formatted it as FAT16 (over 2 GB cards will likely get formatted as FAT32), and copied Hamlet from Project Gutenberg and some other dummy test files to it (also created a subdirectory with a few text files in it):


Continue reading Simple FAT and SD Tutorial Part 1

Handy Pinout Reference Sheet

Just thought to share a quick tip today. I’ve noticed that when doing work with AVR MCU’s, I’m using ATtiny2313, ATmega88 and ATtiny45/85 for 99 % of the time. I got tired of opening the Atmel data sheets every time when swapping a new chip into a breadboard, so I constructed a real cut’n’paste reference sheet by gluing the relevant portions on a piece of rigid cardboard:

I even used a piece of paper to mark the 6-pin header pinout, it’s a real time-saver! And thanks to the cardboard back, it’s easy to keep below my LCD monitor and pull out every time I need it. Additional idea would be to leave some white space around the pinouts and laminate it with clear contact paper, so I could doodle project-specific notes with a water-based marker and clean it after I don’t need them anymore!

Oh, and as you can see, I’m using a Mac this time to do some flashing. I installed the excellent Crosspack for Mac from Obdev guys. It’s a streamlined way to install avrdude and avr-gcc on a Mac, and now I can take my electronics hobby with me when I’m traveling. :)

Using Arduino Uno as ISP

One exciting piece of hardware I received with my Digikey order was an Arduino Uno board (R3). There was conflicting information whether or not it could be used as an ISP (in-system programmer), so I decided to see for myself. It turned out that with just one tweak, I could use the $26 device to program my AVR chips, essentially eliminating the need for a separate ISP such as $22 USBtiny!

This is obviously good news for any beginner with a budget, so I decided to write a short tutorial on how to do it. I used my USB password generator as a guinea pig for this project, so if you have wanted to try that out, this post also doubles as tutorial on how to build it on breadboard (good idea in any case before soldering it anywhere). Read on for details!
Continue reading Using Arduino Uno as ISP

Digi-Key Order and Review

Until now, I’ve been ordering all my electronics supplies through the excellent Finnish firm Partco. However, after running out of ATtiny85 chips I just couldn’t make myself pay 5.90€ ($7.80) when the same part was available for third the price from Digi-Key. I decided to try the fabled distributor myself. In case you haven’t tried them yet, read on for my experiences.

Website and Shopping Process

It is surprising how such a successful electronics component retailer is able to operate with such a poorly laid out and difficult to use website. From a usability standpoint, it’s a prime example of how not do design a web store. There’s so much to critize it’s hard to know where to begin, but here my top annoyances for the front page alone:
Continue reading Digi-Key Order and Review

Fast DDS with ATmega88

I’m planning to make some RFID hacking in near future using 150 kHz tags. Since I don’t have a signal generator, I decided to go where quite many people have gone before and build myself one, more specifically a DDS. Instead of just taking a complete project from the net, I thought this would be a good way to learn a bit of AVR assembly programming, and manual D/A (digital to analog) conversion using R-2R ladders. Here’s what I built:

I’m skipping the schematic to save some time – basically it’s a ATmega88 with 6-pin programming header, power, a 16 MHz crystal (other frequencies also work, lfuse for this setup if 0xFF) and a red LED that is not used. The R-2R ladder is wired with white jumper wires to PB0-PB5 (it’s a 6-bit DAC) so that PB0 is the “least significant bit” and PB5 the most significant one. Read on for details.

Continue reading Fast DDS with ATmega88

Weller Magnastat Autopsy and Repair

Immediately after soldering together my USB password thingy, my solder iron, the family heirloom Weller Magnastat stopped working. Some investigation showed that the base station was providing 24V AC voltage just fine, so I decided to unassemble the handpiece to see if something could be done. Here’s what I found:

It turned out my iron was salvageable; read on to learn a bit about the Magnastat and how I was able to repair mine.
Continue reading Weller Magnastat Autopsy and Repair

DIY USB password generator

Having done half a dozen V-USB tutorials I decided it’s time to whip up something cool. As USB keyboards were an area untouched, I decided to make a small USB HID keyboard device that types a password stored in EEPROM every time it’s attached. A new password can be generated just by tabbing CAPS LOCK a few times (4 times to start password regeneration and one tab for each password character generated, 10 is the default password length). Below you can see the device in action:

The place I work at requires me to change my password every few months so this would be one way to skip remembering a new password altogether (as long as I remember to write it down before regenerating a new one so password can be changed :).

What is inside?

The device is powered with a simplified version of the hardware I used in my ATtiny85 USB tutorial – I stripped away the LCD, reset pullup and both capacitors. If you’re better in cramming components inside enclosures I suggest adding at least a 0.1 uF capacitor between VCC and GND, but it seems to work fine even without it:

Continue reading DIY USB password generator

DIY resistor folder for 9.90€

If you’ve done even a bit of electronics, the chances are that you’ve already amassed a hefty collection of resistors. Buying them is fun but finding the right values from a stack of resistors is not. I noticed that you can buy actual “resistor folders” with nice labels and the full E24 series of 1500 resistors for $100. I already had resistors so I decided to make my own folder with less expense.

I walked into the nearest book store and quickly found a promising offering: 10 transparent plastic sheets of “collectible card holders” for about 3€. Any store having binders and associated supplies will probably have something similar. I also bought a thin A4 binder and 200+ label stickers for about 9.90€ total (about 1:1 to dollar prices). Here’s what I came home with (already added the stickers):

Each sheet had 9 pockets so for 3€ I get storage for 90 values, and 10-20 resistors fit into a pocket without making the page too heavy. I labeled the first 72 based on my E12 series and that left me with 2 extra pages for “exotic” resistor values. Here’s the first page of E12:
Continue reading DIY resistor folder for 9.90€

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:

#define USB_DATA_LONGOUT 5

// [...] 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_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, 
            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:
Continue reading V-USB: Outputting Data with usbFunctionRead()

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 IMakeProjects.com’s AVR tutorial. You’ll also need the following components:
Continue reading 7 Segment Multiplexing With ULN2003 & PNP Transistors