Nano RP2040 A6 and A7 reading 0

Hi there,

I've got a few nano RP2040 boards. I am struggling to get any of them to analogRead on A6 or A7. Here's the sample code:

#include "WiFiNINA.h"

void setup() {
  pinMode(A7, INPUT);
  Serial.begin(115200);
}

void loop() {
    Serial.print("X: ");
    Serial.print(analogRead(A0));
    Serial.print("\tY: ");
    Serial.println(analogRead(A7));
}

For me A0 reads fine, but A7 only outputs 0 to serial.

Any thoughts? I need to use A6/A7 for my application. A0-A3 are already used.

I don’t have that board, only ‘regular’ Nanos, and they read inputs on A6 and A7 ok. Presumably you are sure there is a non-zero voltage on the pin?

Also, is it necessary to use pinMode on any Arduino analog pins? I vaguely recall reading otherwise?

That specific nano has A4-A7 being fed in from the onboard WIFININA chip. I am sure some voltage (~1.6 V) is being applied. The WIFINina firmware has been updated.

I mainly am unsure because I was getting this behavior on multiple boards, but the code seems so simple I don’t know where it could be wrong.

Not sure about the pin mode. Doesn’t seem to matter one way or the other.

Are you using the latest firmware? I was running into problems using the C++ standard firmware, but the latest MicroPython firmware ( https://docs.arduino.cc/micropython/#firmware ) does not have these issues. You still need to calibrate things if you are using all the A# pins but:

import machine
import time
from machine import Pin
adc_pin = [machine.Pin(23), machine.Pin(24),machine.Pin(25),machine.Pin(26),machine.Pin(27),machine.Pin(28),machine.Pin(19),machine.Pin(22)]
adc=[machine.ADC('A0'),machine.ADC('A1'),machine.ADC('A2'),machine.ADC('A3'),machine.ADC('A4'),machine.ADC('A5'),machine.ADC('A6'),machine.ADC('A7')]
led = Pin(6, Pin.OUT)
readings = 0
file=open("data.csv","w") 
file.write("data"+"\n")
while True:
    q=0
    t=str(time.time_ns())
    for sen in adc:
        led.value(1)
        reading = sen.read_u16()
        logger=t+' '+str(q)+' '+str(reading)+'\n'
        print(logger)
        time.sleep_ms(10)
        file.write(t+' '+str(q)+' '+str(reading)+'\n')
        led.value(0)
        time.sleep_ms(10)
        q+=1
    readings += 1
    if readings >= 5:
        file.close()
        break

works fine (A6 & A7 may have some issues (usually shows all 0s), but at least they don't crash the board the way it used to)

Sorry, I completely miss-read (more ignored🙄) what you are actually asking (my answer is the answer to the problem which brought me to find this post from the search engine). I'll keep this up just in case.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.