1

I am trying to port a simple project I have working in an Arduino UNO to a NodeMCU but I am stuck as I am using the analog gpio to receive the input from some buttons, I am always getting always low values (between 0 and 5) while in the working arduino sketch I get values from 0 to 1023.

I have tried deactivating the wifi while trying to retrieve the values, but I got no luck trying that, as I have read that sometimes the NodeMCU A0 gpio malfunctions when the wifi is not sleeping.

I am setting up the gpio in the setup method like this:

void setup(void){ pinMode(sensorPin, INPUT_PULLUP); ... 

And my sensorPin variable is declared in the beginning of the sketch

int sensorPin = A0; 

Any ideas why when I read the value in the NodeMCU I don't get the same behaviour as in an Arduino board?

8
  • Probably because the nodemcu isn't an arduino. Internal pullups on analog pins is an AVR quirk that you cannot rely on being the same on other mcus. Commented Aug 12, 2016 at 8:22
  • Sorry if I am asking really basic questions, as I am starting in this field. The final objective is to put all the code inside an esp8266, as they have an analog gpio, and I was using the nodeMCU because it was easier for me to push the code there. Is there any way to get the right analog values I get in an arduino in a nodeMCU? Commented Aug 12, 2016 at 10:39
  • 1
    The obvious way is to use an external pullup. You can guarantee it will be there then. Commented Aug 12, 2016 at 11:23
  • 2
    You're confusing Arduino with NodeMCU. NodeMCU is a completely different beast running with a different chip from a different manufacturer with a different core architecture. You cannot use Arduino documentation for low-level things like chip internals when looking at a completely different chip. That's like using a Ford manual to try and fix your VW. Commented Aug 12, 2016 at 12:04
  • 1
    I just wrote this blog post you might find interesting: hackingmajenkoblog.wordpress.com/2016/08/12/… Commented Aug 12, 2016 at 14:50

1 Answer 1

3

As stated by Majenko in the comments, I thought that all MCUs analog gpios had a pullup resistor built in, so I have been able to solve the problem using an external pullup, in this case connecting a 10K resistor like in the diagram:

enter image description here .

Special thanks to Majenko for his time and patience. Cheers!

3
  • Did you have to connect the R1 across VCC (5v)? Would it still work with a 3.33v pin or should I need a lower resister in that case? Commented May 19, 2017 at 4:02
  • 1
    @ΕГИІИО I used the 3.3 V pin in my final project with the nodeMCU so you should be good with the same resistance. Cheers! Commented May 21, 2017 at 11:20
  • @PayToPwn Alternatively, you can short the A0 pin with any digital pin and pull-up that digital pin. In fact, INPUT_PULLUP on analog input pin is very useful. In that way, you can connect photo-resistor directly to the analog pin and measure light intensity without external resistors. Commented Aug 17, 2022 at 4:46

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.