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
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:
Continue reading V-USB with ATtiny45 / ATtiny85 without a crystal
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.
Continue reading Dissecting the Excalibur Game Time Chess Clock
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:
Continue reading PicoScope 2204 USB Oscilloscope Review
Since my brief journey to controlling LCD display directly with ATtiny2313 I purchased a display with Hitachi HD44780 compatible driver chip. The web is already pretty full of LCD tutorials and libraries, but most seemed to either skip details and rely on external libraries, or were just overly complex. So I decided it wouldn’t hurt to share the rather short (and functionally limited) versions I came up with.
In 8-bit mode, you will be needing 8 pins for sending or reading a whole byte of data at once, and 3 control lines: enable (EN), register select (RS), and read/write (RW). Basic procedure is to prepare all other lines, and then pulse the enable line high for a short while in which LCD reads your command (when RW is low) or writes data (when RW is high). For control messages, RS line is low, and for writing letters, RS line is high.
I started with ATtiny2313 and used the 8 pins in port B as LCD data lines, and PD4, PD5, and PD6 as RW, RS, and EN, respectively. With such a setup, working write command became:
Continue reading 8 bit and 4 bit LCD interfacing with ATtiny
Wow, my AVR ATtiny USB tutorial here I got featured in Hack a Day! Motivated by the influx of readers, I decided to find out how to make a USB HID (human interface device) mouse.
V-USB examples already contain an example of this, so I digged in to see what is different in
usbconfig.h compared to the one we finished in my tutorial. It seems only a few things need changing:
USB_CFG_HAVE_INTRIN_ENDPOINT needs to be set to have an additional endpoint
USB_CFG_INTR_POLL_INTERVAL set to 100 ms instead of 10 in template
USB_CFG_IMPLEMENT_FN_WRITE is not needed, nor is …FN_READ (define both to 0)
- Device ID and name need to be changed. I’ll just use the same ID as they did
USB_CFG_DEVICE_CLASS is set to 0, not 0xff
USB_CFG_INTERFACE_CLASS set to 3 instead of 0
USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH defined to match the structure’s length
That’s it! So here are the defines I changed:
#define USB_CFG_HAVE_INTRIN_ENDPOINT 1
#define USB_CFG_INTR_POLL_INTERVAL 100
#define USB_CFG_IMPLEMENT_FN_WRITE 0
#define USB_CFG_IMPLEMENT_FN_READ 0
#define USB_CFG_DEVICE_ID 0xe8, 0x03
#define USB_CFG_DEVICE_NAME 'M', 'o', 'u', 's', 'e'
#define USB_CFG_DEVICE_NAME_LEN 5
#define USB_CFG_DEVICE_CLASS 0
#define USB_CFG_INTERFACE_CLASS 3
#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 52
OK. So what about
main.c? Turns out the changes are rather straightforward:
Continue reading V-USB tutorial continued: HID mouse
My local electronics shop Partco (arguably the best in Finland) had a great offer on 6-digit LCD displays. For 1€ a piece, I immediately bought one:
Once I had my hands on it, the reason for such a low price became apparent: There was no controller chip, only 50 pins and the knowledge that pin 1 was “common cathode” and the rest were for the segments. So I decided to see if I could get it work directly without a controller. And succeeded, read on to learn how!
Continue reading Driving an LCD display directly with ATtiny
All right. Now that we got the basic USB code working in part 3, it’s time to wrap things up in this tutorial series. This fourth section will explain how to send data from your device to PC and also the other way around. I may later do a fifth part on how to make a USB HID device like a keyboard or mouse, so if you haven’t already, I’d recommend subscribing to the RSS feed to get updates.
Sending data from device to PC
If you look carefully at our command-line client code, you probably noticed that the control messages sent to toggle the led are of type
USB_ENDPOINT_IN and we have a 256-byte buffer in place to receive any data the device sends. So far we have not received any data and the return value stored in
nBytes has been zero. Let’s change that.
Continue reading AVR ATtiny USB Tutorial Part 4
This is the third part of my USB tutorial for ATtiny2313 and V-USB library. In the second part we got the breadboard setup more or less covered, and now is the time for actual code! This will most likely be the longest of the three parts, so let’s get started.
Adding V-USB as a part of your project
First, we will download the latest version V-USB library from OBdev. Head to the Downloads-section and get the latest .zip – I got vusb-20120109.zip.
Unzip the archive and copy the usbdrv subfolder to your project folder (the whole folder, not just contents). Go to the subfolder and make a copy of
usbconfig-prototype.h with the name
usbconfig.h. Locate the #define lines for IO port and port bits and clock rate, and update them as necessary to reflect our configuration where D+ is in PD2 and D- in PD3 and clock rate is 12 MHz:
#define USB_CFG_IOPORTNAME D
#define USB_CFG_DMINUS_BIT 3
#define USB_CFG_DPLUS_BIT 2
#define USB_CFG_CLOCK_KHZ 12000
Continue reading AVR ATtiny USB Tutorial Part 3
This is the second part of my USB tutorial for ATtiny2313 and V-USB library. In the first part we learned how to get 3.3V from USB to power our circuits. In this part, we will expand our setup with following parts:
- Larger breadboard and additional jumper wires
- 12 MHz crystal oscillator
- Two 27 pF ceramic capacitors to stabilize the crystal
- Two 68 Ω resistors between USB data lines and the microcontroller pins
- 1 MΩ pullup resistor for D+ and 1.5 kΩ pullup for D-
- 6-pin header for programming the ATtiny and 4.7 kΩ pullup for reset pin
Update: Some people have noted that the setup I’m using here runs ATtiny2313 at 12 MHz with only 3.3V VCC, which is outside the specified range (frequencies over 10 Mhz require 4.5V or more). I’ve never had any problems, and many others have succeeded with this setup, but if you encounter persistent problems, I suggest you to power the ATtiny2313 straight from 5V of the USB line and use zener diodes on D+ and D- lines to drop their voltage, as is done in my later tutorial with the ATtiny85 microcontroller.
This time I will not walk you through every connection. Instead, I’ll just outline the steps needed and show the pictures of end result. Here is the schematic we’re building:
Continue reading AVR ATtiny USB Tutorial Part 2