Input devices

In this unit, we'll be adding an input device to a microcontroller. The project chosen was to add the DHT22 temperature/humidity sensor to an ATTiny 45 and print out the data to the serial port. Easy-peasy!? Guess again... Take a few moments to understand how much one can learn from one's errors especially when you make a LOT of them.




Very simple, very easy...

The DHT22 temperature/humidity sensor is a widely used, very well-documented sensor (e.g.- Adafruit and Sparkfun). The interesting thing about this sensor is that it provides a digital output that encapsulates both measurements. The data is passed to the microcontroller using some device-specific pulse sequences. Learning to work with pulse sequences and timing is something that is very useful since almost all peripheral interfaces require these techniques to communicate. Sometimes - such as with the Arduino platform - much of the complexity is hidden from the user through fucntion calls. However, once outside of the protective cocoon of the Arduino libaries, the hard realitites of timing make an ugly appearence.

The ATTiny 45 is indeed a 'powerful' microcontroller with lots of functionality. And if its good enough for Neil, well, that makes it good enough for me. So lots of example code exists on the the Fab Academy website for using the chip. So, we have a well-documented sensor and a well documented chip so nothing could be easier then combining the two, producing some output and closing another week in the Fablab. Little did I know!




Size matters

First step was downloading the Adafruit Arduino libraries for the sensor. IMHO, well written OO C++ code for the sensor that did everything perfectly. Fire up the Arduino IDE and select the ATtiny45 chipset, uhhh, where's the ATtiny45 chipset? Strange?! Infact, Arduino does not support the ATtiny45 of the box. Long story short, some googling, forum reviews and we found the libraries for integrating ATTiny45 into the Arduino IDE. Note it took almost a full day to get everthing working. Amoung other things, we discovered that the bootloader for the ATTiny45 is very difficult to find and that the AVR IDE and ARduino USB drivers for the AVR programmer are not compatiable and only one can be installed at the same time. Ok, Arduino and programmer are working again and we are ready to compile.

Start first compilation, compile error, 'Serial' not found. What!?!? That is such a basic library. It is but it has not been ported to the ATtiny45 library. No problem, we can use SoftwareSerial. Complilation complete - "target to small". Uh oh... Indeed, the ATTiny45 has only 4k of memory when the 328P that has been the goto chip has 32k. No problem. We can remove all the OO C++ goodness in the original and go old-school C to make things smaller. Hmmm, in fact, that has very little effect on the size of the compilation. How does Neil do it? Complete review of Neil's code... Tick, tick, tick. Ok, first off Neil uses no Arduino libaries, pure AVR C. When he talked about bit-banging, I didn't remember him saying that this was because SoftwareSerial pulls in loads of code (relatively speaking) to drive the coms. Delete all the Serial code and replace with Neil's bit bang code. But now we've lost all the 'debugging' that serial provides.




To-do

Add stuff that would be cool to investigate when time and resources permit.




Bibliography

This article discusses in great detail PCB milling with loads of information on V-engravers.