Go Down

Topic: Esp8266 wemos d1 mini for reading analog values (Read 184 times) previous topic - next topic

xman236

Nov 19, 2019, 05:44 pm Last Edit: Nov 19, 2019, 06:08 pm by xman236
Hi guys,

as the title says, I am using Esp 8266 wemos d1 mini to read analog values. First, I connected the wifi module with a micro USB cable to PC. Then using the code below, I read the analog values:


Code: [Select]
void setup()
{


  Wire.begin(0,2);

  Serial.begin(115200);
  Serial.println();

}


void loop()


  int sensorValue = analogRead(A0);

 Serial.println(sensorValue);
 delay(10);
}


However the default value of A0 is changing between 3~4. What could be the reason and how could I eliminate this so that the reading value is steady?


----------------------------------------
Edit: So one reason for this floating could be that nothing is connected to the pin. I connected it now to my sensor sharing a common ground, as in the attached figure. Since the sensor requires 24 V, I converted the 4.5V from battery to 24V. Using a voltage divider I then converted the output of the sensor (0-10V) to 0-1.66V. However the reading value A0 is still floating. What could be the reason?


Juraj

only info, not a solution
- the analog pin of the Wemos has a voltage divider to convert 0 to 3.3 V to 0 to 1 V of the esp8266 ADC pin
- if you read the ADC in every loop WiFi goes down (it uses the ADC too)

Paul__B

if you read the ADC in every loop WiFi goes down (it uses the ADC too)
Really?

Wawa

A delay() puts the WiFi of the WeMos AFAIK to sleep for some random time (about a second and a bit IIRC).
So use millis() to manage time between analogReads, not delay().

Can also use a single resistor (not a voltage divider) between sensor output and analogue input,
because the WeMos D1 mini already has a voltage divider buildin.
In theory, use 100k for every volt above 3.2volt, so 680k for a 0-10volt sensor.
Don't expect a lot from the A/D of an ESP8266. The one I tested did output ~8-1024 (not 0-1023).
Leo..

Juraj

#4
Nov 20, 2019, 07:24 am Last Edit: Nov 26, 2019, 07:49 pm by Juraj
Really?
try it out
ADC is switched between external pin and internal connection to measure WiFi power. but the measurements influence each other without a pause between readings
the esp8266 was developed to be used as WiFi module, not as general purpose MCU

https://github.com/esp8266/Arduino/issues/1634

xman236

Can also use a single resistor (not a voltage divider) between sensor output and analogue input,
Could you tell me about the theory behind this? This sounds like a pull-up resistor, but as far as I know pull-up/down resistor only helps in floating values (when the analogue pin is connected to nothing.)

Wawa

Could you tell me about the theory behind this? This sounds like a pull-up resistor, but as far as I know pull-up/down resistor only helps in floating values (when the analogue pin is connected to nothing.)
The WeMos already has a 220k:100k voltage divider, to reduce 3.2volt to 1volt for the A/D.
Adding a 680k resistor to that 220k makes it a 900k:100k voltage divider.
Leo..

xman236

The WeMos already has a 220k:100k voltage divider, to reduce 3.2volt to 1volt for the A/D.
Adding a 680k resistor to that 220k makes it a 900k:100k voltage divider.
Leo..
I understand that adding a 680K resistor makes a 900k:100k voltage divider. But why would this voltage divider eliminate the noise at A0?

Wawa

I don't know what the source of the noise is, or if the problem lies with the crappy A/D of an ESP8266.
You did not post any information about the sensor or the setup.

If the sensor itself produces the "noise", then a 100n cap from analogue input to ground could help.
Leo..

xman236

I don't know what the source of the noise is, or if the problem lies with the crappy A/D of an ESP8266.
You did not post any information about the sensor or the setup.

If the sensor itself produces the "noise", then a 100n cap from analogue input to ground could help.
Leo..
The sensor is a linear encoder :https://www.sick.com/de/en/encoders/wire-draw-encoders/ecoline/bcg05-k1km01pp/p/p332384

Since the resolution of the sensor is below 1mm, the noise is coming from the circuit. I also tried with Arduino Mega2560 but the noise is still there.
Following your advice, I added a low pass filter with 10 kOhm and 33 uF cap. Now the noise is reduced. However, the reading analog value is still jittering with 1~2 value (if the actual value is 209, the reading value varies between 208~210). Is there any other way to eliminate this jittering? If ESP8266 is a bad choise, what could be a better choise? All I want is to send the sensor value wireless to my PC.

Wawa

Maybe the noise comes from the 24volt DC/DC converter, maybe not.
I can't tell from the limited information you have given us.
You are there, so you have the best opportunity to measure/solve this.
Grounding scheme (how/where) could also make a difference.

A common external A/D is the ADS1115.
That 15-bit A/D (single-ended) could also give you a higher resolution than the 10-bit A/D of a WeMos.
But if the noise comes from the sensor, then it could make things worse.
Leo..

Go Up