Temperature Monitor using an atmega32u4

There are a number of significant aspects to this little project. It was my first time using the LUFA stack with a chip like the 32u4 that has built in USB support. It was also my first time using libusb-1.0 on linux to communicate with a USB device.

The temperature sensor

Many AVR controllers have a built in temperature sensor. The 32u4 chips has a 10 bit ADC, and the internal temperature sensor is connected to one of the converters input channels. When properly configured, the sensor reads in degrees Kelvin. Atmel does not claim better than 10 degrees C accuracy unless you calibrate your particular sensor. Mine actually does pretty good without calibration (based on it reading 77F when my room is about 78F, and then dropping to about 20F when I set an ice cube (in a zip lock bag) on top of the chip.

The following note gives information about calibrating the internal sensor. Apparently the factory may store calibration values in the EEPROM of every device.

The hardware and firmware

I am using a 32u4 device on the Adafruit breakout board. I built the firmware based on the Generic HID low level demo that came with the LUFA 130303 release. The way I handle the ADC is to let it free run, monitoring the IF bit that signals a conversion done once on each pass of the main loop. When I find a completed conversion, I read it out, placing the data in a global location, then I trigger a new conversion. This decouples the conversions from the USB IO events. Whenever a request is made for data, I supply it immediately from the globally posted values, which are being continually updated.

Host side software

After a number of false starts with libusb-0.1, I wrote C code that uses the current libusbx library (which is the active fork of what is generally known as "libusb-1.0". I fiddled with both python and ruby bindings, but neither was well enough documented for a beginner with USB to be able to use them with any confidence. There is something satisfying about just writing C code.
Feedback? Questions? Drop me a line!

Tom's Computer Info / tom@mmto.org