Can't get A6 or A7 to act as Inputs

I have four voltage dividers set up on a breadboard, all are the same values (100k & 10k), with the same input voltage to the top of each divider. Seems crazy, but I am just testing a very simple setup to make sure it runs right before I get complicated. I doesn’t.

The values I get for pins A1, A2, and A3 are correct. But A6 is an order of magnitude too big. I have tried using A7 instead, and it is the same problem.

The pin is completely unaware of what the input voltage is, it stays where it is even if I take the input voltage jumper completely out. It is as if it doesn’t realize it is an input pin.

Maybe that is the problem (setting the pins up right). Here is my code :

#include <Arduino.h>
//#include <SPI.h>
#include <Wire.h>
#include <U8g2lib.h>

 U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0);    // setup u8g2 object

const int sensorPin1 = A0;  // Analog input pin that senses Vout


int sensorValue1 = 0;       // sensorPin default value
float Vin1 = 5;             // Input voltage
float Vout1 = 0;            // Vout default value
float Rref = 3000;          // Reference resistor's value in ohms
float R = 0;               // Tested resistors default value
//float Vs = 0.0;
//float input_volt = 0.0;
//float temp = 0.0;
float r1=100300.0;      //r2 value  This value of the resistor has been adjusted in order to make the actual displayed value match the known Voltage rail tested.
float r2=9900.0;    //r1 value  This value of the resistor has been adjusted in order to make the actual displayed value match the known Voltage rail tested.

/*
  Fontname: -FreeType-FreeUniversal-Medium-R-Normal--32-320-72-72-P-151-ISO10646-1
  Copyright: (FreeUniversal) Copyright (c) Stephen Wilson 2009    a modification of:    Original Font (SIL Sophia)  Copyright (c) SIL International, 1994-2008.    
  Glyphs: 45/243
  BBX Build Mode: 0
*/
const uint8_t u8g2_font_omega_tn[1714] U8G2_FONT_SECTION("u8g2_font_omega_tn") = 
 

  void setup(void) {
  pinMode(A0,INPUT);
  pinMode(A1,INPUT);
  pinMode(A2,INPUT);
  pinMode(A3,INPUT);
  pinMode(A6,INPUT);
  pinMode(A7,INPUT);

  u8g2.begin();    }

  void loop(void) {
  u8g2.clearBuffer();

  //  *************************************************  ********************************************

  int analogvalue1 = analogRead(A1);     
  float temp1 = (analogvalue1 * 5) / 1024.0;       
  float input_volt1 = temp1 / .0943938;       // r1 94500   r2 9850    =  .0943938   (r2/(r1+r2)
  float Vs1 = input_volt1;  
  
  int analogvalue2 = analogRead(A2);     // Future Potentiometer Node 2
  float temp2 = (analogvalue2 * 5) / 1024.0;       
  float input_volt2 = temp2 / .090909;     // r1 98100   r2 9810    =   .090909
  float Vs2 = input_volt2; 
  
  int analogvalue3 = analogRead(A3);     // Future Potentiometer Node 2
  float temp3 = (analogvalue3 * 5) / 1024.0;       
  float input_volt3 = temp3 / (r2/(r1+r2));     // r1 97700   r2 9840    =   .0915008
  float Vs3 = input_volt3;

  int analogvalue4 = analogRead(A6);     // Future Potentiometer Node 2
  float temp4 = (analogvalue4 * 5) / 1024.0;       
  float input_volt4 = temp4 / .090491;       // r1 98900   r2 9840    =  .090491
  float Vs4 = input_volt4;
  

  u8g2.setFont(u8g2_font_pxplusibmvga9_tf);

  if(R>=11000){
    
  u8g2.drawStr(0,10,"P1 ");
  u8g2.setCursor(22, 10);   
  u8g2.print(analogvalue1,1);
  u8g2.print("v");
  u8g2.print(" ");
  u8g2.print("Max ");
  u8g2.print("1.2");
  u8g2.print("w");

  u8g2.drawStr(0,28,"P2 ");
  u8g2.setCursor(22, 28);   
  u8g2.print(analogvalue2,1);
  u8g2.print("v");
  u8g2.print(" ");
  u8g2.print("Max ");
  u8g2.print("1.8");
  u8g2.print("w");
       
  u8g2.drawStr(0,46,"P3 ");
  u8g2.setCursor(22, 46);   
  u8g2.print(analogvalue3,1);
  u8g2.print("v");
  u8g2.print(" ");
  u8g2.print("Max ");
  u8g2.print("1.2");
  u8g2.print("w");

  u8g2.drawStr(0,63,"P4 ");
  u8g2.setCursor(22, 63);   
  u8g2.print(analogvalue4,1);
  u8g2.print("v");
  u8g2.print(" ");
  u8g2.print("Max ");
  u8g2.print("1.8");
  u8g2.print("w");
    
   }


  
  //  ************************************************* POTENTIOMETER RESISTOR CALCULATION ********************************************
  
  sensorValue1 = analogRead(sensorPin1);  // Read Vout on analog input pin A0 (Arduino can sense from 0-1023, 1023 is 5V)
  Vout1 = (Vin1 * sensorValue1) / 1023;    // Convert Vout to volts relative to 5v
  // R = Rref * (1 / ((Vin1 / Vout1) - 1));  // Formula to calculate tested resistor's value
  R = (3000 * Vout1)/(Vin1-Vout1);
  
  u8g2.setFont(u8g2_font_fub20_tr);
  if(R>=11000){
    u8g2.drawStr( 10, 24, " ");
    }

   else if(R>=10000 && R<11000){
    u8g2.setCursor(36, 44); 
    //u8g2.print("> 10k ");
    u8g2.drawStr(87,44,"k");
    u8g2.setFont(u8g2_font_omega_tn);   // this is a Font customized by Oliver, its author, to include the Omega symbol
    u8g2.drawGlyph(80,45,0x03a9);
     }

   else if(R>999 && R<10000){
    u8g2.setCursor(6, 44);      //Changed 
    u8g2.print(R/1000,2);
    u8g2.drawStr(80,44,"k");
    u8g2.setFont(u8g2_font_omega_tn);   // this is a Font customized by Oliver, its author, to include the Omega symbol
    u8g2.drawGlyph(97,45,0x03a9);
       
     }
       
   else if(R>200){
    u8g2.setCursor(19, 44);
    u8g2.print(R,0);
    u8g2.setFont(u8g2_font_omega_tn);   // this is a Font customized by Oliver, its author, to include the Omega symbol
    u8g2.drawGlyph(80,45,0x03a9);
     }
   else{
    u8g2.setCursor(29, 44);
    u8g2.print(R*1.08,0);
    u8g2.setFont(u8g2_font_omega_tn);   // this is a Font customized by Oliver, its author, to include the Omega symbol
    u8g2.drawGlyph(80,45,0x03a9);
     }
  
  
   //u8g2.setFont(u8g2_font_unifont_t_symbols);   This is just an example of how to draw a glyph using this library
   //u8g2.drawUTF8(5, 60, "Snowman: ☃");
   
  delay(100);
  u8g2.sendBuffer();
  
     }

