Go Down

Topic: Problems with ATTiny and it's ADC's (Read 6 times) previous topic - next topic

UnaClocker

Ok, I managed to get it working. Instead of calling it Pin 3, I called it A2. The HLT core would not let me do that, it wouldn't take pinMode(A2, INPUT);, or any of the A1, A2, A3 defines. This Tiny core does, and it reads the port. Seems to be reading a bit off, but I can apply a correction factor to it as long as it's consistant.
Thanks for the help troubleshooting this, guys.
Brian from Tacoma, WA
Arduino evangelist - since Dec, 2010.

Jack Christensen


Seems to be reading a bit off, but I can apply a correction factor to it as long as it's consistent.


This was still bothering me, so I gave it a shot. I get near perfect results with the code below. With the inputs tied to ground, three zeroes. Tied to Vcc, three 1023 readings. Connected to a voltage divider consisting of two 10K resistors from Vcc to ground, I get mostly 507 or 508, the three are all usually within one of each other. ATtiny85-20PU at 8MHz, Arduino-Tiny core.

Code: [Select]
#include <SoftwareSerial.h>
#include <Streaming.h>    //http://arduiniana.org/libraries/streaming/

int a1, a2, a3;
SoftwareSerial ser(1, 0);

void setup(void)
{
    ser.begin(9600);
}

void loop(void)
{
    a1 = analogRead(1);    //dip pin 7
    a2 = analogRead(2);    //dip pin 3
    a3 = analogRead(3);    //dip pin 2
    ser << _DEC(millis());
    ser << ' ' << _DEC(a1) << ' ' << _DEC(a2) << ' ' << _DEC(a3) <<endl;
    delay(1000);
}

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

UnaClocker

You never set the pins to input.  I had also read that you need to toss the first result when switching analog pins. So you're definitely having great success. You're using serial on pin 1, AND reading analog from it.... Apparently the pin numbering is nothing like I imagined.
Brian from Tacoma, WA
Arduino evangelist - since Dec, 2010.

Jack Christensen

#18
Sep 25, 2012, 06:45 pm Last Edit: Sep 25, 2012, 06:53 pm by Jack Christensen Reason: 1
AVR pins default to input on power up/reset. Plus I'm lazy efficient XD  The readings I quoted were after it ran a bit, I missed the first reading actually, so they may have been off a bit, but I don't know.

The pin numbering makes me crazy too, what between the DIP pins, the Arduino pins, the port number (e.g. PB2) etc. With The ATtiny85 and Arduino-Tiny, for digital pins, the pin number matches the port (PBn) number, which is nice and straightforward. The argument to analogRead() is really the ADC MUX channel number, not a pin number. So SoftwareSerial ser(1, 0); refers to DIP pin 6 (PB1) and DIP pin 5 (PB0) respectively, and the calls to analogRead() correspond to the DIP pins in the comments in the code.
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Erni


Go Up