Changing pinmode on the fly - nRF52840 Express

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Molder
 
Posts: 13
Joined: Tue Apr 12, 2022 7:06 am

Changing pinmode on the fly - nRF52840 Express

Post by Molder »

Hi,

I am trying to change an analogue pin (A0=PIN_HOLD) on the fly but running into an issue. The pin is initially set to an output in setup() and held high - no problem. In a function I then change it to an input and perform and A/D read - again no problem and I get the expected value.
I then try set it back to an output and take it high again but the pin just stays as an input.
If I comment out the analogRead line the pin will happily switch from input to output repeatedly, it just won't play ball after performing an A/D read.
Any ideas very welcome?

Code: Select all

pinMode(PIN_HOLD, INPUT);                     //Make the power hold pin an input
delay(20);							// probably not needed
AD_Val = analogRead(PIN_HOLD);              //Perform an A/D read to check for switch activity 
delay(20);
pinMode(PIN_HOLD, OUTPUT);                   //turn the pin back to an output to maintain the power
digitalWrite(PIN_HOLD, HIGH);
I have used the same technique on the SAMD21 and it works fine.

Thanks

User avatar
adafruit_support_mike
 
Posts: 67391
Joined: Thu Feb 11, 2010 2:51 pm

Re: Changing pinmode on the fly - nRF52840 Express

Post by adafruit_support_mike »

Hmm.. that should work.

Is the code above everything you're testing right now? If not, try loading a toy sketch that just swaps the pin between input and output, and see if you get the same behavior there.

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”