What am I doing wrong ?

pratto: What am I doing wrong ?

For one you don't specify the type of Arduino you are using.

I should have mentioned, I am using a NANO. I looked very closely for cold solder joints where the board is connected (as well as bridges using a continuity beeper), and I have used 3 different nano's.

I've used A6 and A7 on Nanos without problems.

Just a note: you don't have to configure analog ports as INPUT, that's the default.

Why are you testing with such a complicated sketch?

I just tested one of my new capacitive moisture sensors on a Nano clone.

void setup() {
  Serial.begin(250000);
}
void loop() {
  static uint32_t lastPrint;
  uint32_t topLoop = millis();
  if (topLoop - lastPrint >= 1000) {
    Serial.print(F("A6 "));
    Serial.println(analogRead(A6));
    lastPrint = topLoop;
  }
}
A6 738
A6 738
A6 739
A6 739
A6 735
A6 732
A6 743
A6 736
A6 725
A6 714
A6 703
A6 693
A6 683
A6 673
A6 665
A6 655
A6 646
A6 636
A6 627
A6 619
A6 607
A6 598
A6 589
A6 581
A6 573
A6 597
A6 713
A6 705
A6 731
A6 733
A6 734
A6 735
A6 737
A6 736
A6 735
A6 735
A6 735
A6 724
A6 712
A6 700
A6 690
A6 680
A6 671
A6 662
A6 653
A6 645
A6 637
A6 629
A6 621
A6 613
A6 605
A6 597
A6 590
A6 583
A6 576
A6 566
A6 559
A6 552
A6 546
A6 539
A6 533
A6 526
A6 518
A6 511
A6 504
A6 497
A6 491
A6 484
A6 478
A6 472
A6 466
A6 460
A6 454
A6 449
A6 444
A6 441
A6 440
A6 438
A6 437
A6 437
A6 436
A6 434
A6 434
A6 434
A6 433
A6 433

