title: ADC on arduino in C
body: <p>I'm trying to use the Arduio Uno in pure C because I can't use the Arduino IDE for my senior design project. I've succeeded in getting the serial communication to work, the digital outputs/inputs, and the analog inputs, to an extent. I'm getting a reading off the analog input, but most of them are 20,000+, which is way to high. This is supposedly a 10 bit ADC, and I'm only trying to use 8 bits. Why is my resulting read 100X what the highest supposedly is?</p>
  
  <pre><code>void init_aio(){
        DIDR0 = 0x00;           //Digital input disabled on all ADC ports
        PRR &amp;= ~(1&lt;&lt;PRADC);     //ADC turned on
        ADMUX = 0x60;           //AVcc, right adjusted, ADC0 pin
        ADCSRA = 0xcF;          //ADC Enabled, no auto trigger, Iterrupt enabled, 128 prescaller
  }
  
  int read_analog(){
      reading = APin0;
      ADCSRA |= 1&lt;&lt;ADSC; //conversion start
      reading = abs(reading);
      return reading;
  }
  </code></pre>
  
  <p>The only thing I can think of is that I'm using "int reading_str = itoa(reading, buffer, 10);" to make it a printable value. When I print reading directly, it prints garbage to the terminal. (char buffer[100]; is what buffer is) </p>
  
  <p>The Uno uses an Atmega328P:
  www.atmel.com/Images/doc8161.pdf‎</p>
  
  <p>Thanks for any help.</p>