Code and Life

Programming, electronics and other cool tech stuff

Supported by

Supported by Picotech

Driving an LCD display directly with ATtiny

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!

Read post

AVR ATtiny USB Tutorial Part 4

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.

Read post

AVR ATtiny USB Tutorial Part 3

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

Read post

AVR ATtiny USB Tutorial Part 2

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
  • ATtiny2313
  • 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.

Breadboard setup

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:

Read post

AVR ATtiny USB Tutorial Part 1

I wanted to build an USB device using AVR microcontrollers since I found out that it was possible. However, both the USBtiny project and the more extensive V-USB library lacked an easy-to-approach tutorial. So I decided to make one.

This first part covers the basics for making USB-powered devices, and serves as introduction for second part, which goes through simple example for using V-USB library to implement USB communication to and from ATtiny2313. Additional parts might be published later if I have the time and there’s interest.

But let’s get started. Here is what you need for this first part:

  • USB cable and pin header
  • Small breadboard and a few jump wires
  • LED and 330 ohm resistor
  • Low voltage drop 3.3V regulator, such as LD1086V33 or LE33CZ

The cable

The first thing we need to do is cut the USB cable so the end that goes into computer remains, strip the other end and solder the four wires into a pin header so it’s easy to plug the cable into a breadboard. USB contains four wires which you should solder in the following order (note: not all cables conform to this so check with a multimeter!):

Pin Color Function
1 Red VCC (+5V)
2 White D-
3 Green D+
4 Black Ground (0V)

Here you see the end result. When stripping the wire, be careful not to damage the wires and make sure the wires will not touch each other so your cable won’t short circuit your computer or USB hub!

Cable with soldered pin header

Read post

Apple TV First Impressions

Long time no see. I decided that instead of rambling on and on about my newly acquired Apple TV, I’ll just write about it in my blag. I’ve divided the review into sections so you can dive into the action if you’re only interested in one of the aspects.

Pricing and the Package

For Apple, the 119 € they charge for the second generation Apple TV is not much. I mean, it’s like two iPad HDMI cables, right? With that price, you get a beautiful and very small black box that has a HDMI (limited to 720p) output for video/audio, alternative optical S/PDIF output for audio, ethernet jack if for some reason you don’t want to use integrated wireless chip, and a micro-USB slot for debug purposes (no, I think you cannot connect external drives).

I really don’t have anything but positive things to say about the package and hardware, every detail is beatifully executed. For reference, the hi-fi Cambridge Audio dock that is basically just the S/PDIF part of Apple TV costs a whopping 200 €. So if you can live without 96 kHz / 24 bit audio and satisfy yourself with “just” CD quality sound output, you save 80 € and get a ton of features for free.

Read post