Works as expected.

My cristall ball shows a breadboard with split power rails that are not connected.

Could you please upload a picture of your breadboard setup?

You appear to read A6 and then go to some effort to derive Vs4 indirectly from it . . .

  int analogvalue4 = analogRead(A6);     // Future Potentiometer Node 2
  float temp4 = (analogvalue4 * 5) / 1024.0;       
  float input_volt4 = temp4 / .090491;       // r1 98900   r2 9840    =  .090491
  float Vs4 = input_volt4;

but Vs4 is not used afterwards.

Agreed the sketch is too complicated. Pare it down to just the basics that will demonstrate the problem.

Whandall: I've used A6 and A7 on Nanos without problems.

Just a note: you don't have to configure analog ports as INPUT, that's the default.

A6 and A7 don't have digital capability, you should not be calling pinMode for them at all. (You may end up writing bits in ports that have undefined behaviour, just take out that call)

Another little point to realize is that the analog and digital uses of a pin such as A0 are completely independent of each other.

You can set A0 as an output, set it high, then measure its voltage with analogRead() to see if its voltage is drooping below Vcc due to the load its connected to.

analogRead() does two things, it switches the source for the analog multiplexer on the chip to a particular pin (without any effect on other uses of the pin), and then triggers the ADC to run (and waits for the result).

A6 and A7 on the Uno are not standard pins at all, they merely go direct to the analog multiplexer.

[ This is all for the ATmega chip based Arduinos like Uno/Mega ]

Note how handy this is for hardware POST and fault detection...

Connect a jumper from the 3.3V pin to A6 pin, load and run this test sketch:

void setup()
{
  Serial.begin(250000);
}
void loop()
{
  Serial.println(analogRead(A6));
  delay(1000);
}

You should see an ADC result around 718.

You should see an ADC result around 718.

I see a value of about 350, that is until I put my finger on pin A6

Why do you expect the magic value of 718 ?

UKHeliBob: I see a value of about 350,

For a voltage of 3.3V? That would be a VRef of about 9.65V... strange.

I see around 784 for the 3.3V of an AMS1117 3.3V while running the Nano powered by USB.

OK. Thanks to you all for helping. I have made changes to the code for clarification. I now use Vs4, and I have commented out A6 & A7 as INPUTS.
As far as the thing being too complicated, the only part of interest is the top part that reads a voltage and writes it to an OLED. The whole lower half is not involved. But I whacked it anyway.

#include <Arduino.h>
//#include <SPI.h>
#include <Wire.h>
#include <U8g2lib.h>

 U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0);    // setup u8g2 object

const int sensorPin1 = A0;  // Analog input pin that senses Vout


int sensorValue1 = 0;       // sensorPin default value
float Vin1 = 5;             // Input voltage
float Vout1 = 0;            // Vout default value
float Rref = 3000;          // Reference resistor's value in ohms
float R = 0;               // Tested resistors default value
//float Vs = 0.0;
//float input_volt = 0.0;
//float temp = 0.0;
float r1=100300.0;      //r2 value  This value of the resistor has been adjusted in order to make the actual displayed value match the known Voltage rail tested.
float r2=9900.0;    //r1 value  This value of the resistor has been adjusted in order to make the actual displayed value match the known Voltage rail tested.

