Summary of USB Sensors with ATtiny Microcontrollers
This article demonstrates creating a sensor graph using an ATtiny45 microcontroller with the V-USB stack on GNU/Linux. It covers interfacing analog sensors like light detectors, utilizing internal ADCs with specific voltage references, and adding signal conditioning components such as low-pass filters and buffers. The project also notes the use of internal thermal diodes for temperature sensing and mentions rrdtool for data visualization.
Parts used in the USB Sensors with ATtiny Microcontrollers:
- Light sensor
- ATtiny45 microcontroller (8-pin AVR)
- V-USB stack
- GNU/Linux system
- rrdtool
- 10kOhm SMD resistor
- avr-micro-usb board
Working with embedded electronics, you will eventually ends up with some sensor between your hands, here I’ll show how to make a graph out of it!
This project involves a light sensor, a tiny 8-pin AVR USB key with the V-USB stack, a GNU/Linux system and rrdtool.
Sensors
If your are working with some digital sensor (like I2C or SPI ones) you just have to connect it to your system and write the protocol, but if you are using an analog sensor, you probably need to do some work on the signals before feeding it to the microcontroller’s ADC.
In case of the ATtiny45 and alike, you have a 10bit ADC with three possible voltage references: the external VCC, a 2.56V and a 1.1V internal bandgap.
If you are designing a signal adaption circuit and you want to make reliable measurements, don’t forget to include a low-pass filter and a high impedance buffer for the sensor signal, just in case the ADC input doesn’t satisfy your needs.
In this case, the light sensor I had works like a variable resistor, so it was just wired in series with a 10kOhm SMD resistor.
Also, the microcontroller includes an internal thermal diode which, when calibrated, can be used to make temperature measurements.
Of course, if you want to make real measurements out of the sensor, you also have to calibrate and linearize it, but that’s out of the scope of this post.
USB Interface
When interfacing a sensor with a generic non-embedded GNU/Linux system, the easiest way is to use an USB interface. The free V-USB stack from obdev.at is well suited or this kind of application, as it allows to implement a low-speed USB device with any AVR microcontroller.
The stack has a really low memory footprint, and there are many examples of how to use it for many different purposes.
To implement the sensor, I reused one of my avr-micro-usb boards, which had two SMD pads for GND and an analog inputs, and an easy solder point for the VCC supply.
For more detail: USB Sensors with ATtiny Microcontrollers
- How do you interface an analog sensor with an ATtiny45?
You wire the sensor in series with a 10kOhm SMD resistor if it acts as a variable resistor. - What voltage references are available on the ATtiny45 ADC?
The three possible voltage references are external VCC, a 2.56V internal reference, and a 1.1V internal bandgap. - What components should be included for reliable analog measurements?
You should include a low-pass filter and a high impedance buffer for the sensor signal. - Can the ATtiny45 measure temperature without an external sensor?
Yes, the microcontroller includes an internal thermal diode that can be calibrated for temperature measurements. - Which software stack is recommended for implementing a USB device with AVR?
The free V-USB stack from obdev.at is well suited for implementing a low-speed USB device. - What tools are mentioned for visualizing sensor data into a graph?
The project uses rrdtool on a GNU/Linux system to create graphs from the sensor data. - Does the V-USB stack require significant memory?
No, the stack has a really low memory footprint. - What is the resolution of the ADC in the ATtiny45?
The ATtiny45 features a 10bit ADC.


