I just accidentally burnt out my atmega168 and all i have around the house is an Attiny2313. I read that the 2313 does not have an ADC, but it does have an analog comparator, which I think it is just what I need for my project. I need to see if a specific voltage is above or below a reference voltage. Does any of you have an Arduio IDE code for that? i only use the Arduino IDE for programming Atmega s and I am not familiar with other languages. Basically, if a value is below another value, digitalWrite(ledPin, LOW) and viceversa, that is what I need.

The 2313 can do this, but not as an Arduino. AFAIK, that chip isn't supported. You can use AVR C/C++ instead though, which is what the Arduino libraries are built on. You'll have to use direct I/O instead of digitalWrite, you'll put your code in main() instead of loop(), and you'll have to initialize all the hardware stuff yourself. Not a big deal if you're comfortable with regular C development and can read the datasheet. :-)

Download AVR Studio (free from Atmel's site) and follow some online AVR tutorials to get yourself started. Or just order a new ATmega chip.

Thank you very much, it was very kind of you to provide the solutions and the code. I will surely dig into it until a new Atmega168 arrives.

Let me tell you what I did with the last one. i accidentally connected a 470nF capacitor from VCC to ADC0. After that, i only get "Atmega not responding, check the connections and try again". I checked the connections, the progammers is ok, all I can think is that the Atmega168 burnt out consequently to the capacitor (which stayed there long enough before I figured it out). Is that possible?

Thank you very much, it was very kind of you to provide the solutions and the code. I will surely dig into it until a new Atmega168 arrives.

The code is certainly a bit odd so I will understand if you have questions.

Quote

i accidentally connected a 470nF capacitor from VCC to ADC0. After that, i only get "Atmega not responding, check the connections and try again". I checked the connections, the progammers is ok, all I can think is that the Atmega168 burnt out consequently to the capacitor (which stayed there long enough before I figured it out). Is that possible?

I have no idea. But I'm will to bet the folks who hang out here can answer the question...http://arduino.cc/forum/index.php/board,5.0.html

...but I don't know if it is reliable, considering that 8MHz looks a bit large to me. Until now, except Arduino, I only used Atmega168 (the burnout one) and Attiny2313, at 1MHz, whithout external crystal. Could this board be ok or I might have signature problems at uploading? i am using uspasp programmer and Arduino 1.0.1.

The cap was not charged, I just placed it between Vcc and ADC0, but I wanted to put it between ADC0 and GND. Not knowing what I have done, I connected the programmer and I got the message "Board not responding, check the connections." No matter how many times I checked, undid and did the connections, I still get this message. The board does nothing, even the previous sketch I uploaded on it does not work (a simple Blinky on pin 2 -Arduino pin, that is).

I hope the programmer is ok, it works on Attiny2313, so I think the usbasp is ok.

Is there any other way to test an Atmega168, other than upload the simplest sketch on it? It is not a big gap in the budget, but I want to know what caused the problem, in order to avoid it in the future.

Half of problem solved: I purchased my Atmega8 and it did not work with the boards file I posted earlier, so I had to set the board to Arduino NG/Atmega8 and upload the sketch by Upload by programmer option. It looks fine and it is a lot cheaper an Atmega168 that I initially purchased. i'll keep you posted.