Maybe that serial library does something weird.
Did you already try different pins (for serial and analogue).
Leo..
The function analogRead() will also set the reference bits to what was defined in analogReference(), in your case still default (VCC).
Now that I have read it it is clear. Sorry.
Maybe a 100nF decoupling capacitor close to the chip and across its power rails should be added. Other than that, it sounds almost like the pullup resistor on PB4 could somehow be active.
Perhaps, no!
I think that the following tasks are embedded in the int y = analogRead(A2); instruction.
//--default Vref = AVCC = VCC = 5 V
//--default 125 kHz ADC clock
//--default right adjustment of converted data
1. ADC Channel-2 (A2) is selected,
2. Slight waiting for mux stabilization,
3. Issuance of Start Conversion,
4. Wait for conversion completion or keep polling EOC/ADIF status, and
5. After conversion, 16-bit ADC data (upper 6-bit are always 0s) enters into y variable via <ADCH, ADCL> registers of the ADC.
The function analogReference() fills variable analog_reference. If not called, analog_reference remains 0 (default).
The function analogRead() uses lookup tables to find the input to be used.
It also reads the variable analog_reference.
These two are combined and written in one go to register ADMUX.
In register ADCSRA one bit is set: ADSC (start conversion).
This bit is read repeatedly until it clears (conversion complete).
The function returns the result of the conversion.
Notice that the clock speed is not touched.
I didn't know that. Thank you.
If I do not execute analogRefernece(INTERNAL/EXTERNAL); prior to executing analogRead(), the VREF of the ADC will remain connected at default 5V -- am I correct?
I appreciate that info. I’m going to dig into the library code. it would sure explain how I’m not getting a 5 Volt reference. and I need to see what happens if I apply 5V to PB0 which is currently floating in my setup.
Warning! Do not exceed VCC!
