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?

  • 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. – Majenko Aug 12 '16 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? – PayToPwn Aug 12 '16 at 10:39
  • 1
    The obvious way is to use an external pullup. You can guarantee it will be there then. – Majenko Aug 12 '16 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. – Majenko Aug 12 '16 at 12:04
  • 1
    I just wrote this blog post you might find interesting: hackingmajenkoblog.wordpress.com/2016/08/12/… – Majenko Aug 12 '16 at 14:50
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!

| improve this answer | |
  • 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? – Ε Г И І И О May 19 '17 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! – PayToPwn May 21 '17 at 11:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.