Summary of I2C Tiny USB using ATtiny45 microcontroller
The i2c-tiny-usb project offers a low-cost, open-source USB-to-I2C adapter using an ATtiny45 microcontroller. It supports Linux, Windows, and macOS, eliminating the need for CPU-intensive bitbanging on the host side. The design features a software-based USB implementation and a bit-banged I2C interface operating at approximately 50kHz. This solution provides a future-proof alternative to printer port adapters with built-in power supply.
Parts used in the i2c-tiny-usb:
- Atmel AVR ATtiny45 CPU
- ds1621 temperature sensor
- Resistor R1
Attach any I2C client chip (thermo sensors, AD converter, displays, relais driver, …) to your PC via USB … quick, easy and cheap! Drivers for Linux, Windows and MacOS available.
The i2c-tiny-usb project is an open source/open hardware project. The goal of i2c-tiny-usb is to provide a cheap generic i2c interface to be attached to the usb. It is meant as a replacement for those simple and cheap printer port to i2c adapters. A USB solution has several advantages incl. the built-in power supply and a more future proof interface. Furthermore no cpu intense bitbanging is required on the host side. This USB solution even requires less parts than some printer port solutions.
While the i2c-tiny-usb was developed under and for Linux it also works under Windows and MacOS X. A windows demo driver and demo application is included to get you started immediately.
The i2c-tiny-usb project is based on:
- The Linux USB project and the Linux i2c implementation
- The windows driver and test application are based on the libusb-win32
- AVR-USB, a pure software implementation of USB for the AVR platform
- USBtiny, another software usb implementation for the AVR
Hardware
The prototype board including a ds1621 temperature sensor
The hardware of the i2c-tiny-usb interface consists of the Atmel AVR ATtiny45 CPU, a cheap and easy to obtain microcontroller with 4 KBytes flash (of which ~2k are used in this application) and 256 Bytes RAM. The processor is surrounded by few other parts.
The USB interface
The USB interface of the i2c-tiny-usb interface is based on a pure software implementation and uses two pins of the AVR (PB0 and PB2). This software implementation supports low speed USB only which is signalled to the PC by resistor R1.
The I2C interface is implemented using a bitbanging approach. The hardware supported twi interface of the attiny45 is bound to hardware pins at the chip that are required for USB operation and can thus not be used for I2C. The bitbanging I2C interface being used instead may not be fully I2C compatible and thus not every I2C client chip may function correctly at this bus. No incompatibilities have been reported so far. The i2c-tiny-usb provides a software adjustable i2c clock delay allowing to configure the i2c clock. The default delay is 10us. Due to additional delays in the i2c bitbanging code this results in a i2c clock of about 50kHz.
The final hardware with the same sensor added
For simplicity reasons all USB transfers are done via the control endpoint. Since the avr usb library does only support low speed devices it cannot use bulk transfers which are specified for high and full speed devices only. Low speed devices support so called interrupt transfers which are limited to a preset bandwidth while control transfers can use any free bandwidth (if there’s any at all).
The device therefore uses control transfers for all of its communication. This requires some additional limitation to prevent multiple driver software (e.g. the kernel driver and the libusb based test application) to access the device at the same time. Under Linux this can be achieved by selecting certain access request types. This kind of access control may not be possible under other operating systems.
For more detail: I2C Tiny USB using ATtiny45 microcontroller
- What is the primary goal of the i2c-tiny-usb project?
The goal is to provide a cheap generic I2C interface attached to USB as a replacement for simple printer port adapters. - Which operating systems are supported by this project?
Drivers are available for Linux, Windows, and MacOS X. - How is the USB interface implemented in the hardware?
It uses a pure software implementation based on two pins of the AVR (PB0 and PB2) supporting only low speed USB. - Does the device use the hardware TWI interface for I2C communication?
No, the hardware TWI interface cannot be used because those pins are required for USB operation; instead, a bitbanging approach is used. - What is the approximate clock speed of the I2C interface?
The default delay results in an I2C clock of about 50kHz due to additional delays in the bitbanging code. - Can every I2C client chip function correctly with this interface?
The bitbanging interface may not be fully I2C compatible, so not every chip may function correctly, though no incompatibilities have been reported so far. - Why does the device use control transfers instead of bulk transfers?
The AVR USB library only supports low speed devices, which cannot use bulk transfers specified for high and full speed devices. - Is the I2C clock configurable?
Yes, the project provides a software adjustable I2C clock delay allowing users to configure the clock.


