[solved] ATTiny13A using MicroCore: analogRead() problems

I spent to much time to solve a problem that was none. Maybe others will face this problem an fail--like me--to find the correct information. Hence, I write this post to help save time.

Problem: AnalogRead did not work. My first fault: only PB2, PB3, PB4, and PB5 can be used for ADC ... ouch ;) My second fault: I used analogRead() with PB2/PB3/PB4/PB5. Solution: Use 0,1,2,3 for ADC0-3 like

#define TINY_ADC_PB2 0x01
#define TINY_ADC_PB3 0x03
#define TINY_ADC_PB4 0x02
#define TINY_ADC_PB5 0x00

uint16_t val = analogRead(TINY_ADC_PB4); // using PB4

Maybe I'm still wrong here but I expected the analogRead() function to translate PBx to the correct ADC value. However, now everything works fine :)

Arduino functions are meant to work with Arduino pin numbers. I think you will find this to be the case no matter which hardware package you use. Generally it is possible to use the analog pin number (0, 1, 2, 3), the analog pin name (A0, A1, A2, A3), or the digital pin number (5, 2, 4, 3) with analogRead(). However, in the case of MicroCore only the first two may be used. This is likely because the core is intended to be as lightweight as possible due to the limited resources of the ATtiny13 (EDIT: and also since the numbers overlap it would not be possible anyway).