/*
  Fontname: -FreeType-FreeUniversal-Medium-R-Normal--32-320-72-72-P-151-ISO10646-1
  Copyright: (FreeUniversal) Copyright (c) Stephen Wilson 2009    a modification of:    Original Font (SIL Sophia)  Copyright (c) SIL International, 1994-2008.    
  Glyphs: 45/243
  BBX Build Mode: 0
*/
const uint8_t u8g2_font_omega_tn[1714] U8G2_FONT_SECTION("u8g2_font_omega_tn") = 
  

  void setup(void) {
  pinMode(A0,INPUT);
  pinMode(A1,INPUT);
  pinMode(A2,INPUT);
  pinMode(A3,INPUT);
  //pinMode(A6,INPUT);
  //pinMode(A7,INPUT);

  u8g2.begin();    }

  void loop(void) {
  u8g2.clearBuffer();

  //  *************************************************  ********************************************

  int analogvalue1 = analogRead(A1);     
  float temp1 = (analogvalue1 * 5) / 1024.0;       
  float input_volt1 = temp1 / .0943938;       // r1 94500   r2 9850    =  .0943938   (r2/(r1+r2)
  float Vs1 = input_volt1;  
  
  int analogvalue2 = analogRead(A2);     // Future Potentiometer Node 2
  float temp2 = (analogvalue2 * 5) / 1024.0;       
  float input_volt2 = temp2 / .090909;     // r1 98100   r2 9810    =   .090909
  float Vs2 = input_volt2; 
  
  int analogvalue3 = analogRead(A3);     // Future Potentiometer Node 2
  float temp3 = (analogvalue3 * 5) / 1024.0;       
  float input_volt3 = temp3 / (r2/(r1+r2));     // r1 97700   r2 9840    =   .0915008
  float Vs3 = input_volt3;

  int analogvalue4 = analogRead(A6);     // Future Potentiometer Node 2
  float temp4 = (analogvalue4 * 5) / 1024.0;       
  float input_volt4 = temp4 / .090491;       // r1 98900   r2 9840    =  .090491
  float Vs4 = input_volt4;
  

  u8g2.setFont(u8g2_font_pxplusibmvga9_tf);

  if(R>=11000){
    
  u8g2.drawStr(0,10,"P1 ");
  u8g2.setCursor(22, 10);   
  u8g2.print(Vs1,1);
  u8g2.print("v");
  u8g2.print(" ");
  u8g2.print("Max ");
  u8g2.print("1.2");
  u8g2.print("w");

  u8g2.drawStr(0,28,"P2 ");
  u8g2.setCursor(22, 28);   
  u8g2.print(Vs2,1);
  u8g2.print("v");
  u8g2.print(" ");
  u8g2.print("Max ");
  u8g2.print("1.8");
  u8g2.print("w");
       
  u8g2.drawStr(0,46,"P3 ");
  u8g2.setCursor(22, 46);   
  u8g2.print(Vs3,1);
  u8g2.print("v");
  u8g2.print(" ");
  u8g2.print("Max ");
  u8g2.print("1.2");
  u8g2.print("w");

  u8g2.drawStr(0,63,"P4 ");
  u8g2.setCursor(22, 63);   
  u8g2.print(Vs4,1);
  u8g2.print("v");
  u8g2.print(" ");
  u8g2.print("Max ");
  u8g2.print("1.8");
  u8g2.print("w");
    
   }


  
  
   
  delay(100);
  u8g2.sendBuffer();
  
     }

attached is a shot of my breadboard setup. The Nano is connected to the wires running under the BB.
You can see my four voltage dividers and the p1-p4 voltages displayed on the 4 lines on the oled, although due to sweep speed / camera issue you can only see the top and bottom lines. The first 3 lines read about 4.7v, while the bottom (reading A6) reads about 38v.

I did jumper the 3.3v, and attached is a shot of the printout (about 745).

I can’t seem to get it to accept attachments. each photo is 8 Mb.

photo 1

photo 1

figured out how to resize image.

Hello there!

While reading the original post, I noticed that you are using 10k and 100k resistors, which are an order of magnitude apart, and you said the analogRead() results you are getting are also an order of magnitude apart. Coincidence? Maybe.

I drew up a schematic in Microsoft Paint (so excuse the mess) that may explain the issue. Give it a look over and look at the equations.

Check your circuit to make sure the resistors are all in the same order from supply to ground and let me know if that's the issue.

VoltageDivider.png

VoltageDivider.png

That looked like it needed investigating. so i unplugged power to all but A1. the first line correctly shows about 4.6v, the second and third lines show 0v, but line 4 continues to show 41v. It seems it is only a problem when I use A6 or A7.

That seems strange. Judging by the posts, it seems that A0 is working correctly. Can you hook up A0, A6, and A7 to the same voltage divider node and see what readings you get on each?

Yes. On A1-A3 (A0 is already used in another calculation that works, A4 & A5 already used in I2C) I get the correct voltage. But either A6 or A7 I get garbage.