Go Down

Topic: ATTiny ADC issues (Read 258 times) previous topic - next topic

bahamutkotd

So i've been fighting with getting a attiny84 to give me a reading from it's adc.  I've installed Attinycore package and i can get blink to work on the chip, and can even send int values over i2c w/ tinywireS but when i try to do an analogRead, i get nothing.

I noticed in one example that he uses functions from a core_adc.h which is also in the repo, but the arduino IDE doesn't recognize it. 

Can someone walk me though either getting the header to be in arduinoIDE, or the required steps to enable the adc on on adc1, w/ the 8mhz clock speed, though at this point i'm using the 3 pin to power the measured analog pins, i'm aware that using an external AREF would be more advantageous.

Thank you for your time

waqaszahid

Hello,

Whats the IDE version you are using? Secondly, can you please share your code.

Thanks

ArduinoJ4ck

I interestet in a Solution aswell...

DrAzzy

All that should be necessary is to do analogRead(A1) - please do note the caveat in the documentation; pinMode() does not correctly interpret the A# pin names, you need to use the digital pin numbers.

Refer to the pinout diagrams in the documentation and make sure you're using the right pin.

I would suggest using the latest version (ie, github install) and seeing if that fixes things. I thought the ADC-related fixes got into the 1.1.2 release (I remember some issues there relating to a feature enhancement to support ADC options that don't correspond to a pin (ex, differential ADC, measuring internal reference, etc)) - but I may be misremembering, in which case that's all the more reason for me to get 1.1.3 out the door (I think it's just about ready for release at this point).

There's an open issue to fix the issue with pinMode() not working with A# pins (it's non-trivial to fix without breaking other features, else it would be in 1.1.3).
ATtiny core for 841+1634+828 and x313/x4/x5/x61/x7/x8 series Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts (some assembled), mosfets and awesome prototyping board in my store http://tindie.com/stores/DrAzzy

ArduinoJ4ck

I just can´t get a potentiometer working.

I connectet the Potentiometer to PA1
The LED is connectet to PB2

The led is slowly glimming but the potentiometer doesn´t do anything to it.
U can find my Code below. Please tell me did i do anything wrong ?
Code: [Select]
  int LED = 2;

void setup() {
  pinMode(2, OUTPUT);
  Serial.begin(9600);
 
}

// the loop routine runs over and over again forever:
void loop() {
 
 
  int Poti = analogRead(A1);
 
  if (Poti > 250)
  {
    digitalWrite(LED, HIGH);
  }
  else
  {
    digitalWrite(LED, LOW);
  }
 
}

mart256

I reccomend using the number of the pin, instead of A1. Check an attiny84 pinout and choose the pin number.
I dont know if it is mandatory but you could and a pinMode(?, INPUT) where ? Is the number of the analog pin you are using.

Erni

If you delete the

Code: [Select]
Serial.begin(9600);

it works, I am not sure why.

If you realy want to use the serial monitor to debug (which is a good idea) you should look up TinyDebugKnockBang.

DrAzzy

#7
May 22, 2017, 08:15 pm Last Edit: May 22, 2017, 08:15 pm by DrAzzy
Oh, ya, that'd do it.

Per the documentation https://github.com/SpenceKonde/ATTinyCore/blob/master/avr/extras/ATtiny_x4.md "Serial" uses a software serial implementation on the AIN0 and AIN1 pins (there's no hardware serial on the x4, so it has to be a software implementation.)

These pins are used to take advantage of the analog comparator interrupt, which is almost never used in arduino-land, in order to avoid using the PCINT or external INTn interupt vectors. The normal software serial libraries work on any pin, but use a PCINT vector, making them incompatible with other things that use PCINTs on a different pin. Naturally, if you're using those pins for Serial, you can't also use them for other purposes!
ATtiny core for 841+1634+828 and x313/x4/x5/x61/x7/x8 series Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts (some assembled), mosfets and awesome prototyping board in my store http://tindie.com/stores/DrAzzy

ArduinoJ4ck

So i got this code trying to figure out how to get my analog in. Value is connectet to a potentimeter. But it seems its not the right pin
This is the pinout for my Attyiny = Pinout
Code: [Select]
int value = 3;
int varvalue = 0;
int LED = 1;

void setup() {

pinMode(1, OUTPUT);

}

void loop() {

  varvalue = analogRead(A3);

  if (varvalue < 90)
  {
    digitalWrite(LED, HIGH);
  }
  else
  {
    digitalWrite(LED, HIGH);
  }


}

DrAzzy

As you can see in that diagram, there are two pin mapping options. Have you selected the correct one from the tools menu? With my core, when using the tiny84 (or other x4 series) there is an option in the tools menu to choose which pin mapping you want.

In the current released version, 1.1.2, it defaults to the "alternate" one instead of the clockwise one (the default option is corrected to the clockwise one in the upcoming 1.1.3 release)
ATtiny core for 841+1634+828 and x313/x4/x5/x61/x7/x8 series Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts (some assembled), mosfets and awesome prototyping board in my store http://tindie.com/stores/DrAzzy

ArduinoJ4ck

I choosed Counterclockwise(Like ATTiny Core) but none of my analog ins work i tried both pin mappings. :(

ArduinoJ4ck

Well, i feel stupid right now but for me burning the Bootloader solved the Problem... wastet 4 days of work cuz nobody told me :D Anyway i hope u´ll have some luck 2. Thanks everyone 

DrAzzy

I was about to say I had no idea how that could be the cause - but then I realized: The ADC clock would be way off. Maybe that could cause it.

Anyway, you need to burn bootloader whenever you first use a virgin AVR microcontroller, and whenever you want to change the clock speed or clock source.

Note that there isn't actually a bootloader in the case of most attiny's - but you still need to set the fuses for the selected clock speed (they're set to 1mhz when new) and clock source, and that's what burn bootloader does.
ATtiny core for 841+1634+828 and x313/x4/x5/x61/x7/x8 series Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts (some assembled), mosfets and awesome prototyping board in my store http://tindie.com/stores/DrAzzy

ArduinoJ4ck

Thanks for your help appreciate it. :)
have a nice day

GolamMostafa

Quote
i'm aware that using an external AREF would be more advantageous.
When using External Voltage for AREF, we must recall the following (extracted from Arduino Programming Language Reference Manual):


Warning

Don't use anything less than 0V or more than 5V for external reference voltage on the AREF pin! If you're using an external reference on the AREF pin, you must set the analog reference to EXTERNAL before calling analogRead(). Otherwise, you will short together the active reference voltage (internally generated) and the AREF pin, possibly damaging the microcontroller on your Arduino board.

Go Up