PocketMagic

March 1, 2009

ATMega8 and DS18B20 (digital temperature sensor)

Filed under: Electronics, Hardware — Tags: , , , , , — radumotisan @ 1:29 pm

“The DS18B20 Digital Thermometer provides 9 to 12–bit centigrade temperature measurements and has an alarm function with nonvolatile user-programmable upper and lower trigger points. The DS18B20 communicates over a 1-Wire bus that by definition requires only one data line (and gound) for communication with a central microprocessor. It has an operating temperature range of –55°C to +125°C and is accurate to +-0.5°C over the range of –10°C to +85°C. In addition, the DS18B20 can derive power directly from the data line (“parasite power”), eliminating the need for an external power supply.” Read more about this sensor, here.

Since I had two DS18B20 sitting among my other electronic components, I’ve decided to hook one up to my ATMega8 test board and see if I manage to get some temperature readings. One wire to a microcontroller’s pin, and two other wires for 5V power.

Now we’re ready to go… well not quite, this is a digital sensor and first we need to understand the way it communicates.

I’ve also found some good resources online here. If the link doesn’t work for you, see the attached PDF.

Here’s my source code, to get you started right away:
atmega8_lcd_temp.zip

Bottom line, this sensor offer some impressive results, and works very well. It is a good addition to any microcontroller board for gathering some extra environment parameters, and all at the expense of a single PIN on the microchip.

Radu Motisan

February 13, 2009

ATmega8 and 2×16 HD44780 LCD

Filed under: Electronics, Hardware, Uncategorized — Tags: , , , — radumotisan @ 4:43 pm

Following my first article on the initial findings and results of my tests on the ATMega8, this article will show basic steps on how to connect a 2×16 characters LCD to the micro chip.

The reason for this is to have a way of debugging the microchip functionality, to output the results, the data and various other stuff. I can tell you this is a must have.

To use a minimum of I/O pins, I’ve decided to build a 4bit interface with the LCD. The hard part was to write the code, but finally after fixing several bugs and reading a lot of HD44780 documentation, I can say that I’ve completed a nice flexible code – meaning that you can easily configure the LCD pin connection.

The wiring diagram is below:

The code interface is also attached, not much to say about it here, since it’s full of technical details and bit-wise operations, but if anyone has questions feel free to use the comments form at the bottom.
To edit some parameters like frequency or PIN connections (you can change the I/O pins used by the LCD on the ATMega), have a look in lcd.h . Zip attached:
atmega8-lcd

Function lcd_string2 is very useful for outputting text, since it supports variable parameters similar to printf. So you can use it for outputting misc content: lcd_string2(“Hello World! %d\npocketmagic.net”,i);

Here are some pictures with my LCD running:

Next thing to do is to start connecting various sensors.

Radu Motisan

Create a free website or blog at WordPress.com.